Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/future/PhabricatorTwilioFuture.php
<?php | <?php | ||||
final class PhabricatorTwilioFuture extends FutureProxy { | final class PhabricatorTwilioFuture extends FutureProxy { | ||||
private $future; | private $future; | ||||
private $accountSID; | private $accountSID; | ||||
private $authToken; | private $authToken; | ||||
private $method; | private $method; | ||||
private $parameters; | private $parameters; | ||||
private $timeout; | |||||
public function __construct() { | public function __construct() { | ||||
parent::__construct(null); | parent::__construct(null); | ||||
} | } | ||||
public function setAccountSID($account_sid) { | public function setAccountSID($account_sid) { | ||||
$this->accountSID = $account_sid; | $this->accountSID = $account_sid; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setAuthToken(PhutilOpaqueEnvelope $token) { | public function setAuthToken(PhutilOpaqueEnvelope $token) { | ||||
$this->authToken = $token; | $this->authToken = $token; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setMethod($method, array $parameters) { | public function setMethod($method, array $parameters) { | ||||
$this->method = $method; | $this->method = $method; | ||||
$this->parameters = $parameters; | $this->parameters = $parameters; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setTimeout($timeout) { | |||||
$this->timeout = $timeout; | |||||
return $this; | |||||
} | |||||
public function getTimeout() { | |||||
return $this->timeout; | |||||
} | |||||
protected function getProxiedFuture() { | protected function getProxiedFuture() { | ||||
if (!$this->future) { | if (!$this->future) { | ||||
if ($this->accountSID === null) { | if ($this->accountSID === null) { | ||||
throw new PhutilInvalidStateException('setAccountSID'); | throw new PhutilInvalidStateException('setAccountSID'); | ||||
} | } | ||||
if ($this->authToken === null) { | if ($this->authToken === null) { | ||||
throw new PhutilInvalidStateException('setAuthToken'); | throw new PhutilInvalidStateException('setAuthToken'); | ||||
Show All 14 Lines | if (!$this->future) { | ||||
$data = $this->parameters; | $data = $this->parameters; | ||||
$future = id(new HTTPSFuture($uri, $data)) | $future = id(new HTTPSFuture($uri, $data)) | ||||
->setHTTPBasicAuthCredentials($this->accountSID, $this->authToken) | ->setHTTPBasicAuthCredentials($this->accountSID, $this->authToken) | ||||
->setMethod('POST') | ->setMethod('POST') | ||||
->addHeader('Accept', 'application/json'); | ->addHeader('Accept', 'application/json'); | ||||
$timeout = $this->getTimeout(); | |||||
if ($timeout) { | |||||
$future->setTimeout($timeout); | |||||
} | |||||
$this->future = $future; | $this->future = $future; | ||||
} | } | ||||
return $this->future; | return $this->future; | ||||
} | } | ||||
protected function didReceiveResult($result) { | protected function didReceiveResult($result) { | ||||
list($status, $body, $headers) = $result; | list($status, $body, $headers) = $result; | ||||
Show All 17 Lines |