3 final class PhabricatorTwilioFuture
extends FutureProxy
{
12 public function __construct() {
13 parent
::__construct(null);
16 public function setAccountSID($account_sid) {
17 $this->accountSID
= $account_sid;
21 public function setAuthToken(PhutilOpaqueEnvelope
$token) {
22 $this->authToken
= $token;
26 public function setMethod($method, array $parameters) {
27 $this->method
= $method;
28 $this->parameters
= $parameters;
32 public function setTimeout($timeout) {
33 $this->timeout
= $timeout;
37 public function getTimeout() {
38 return $this->timeout
;
41 protected function getProxiedFuture() {
43 if ($this->accountSID
=== null) {
44 throw new PhutilInvalidStateException('setAccountSID');
47 if ($this->authToken
=== null) {
48 throw new PhutilInvalidStateException('setAuthToken');
51 if ($this->method
=== null ||
$this->parameters
=== null) {
52 throw new PhutilInvalidStateException('setMethod');
61 $uri = id(new PhutilURI('https://api.twilio.com/'))
64 $data = $this->parameters
;
66 $future = id(new HTTPSFuture($uri, $data))
67 ->setHTTPBasicAuthCredentials($this->accountSID
, $this->authToken
)
69 ->addHeader('Accept', 'application/json');
71 $timeout = $this->getTimeout();
73 $future->setTimeout($timeout);
76 $this->future
= $future;
82 protected function didReceiveResult($result) {
83 list($status, $body, $headers) = $result;
85 if ($status->isError()) {
90 $data = phutil_json_decode($body);
91 } catch (PhutilJSONParserException
$ex) {
92 throw new PhutilProxyException(
93 pht('Expected JSON response from Twilio.'),