-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGithubApiCallFuture.php
43 lines (35 loc) · 1.3 KB
/
GithubApiCallFuture.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class GithubApiCallFuture extends FutureProxy {
const BASE_URI = 'https://api.github.com/' ; // todo get this from provider.
const GITHUB_PROVIDER_KEY = 'github:github.com';
public $uri;
private $future;
public static function getAccessToken(PhabricatorUser $user) {
$account = id(new PhabricatorExternalAccountQuery())
->setViewer($user)
->withUserPHIDs(array($user->getPHID()))
->withAccountDomains(array("github.com")) // todo get this from provider.
->executeOne();
$github_provider = PhabricatorAuthProvider::getEnabledProviderByKey(
self::GITHUB_PROVIDER_KEY); // todo get this from somewhere.
return $github_provider->getOAuthAccessToken($account);
}
public function __construct($api, $access_token, array $data = null) {
$this->uri = new PhutilURI(self::BASE_URI . $api);
$this->uri->setQueryParam('access_token', $access_token);
$this->future = new HTTPSFuture($this->uri);
$this->setProxiedFuture($this->future);
if ($data !== null) {
$this->setData(json_encode($data));
}
}
protected function didReceiveResult($result){
return $result;
}
public function setMethod($method) {
$this->future->setMethod($method);
}
public function setData($encoded_data) {
$this->future->setData($encoded_data);
}
}