PHP Classes

File: githubclient.php

Recommend this page to a friend!
  Classes of Mat Jung  >  Github PHP API Library  >  githubclient.php  >  Download  
File: githubclient.php
Role: Example script
Content type: text/plain
Description: Sample php client that works with phpGitHub
Class: Github PHP API Library
Get responses to requests to the Github API
Author: By
Last change: sample for returnContent with string added
Date: 2 years ago
Size: 2,495 bytes
 

Contents

Class file image Download
<?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();

?>

For more information send a message to info at phpclasses dot org.