@@ -367,15 +367,16 @@ class GitHubAPI {
367367 * Perform GET request to GitHub API and return answer.
368368 *
369369 * @access protected
370- * @param $command
370+ * @param string $command
371371 * String value. GitHub API url with tokens like :owner, :repo and ect.
372- * @param $params array
372+ * @param array $params
373373 * Values for request and tokens for request url. LIke :owner, :repo, :id and etc.
374+ * @param array $headers
375+ * Additional headers to be sent in the request.
374376 * @return stdClass|FALSE
375377 * FALSE if request failed. Object if success.
376378 */
377- public function getRequest ($ command , $ params = array ()) {
378-
379+ public function getRequest ($ command , $ params = array (), $ headers = array ()) {
379380 $ this ->prepareCommand ($ command , $ params );
380381
381382 if ($ this ->getToken ()) {
@@ -389,6 +390,12 @@ class GitHubAPI {
389390 return $ response ;
390391 }
391392
393+ // Always start with a fresh cURL object before each request.
394+ $ this ->reInitCurl ();
395+ foreach ($ headers as $ header_key => $ header_value ) {
396+ $ this ->curl ->setHeader ($ header_key , $ header_value );
397+ }
398+
392399 $ this ->curl ->get (GITHUB_API_URI . '/ ' . $ command , $ params );
393400 $ response = $ this ->getResponse ();
394401 $ this ->cacheRequest ($ command , $ params );
@@ -416,6 +423,7 @@ class GitHubAPI {
416423 $ query = '?access_token= ' . $ this ->getToken ();
417424 }
418425
426+ $ this ->reInitCurl ();
419427 $ this ->curl ->put (GITHUB_API_URI . '/ ' . $ command . $ query , $ params );
420428 $ response = $ this ->getResponse ();
421429 return $ response ;
@@ -439,6 +447,7 @@ class GitHubAPI {
439447 if ($ this ->getToken ()) {
440448 $ query = '?access_token= ' . $ this ->getToken ();
441449 }
450+ $ this ->reInitCurl ();
442451 $ this ->curl ->post (GITHUB_API_URI . '/ ' . $ command . $ query , $ params );
443452 $ response = $ this ->getResponse ();
444453 return $ response ;
@@ -464,6 +473,7 @@ class GitHubAPI {
464473 $ query = '?access_token= ' . $ this ->getToken ();
465474 }
466475
476+ $ this ->reInitCurl ();
467477 $ this ->curl ->delete (GITHUB_API_URI . '/ ' . $ command . $ query , $ params );
468478 $ response = $ this ->getResponse ();
469479 return $ response ;
@@ -728,19 +738,25 @@ class GitHubAPI {
728738 }
729739
730740 /**
731- * Get README.md file content from repository.
741+ * Get README.md file content from repository as HTML.
742+ *
732743 * https://developer.github.com/v3/repos/contents/#get-the-readme
733744 *
734745 * @return
735- * Return content of the file already decoded.
746+ * Return HTML content of the file already decoded.
736747 *
737748 * @see SetRepoName
738749 * @see SetOwnerName
739750 */
740751 public function getReadme () {
741- $ readme = $ this ->getRequest ('repos/:owner/:repo/readme ' );
742- if (!empty ($ readme ->content )) {
743- return base64_decode ($ readme ->content );
752+ $ readme = $ this ->getRequest ('repos/:owner/:repo/readme ' , array (
753+ ':owner ' => $ this ->owner_name ,
754+ ':repo ' => $ this ->repo_name ,
755+ ), array (
756+ 'Accept ' => 'application/vnd.github.v3.html ' ,
757+ ));
758+ if (is_string ($ readme )) {
759+ return $ readme ;
744760 }
745761 return FALSE ;
746762 }
0 commit comments