Changeset View
Changeset View
Standalone View
Standalone View
src/conduit/ConduitClient.php
<?php | <?php | ||||
final class ConduitClient extends Phobject { | final class ConduitClient extends Phobject { | ||||
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; | private $conduitToken; | ||||
private $oauthToken; | |||||
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 26 Lines | public function setConduitToken($conduit_token) { | ||||
$this->conduitToken = $conduit_token; | $this->conduitToken = $conduit_token; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getConduitToken() { | public function getConduitToken() { | ||||
return $this->conduitToken; | return $this->conduitToken; | ||||
} | } | ||||
public function setOAuthToken($oauth_token) { | |||||
$this->oauthToken = $oauth_token; | |||||
return $this; | |||||
} | |||||
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 45 Lines • ▼ Show 20 Lines | if ($this->privateKey && $this->publicKey) { | ||||
$signature = $this->signRequest($method, $params, $meta); | $signature = $this->signRequest($method, $params, $meta); | ||||
$meta['auth.signature'] = $signature; | $meta['auth.signature'] = $signature; | ||||
} | } | ||||
if ($this->conduitToken) { | if ($this->conduitToken) { | ||||
$meta['token'] = $this->conduitToken; | $meta['token'] = $this->conduitToken; | ||||
} | } | ||||
if ($this->oauthToken) { | |||||
$meta['access_token'] = $this->oauthToken; | |||||
} | |||||
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 228 Lines • Show Last 20 Lines |