@@ -8,7 +8,8 @@ final class Client
88{
99
1010 const VERSION = 'v3 ' ;
11- const URL = 'https://api.github.com ' ;
11+ const URL_API = 'https://api.github.com ' ;
12+ const URL_AVATAR = 'https://avatars.githubusercontent.com ' ;
1213
1314 /** @var string */
1415 private $ token ;
@@ -23,10 +24,29 @@ public function __construct($token = NULL)
2324
2425 /**
2526 * @param string $uri
27+ * @return string
28+ */
29+ public function getApiUrl ($ uri )
30+ {
31+ return self ::URL_API . '/ ' . trim ($ uri , '/ ' );
32+ }
33+
34+ /**
35+ * @param string $username
36+ * @return string
37+ */
38+ public function getAvatarUrl ($ username )
39+ {
40+ return self ::URL_AVATAR . '/ ' . trim ($ username , '/ ' );
41+ }
42+
43+ /**
44+ * @param string $url
2645 * @param array $headers
27- * @return mixed (array|NULL)
46+ * @param array $opts
47+ * @return array
2848 */
29- public function makeRequest ($ uri , array $ headers = [])
49+ public function makeRequest ($ url , array $ headers = [], array $ opts = [])
3050 {
3151 $ ch = curl_init ();
3252
@@ -39,35 +59,34 @@ public function makeRequest($uri, array $headers = [])
3959 $ _headers [] = 'Authorization: token ' . $ this ->token ;
4060 }
4161
42- $ url = self ::URL . '/ ' . trim ($ uri , '/ ' );
43-
44- curl_setopt_array ($ ch , [
62+ $ _opts = [
4563 CURLOPT_RETURNTRANSFER => 1 ,
4664 CURLOPT_URL => $ url ,
4765 CURLOPT_USERAGENT => 'ComponetteClient-v1 ' ,
4866 CURLOPT_HTTPHEADER => $ _headers ,
4967 CURLOPT_FOLLOWLOCATION => 1 ,
5068 CURLOPT_SSL_VERIFYPEER => FALSE ,
51- ]);
69+ ];
70+ curl_setopt_array ($ ch , $ opts + $ _opts );
5271
5372 $ result = curl_exec ($ ch );
5473 $ info = curl_getinfo ($ ch );
5574 curl_close ($ ch );
5675
5776 if ($ info ['http_code ' ] > 300 ) {
58- throw new GithubException ($ uri , $ headers , [], $ info , $ result );
77+ throw new GithubException ($ url , $ headers , [], $ info , $ result );
5978 }
6079
6180 // Pure result
6281 if (strpos ($ info ['content_type ' ], 'application/json ' ) === FALSE ) {
63- return $ result ;
82+ return [ $ info , $ result] ;
6483 }
6584
6685 // Parse result from json
6786 if ($ result ) {
68- return @json_decode ($ result , TRUE );
87+ return [ $ info , @json_decode ($ result , TRUE )] ;
6988 } else {
70- return NULL ;
89+ return [ $ info , NULL ] ;
7190 }
7291 }
7392
0 commit comments