Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| SessionClient | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| login | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| loginExtended | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| logout | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | #declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * CNIC\HEXONET |
| 7 | * Copyright © CentralNic Group PLC |
| 8 | */ |
| 9 | |
| 10 | namespace CNIC\HEXONET; |
| 11 | |
| 12 | /** |
| 13 | * HEXONET Session API Client |
| 14 | * |
| 15 | * @package CNIC\HEXONET |
| 16 | */ |
| 17 | |
| 18 | class SessionClient extends Client |
| 19 | { |
| 20 | public function __construct(string $cfgfile = "") |
| 21 | { |
| 22 | if (empty($cfgfile)) { |
| 23 | parent::__construct(implode(DIRECTORY_SEPARATOR, [__DIR__, "config.json"])); |
| 24 | } else { |
| 25 | parent::__construct($cfgfile); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Perform API login to start session-based communication |
| 31 | * @param string $otp optional one time password |
| 32 | * @return Response Response |
| 33 | */ |
| 34 | public function login($otp = "") |
| 35 | { |
| 36 | $this->setOTP($otp); |
| 37 | $rr = $this->request(["COMMAND" => "StartSession"]); |
| 38 | if ($rr->isSuccess()) { |
| 39 | $col = $rr->getColumn("SESSION"); |
| 40 | $this->setSession($col ? $col->getData()[0] : ""); |
| 41 | } |
| 42 | return $rr; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Perform API login to start session-based communication. |
| 47 | * Use given specific command parameters. |
| 48 | * @param array $params given specific command parameters |
| 49 | * @param string $otp optional one time password |
| 50 | * @return Response Response |
| 51 | */ |
| 52 | public function loginExtended($params, $otp = "") |
| 53 | { |
| 54 | $this->setOTP($otp); |
| 55 | $rr = $this->request(array_merge( |
| 56 | ["COMMAND" => "StartSession"], |
| 57 | $params |
| 58 | )); |
| 59 | if ($rr->isSuccess()) { |
| 60 | $col = $rr->getColumn("SESSION"); |
| 61 | $this->setSession($col ? $col->getData()[0] : ""); |
| 62 | } |
| 63 | return $rr; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Perform API logout to close API session in use |
| 68 | * @return Response Response |
| 69 | */ |
| 70 | public function logout() |
| 71 | { |
| 72 | $rr = $this->request(["COMMAND" => "EndSession"]); |
| 73 | if ($rr->isSuccess()) { |
| 74 | $this->setSession(""); |
| 75 | } |
| 76 | return $rr; |
| 77 | } |
| 78 | } |