Changeset View
Changeset View
Standalone View
Standalone View
src/conduit/ConduitClient.php
| <?php | <?php | ||||
| final class ConduitClient { | final class ConduitClient { | ||||
| private $uri; | private $uri; | ||||
| private $host; | private $host; | ||||
| private $connectionID; | private $connectionID; | ||||
| private $sessionKey; | private $sessionKey; | ||||
| private $timeout = 300.0; | private $timeout = 300.0; | ||||
| private $username; | private $username; | ||||
| private $password; | private $password; | ||||
| private $publicKey; | private $publicKey; | ||||
| private $privateKey; | private $privateKey; | ||||
| private $conduitToken; | |||||
| const AUTH_ASYMMETRIC = 'asymmetric'; | const AUTH_ASYMMETRIC = 'asymmetric'; | ||||
| const SIGNATURE_CONSIGN_1 = 'Consign1.0/'; | const SIGNATURE_CONSIGN_1 = 'Consign1.0/'; | ||||
| public function getConnectionID() { | public function getConnectionID() { | ||||
| return $this->connectionID; | return $this->connectionID; | ||||
| } | } | ||||
| Show All 16 Lines | public function setHost($host) { | ||||
| $this->host = $host; | $this->host = $host; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHost() { | public function getHost() { | ||||
| return $this->host; | return $this->host; | ||||
| } | } | ||||
| public function setConduitToken($conduit_token) { | |||||
| $this->conduitToken = $conduit_token; | |||||
| return $this; | |||||
| } | |||||
| public function getConduitToken() { | |||||
| return $this->conduitToken; | |||||
| } | |||||
| public function callMethodSynchronous($method, array $params) { | public function callMethodSynchronous($method, array $params) { | ||||
| return $this->callMethod($method, $params)->resolve(); | return $this->callMethod($method, $params)->resolve(); | ||||
| } | } | ||||
| public function didReceiveResponse($method, $data) { | public function didReceiveResponse($method, $data) { | ||||
| if ($method == 'conduit.connect') { | if ($method == 'conduit.connect') { | ||||
| $this->sessionKey = idx($data, 'sessionKey'); | $this->sessionKey = idx($data, 'sessionKey'); | ||||
| $this->connectionID = idx($data, 'connectionID'); | $this->connectionID = idx($data, 'connectionID'); | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if ($this->privateKey && $this->publicKey) { | ||||
| $meta['auth.type'] = self::AUTH_ASYMMETRIC; | $meta['auth.type'] = self::AUTH_ASYMMETRIC; | ||||
| $meta['auth.key'] = $this->publicKey; | $meta['auth.key'] = $this->publicKey; | ||||
| $meta['auth.host'] = $this->getHostString(); | $meta['auth.host'] = $this->getHostString(); | ||||
| $signature = $this->signRequest($method, $params, $meta); | $signature = $this->signRequest($method, $params, $meta); | ||||
| $meta['auth.signature'] = $signature; | $meta['auth.signature'] = $signature; | ||||
| } | } | ||||
| if ($this->conduitToken) { | |||||
| $meta['token'] = $this->conduitToken; | |||||
| } | |||||
| if ($meta) { | if ($meta) { | ||||
| $params['__conduit__'] = $meta; | $params['__conduit__'] = $meta; | ||||
| } | } | ||||
| $uri = id(clone $this->uri)->setPath('/api/'.$method); | $uri = id(clone $this->uri)->setPath('/api/'.$method); | ||||
| $data = array( | $data = array( | ||||
| 'params' => json_encode($params), | 'params' => json_encode($params), | ||||
| ▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines | |||||