@@ -114,12 +114,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
114114 // Get a new Uri object focusing the api url and given path.
115115 $ uri = new Uri ($ this ->options ->get ('api.url ' ) . $ path );
116116
117- if ($ this ->options ->get ('gh.token ' , false ))
118- {
119- // Use oAuth authentication - @todo set in request header ?
120- $ uri ->setVar ('access_token ' , $ this ->options ->get ('gh.token ' ));
121- }
122- else
117+ if (!$ this ->options ->get ('gh.token ' , false ))
123118 {
124119 // Use basic authentication
125120 if ($ this ->options ->get ('api.username ' , false ))
@@ -136,16 +131,37 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
136131 // If we have a defined page number add it to the JUri object.
137132 if ($ page > 0 )
138133 {
139- $ uri ->setVar ('page ' , (int ) $ page );
134+ $ uri ->setVar ('page ' , (int )$ page );
140135 }
141136
142137 // If we have a defined items per page add it to the JUri object.
143138 if ($ limit > 0 )
144139 {
145- $ uri ->setVar ('per_page ' , (int ) $ limit );
140+ $ uri ->setVar ('per_page ' , (int )$ limit );
146141 }
147142
148- return (string ) $ uri ;
143+ return (string )$ uri ;
144+ }
145+
146+ /**
147+ * Returns the Authorization header, if required.
148+ *
149+ * If the options passed to the constructor contain a value for `gh.token`,
150+ * an array with a suitable Authorization header is returned, an empty array
151+ * otherwise.
152+ *
153+ * @return array Authorization header if set in options.
154+ *
155+ * @since 1.8.0
156+ */
157+ protected function authHeader ()
158+ {
159+ if ($ this ->options ->get ('gh.token ' , false ))
160+ {
161+ return array ('Authorization: ' . $ this ->options ->get ('gh.token ' ));
162+ }
163+
164+ return array ();
149165 }
150166
151167 /**
@@ -156,8 +172,8 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
156172 *
157173 * @return mixed
158174 *
159- * @since 1.0
160175 * @throws UnexpectedResponseException
176+ * @since 1.0
161177 */
162178 protected function processResponse (Response $ response , $ expectedCode = 200 )
163179 {
0 commit comments