PHP Classes

Github PHP API Library: Get responses to requests to the Github API

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 79 This week: 1All time: 10,092 This week: 560Up
Version License PHP version Categories
phpgithub 1.3.0Free for non-comm...7PHP 5, Files and Folders, Web services, P...
Description 

Author

This library class provides functions to work with the GitHub API v3.

It can send a HTTP request to the GitHub API Web server to perform queries using a given API URL.

The class returns an object with several details of the API response like an:

- The API call success status
- An error that may have occurred in case it failed
- The API response data, content type and content length
- The HTTP response code
- The API server IP address

Picture of Mat Jung
  Performance   Level  
Name: Mat Jung <contact>
Classes: 4 packages by
Country: Switzerland Switzerland
Age: 47
All time rank: 389531 in Switzerland Switzerland
Week rank: 416 Up7 in Switzerland Switzerland Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php
$loc_class_path
="..\classes";
set_include_path(get_include_path() . PATH_SEPARATOR . $loc_class_path);
include(
"phpGithub.php");
$hub = new php\github\phpGithub();
echo
$hub->getHubhost();
$hub->AddCurlConfig(CURLOPT_CAINFO, "/path/to/php/curl/cacert.pem");

$response=$hub->returnRoot();
if(
$response->success) {
# echo $response->response;
# print_r($response->info);
   
echo $response->urlip ." " . $response->url ." " . $response->http_code . "<br>";
}

/* returnContent with string 1.1.2 */
$repo="openZH/covid_19";
$content="fallzahlen_kanton_total_csv";
$response=$hub->returnContent($repo,$content);

echo
$response->response;

// no need to download the repository before downloading content 1.1.2


/* https://github.com/openZH/covid_19/tree/master/fallzahlen_kanton_total_csv */
#$response=$hub->returnRepository("CSSEGISandData","COVID-19");
$response=$hub->returnRepository("openZH","covid_19");
if(
$response->success) {
    echo
$response->urlip ." " . $response->url ." " . $response->http_code . "<br>";
# hub\helper::printTableFromArray($response->info);
# hub\helper::printTableFromArray($response->response);
   
$repo=$response->response;
# $response=$hub->returnRootContent($repo);
   
$response=$hub->returnContent($repo, "fallzahlen_kanton_total_csv");
    if(
$response->success) {
        echo
$response->urlip ." " . $response->url ." " . $response->http_code . "<br>";
       
$contents=$response->response;
        echo
$hub->hasContentsFolder()."<hr>";
# hub\helper::printTableFromJson($contents);
       
foreach($hub->getContentsIterator($contents) as $entry)
        {
# echo $entry->type ." ". $entry->name ."<br>";
       
}
       
$files=new php\github\phpGithubContent($contents);
        foreach(
$files->getIterator() as $entry)
        {
# echo $entry->type ." ". $entry->name ." " . $entry->path . "<br>";
       
}
        echo
$files->hasFilenameLike("ZH");
        echo
"<br>".$files->cntFilenameLike("ZH");
        echo
$files->getPathnameLike("ZH");
    }
}

$response=$hub->returnContent($repo, $files->getPathnameLike("ZH"));
if(
$response->success) {
    echo
$response->urlip ." " . $response->url ." " . $response->http_code . "<br>";
# echo $response;
# hub\helper::printTableFromArray($response->response);
   
$files=new php\github\phpGithubContent($response->response);
    echo
$files->isArray."<br>";
    echo
$files->isObject."<br>";
    echo
$files->getEncodedContent();
    echo
$files->getContentProperty("download_url");
}
   
   
echo
$hub->getLastErrorMessage();

?>


Details

The class has a dependency with PHP cURL https://www.php.net/manual/en/book.curl.php If that is not working for you, the class won't work for you. Class namespace: namespace php\github; Instantiation: $hub = new php\github\phpGithub(); Optional $hub->AddCurlConfig(CURLOPT_CAINFO, "/path/to/php/curl/cacert.pem"); Sample client $response=$hub->returnRoot(); if($response->success) { echo $response->urlip ." " . $response->url ." " . $response->http_code . "<br>"; } Sample output 140.82.112.6 https://api.github.com/ 200 In tab Example you find a more comprehensive sample github api client

  GitHub Repository Directory TreeExternal page   Invite yourself to GitHub RepoExternal page  

Open in a separate window

Open in a separate window

  Files folder image Files  
File Role Description
Files folder imageconsumer (1 directory)
Accessible without login Plain text file ghacadduser2repo.php Example Sample invite friends to GitHub Repository
Accessible without login Plain text file githubclient.php Example Sample php client that works with phpGitHub
Accessible without login Plain text file githubclient_current_user.php Example Sample client for calling current_user_url https://api.github.com/user
Accessible without login Plain text file githubclient_repository_content_tree.php Example GitHub Content Tree Walker
Accessible without login Plain text file githubclient_userprofile.php Example Example for phpGithubUser
Plain text file hubHelper.php Class class helper
Plain text file phpGithub.php Class class phpGithub
Plain text file phpGithubContent.php Class class phpGithubContent
Accessible without login Plain text file phpGithubServiceArray.php Appl. AssociativeArray gh mapping between service name and api url
Plain text file phpGithubUser.php Class class phpGithubUser Model for Github user
Plain text file phpHubResult.php Class class phpHubResult
Accessible without login Plain text file Readme Doc. Readme

  Files folder image Files  /  consumer  
File Role Description
Files folder imagejhu (1 file)

  Files folder image Files  /  consumer  /  jhu  
File Role Description
  Accessible without login Plain text file web.php Example Returns todays covid file from JHU repository

 Version Control Unique User Downloads Download Rankings  
 0%
Total:79
This week:1
All time:10,092
This week:560Up