Changeset View
Changeset View
Standalone View
Standalone View
src/future/asana/PhutilAsanaFuture.php
<?php | <?php | ||||
final class PhutilAsanaFuture extends FutureProxy { | final class PhutilAsanaFuture extends FutureProxy { | ||||
private $future; | private $future; | ||||
private $accessToken; | private $accessToken; | ||||
private $action; | private $action; | ||||
private $params; | private $params; | ||||
private $method = 'GET'; | private $method = 'GET'; | ||||
private $timeout; | |||||
public function __construct() { | public function __construct() { | ||||
parent::__construct(null); | parent::__construct(null); | ||||
} | } | ||||
public function setAccessToken($token) { | public function setAccessToken($token) { | ||||
$this->accessToken = $token; | $this->accessToken = $token; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setRawAsanaQuery($action, array $params = array()) { | public function setRawAsanaQuery($action, array $params = array()) { | ||||
$this->action = $action; | $this->action = $action; | ||||
$this->params = $params; | $this->params = $params; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setMethod($method) { | public function setMethod($method) { | ||||
$this->method = $method; | $this->method = $method; | ||||
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) { | ||||
$params = $this->params; | $params = $this->params; | ||||
if (!$this->action) { | if (!$this->action) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'You must %s!', | 'You must %s!', | ||||
Show All 10 Lines | if (!$this->future) { | ||||
$uri = new PhutilURI('https://app.asana.com/'); | $uri = new PhutilURI('https://app.asana.com/'); | ||||
$uri->setPath('/api/1.0/'.ltrim($this->action, '/')); | $uri->setPath('/api/1.0/'.ltrim($this->action, '/')); | ||||
$future = new HTTPSFuture($uri); | $future = new HTTPSFuture($uri); | ||||
$future->setData($this->params); | $future->setData($this->params); | ||||
$future->addHeader('Authorization', 'Bearer '.$this->accessToken); | $future->addHeader('Authorization', 'Bearer '.$this->accessToken); | ||||
$future->setMethod($this->method); | $future->setMethod($this->method); | ||||
$timeout = $this->getTimeout(); | |||||
if ($timeout !== null) { | |||||
$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 26 Lines |