1 | <?php |
||
28 | class GithubApiComponent extends Component |
||
29 | { |
||
30 | /** |
||
31 | * perform an api request given a path, the data to send, the method and whether |
||
32 | * or not to return a status. |
||
33 | * |
||
34 | * @param string $path the api path to preform the request to |
||
35 | * @param array $data the data to send in the request. This works with both GET |
||
36 | * and Post requests |
||
37 | * @param string $method the method type of the request |
||
38 | * @param bool $returnStatus whether to return the status code with the |
||
39 | * request |
||
40 | * @param mixed $access_token |
||
41 | * |
||
42 | * @return array the returned response decoded and optionally the status code, |
||
43 | * see GithubApiComponent::sendRequest() |
||
44 | * |
||
45 | * @see GithubApiComponent::sendRequest() |
||
46 | */ |
||
47 | public function apiRequest( |
||
62 | |||
63 | /** |
||
64 | * retrieve an access token using a code that has been authorized by a user. |
||
65 | * |
||
66 | * @param string $code the code returned by github to the callback url |
||
67 | * |
||
68 | * @return string the access token |
||
69 | */ |
||
70 | public function getAccessToken($code) |
||
83 | |||
84 | /** |
||
85 | * retrieve the github info stored on a user by his access token. |
||
86 | * |
||
87 | * @param string $accessToken the access token belonging to the user being |
||
88 | * requested |
||
89 | * |
||
90 | * @return Arrray the github info returned by github as an associative array |
||
91 | */ |
||
92 | public function getUserInfo($accessToken) |
||
100 | |||
101 | /** |
||
102 | * perform an http request using curl given a url, the post data to send, the |
||
103 | * request method and whether or not to return a status. |
||
104 | * |
||
105 | * @param string $url the url to preform the request to |
||
106 | * @param array $data the post data to send in the request. This only works with POST requests. GET requests need the data appended in the url. |
||
107 | * with POST requests. GET requests need the data appended |
||
108 | * in the url. |
||
109 | * @param string $method the method type of the request |
||
110 | * @param bool $returnCode whether to return the status code with the |
||
111 | * request |
||
112 | * @param mixed $access_token |
||
113 | * |
||
114 | * @return array the returned response decoded and optionally the status code, |
||
115 | * eg: array($decodedResponse, $statusCode) or just $decodedResponse |
||
116 | */ |
||
117 | public function sendRequest( |
||
144 | |||
145 | /** |
||
146 | * generate the url to redirect the user to for authorization given the |
||
147 | * requested scope. |
||
148 | * |
||
149 | * @param string $scope the api scope for the user to authorize |
||
150 | * |
||
151 | * @return string the generated url to redirect the user to |
||
152 | */ |
||
153 | public function getRedirectUrl($scope = null) |
||
171 | |||
172 | /** |
||
173 | * Check if a user can commit to a rep. |
||
174 | * |
||
175 | * @param string $username the username to check |
||
176 | * @param string $repoPath the repo path of the repo to check for |
||
177 | * |
||
178 | * @return bool true if the user is a collaborator and false if they arent |
||
179 | */ |
||
180 | public function canCommitTo($username, $repoPath, $access_token) |
||
192 | |||
193 | /** |
||
194 | * make api request for github issue creation. |
||
195 | * |
||
196 | * @param string $repoPath |
||
197 | * @param array $data issue details |
||
198 | * @param string $access_token |
||
199 | */ |
||
200 | public function createIssue($repoPath, $data, $access_token) |
||
210 | |||
211 | /** |
||
212 | * make api request for github comment creation. |
||
213 | * |
||
214 | * @param string $repoPath |
||
215 | * @param array $data |
||
216 | * @param int $issueNumber |
||
217 | * @param string $access_token |
||
218 | */ |
||
219 | public function createComment($repoPath, $data, $issueNumber, $access_token) |
||
229 | |||
230 | /** |
||
231 | * Make API request for getting Github issue's status |
||
232 | * |
||
233 | * @param string $repoPath |
||
234 | * @param array $data |
||
235 | * @param int $issueNumber |
||
236 | * @param string $access_token |
||
237 | */ |
||
238 | public function getIssue($repoPath, $data, $issueNumber, $access_token) |
||
248 | |||
249 | } |
||
250 |