- Saved searches
- Use saved searches to filter your results more quickly
- License
- mpscholten/github-api
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- License
- KnpLabs/php-github-api
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- About
- Saved searches
- Use saved searches to filter your results more quickly
- diversen/simple-php-github-api
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
An easy to use github api client for php
License
mpscholten/github-api
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
An easy to use github api client for PHP.
You need php 5.4 or higher to use this library.
- very easy to use and ide-friendly
- pure object oriented interface
- automatically handled pagination
- psr-2
Install via composer: composer require mpscholten/github-api v0.3
< "require": < "mpscholten/github-api": "v0.3" > >
To use oauth just pass your oauth token to Github::create() like this.
use MPScholten\GitHubApi\Github; $github = Github::create('oauth token');
If you want to use the public api without any authentication you can do this by just calling Github::create without any arguments.
use MPScholten\GitHubApi\Github; $github = Github::create();
In case you are using oauth you can get the current logged-in user by calling
$user = Github::create('oauth token')->getCurrentUser();
Otherwise you can get users by their github username.
$user = Github::create()->getUser('mpscholten');
With the user object you can now do
$user->getEmail(); $user->getName(); $user->getUrl(); $user->getAvatarUrl(); // . // relations $user->getRepositories(); // returns an array of Repositories owned by the user $user->getOrganizations(); // list the users repositories foreach ($user->getRepositories() as $repository) < echo $repository->getName(); > // with the 'user:email' oauth scope $user->getPrimaryEmail(); $user->getEmails(); foreach ($user->getEmails() as $email) < if ($email->isVerified()) < echo $email; > >
$repository = Github::create()->getRepository('mpscholten', 'github-api'); $repository->getName(); $repository->getCommits(); $repository->getBranches(); $repository->getOwner(); // returns a user object $repository->getOwner()->getName(); // chaining // list the collaborators of the repo foreach ($repository->getCollaborators() as $collaborators) < echo $collaborators->getName(); >
foreach ($user->getOrganizations() as $org) < $org->getName(); // e.g. GitHub $org->getLocation(); // e.g. San Francisco >
You can use the search api by calling $github->getSearch()
// this is equals to https://github.com/search?q=language%3Aphp+&type=Repositories&ref=searchresults foreach (Github::create()->getSearch()->findRepositories('language:php') as $repo) < $repo->getName(); // . >
foreach ($repository->getReleases() as $release) < $release->getUrl(); // https://github.com/octocat/Hello-World/releases/v1.0.0 $release->getUrl('zipball'); // https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0 $release->getCreatedAt()->format('Y-m-d H:i:s'); >
foreach ($repository->getIssues() as $issue) < $issue->getLabels()->count(); $issue->getNumber(); // 2 $issue->getAuthor()->getLogin(); // "mpscholten" $issue->getTitle(); // "Add Issue-API" $issue->getBody(); $issue->isOpen(); $issue->isClosed(); $issue->getState(); >
Don’t worry about pagination, all paginated collections are using a custom Iterator so we can automatically load more results if you need them. So you can focus on what you really want to do.
Example This will print you all commits of the repository.
foreach ($repository->getCommits() as $commit) < echo $commit->getMessage() . "\n"; >
It’s builtin! By default we will use in-memory caching but you might want to use file caching. Just pass your cache directory to Github::create() , like this
use MPScholten\GitHubApi\Github; $github = Github::create('oauth token', 'my-cache-dir/');
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple PHP GitHub API client, Object Oriented, tested and documented.
License
KnpLabs/php-github-api
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
…novate[bot]) This PR was squashed before being merged into the 3.11.x-dev branch. Discussion ---------- Commits ------- 9d1ab1e feat: Support for Organization Runners 02bd5bc fix: StyleCI ea2f3ec docs: Add Organization Self-Hosted runner doc 6df9b8f docs: Add org runner link in README.md 70e7bbe Merge branch 'KnpLabs:master' into master 50a0ee1 Merge branch 'master' into master 370927e Merge branch 'KnpLabs:master' into master 91c8043 chore: change argument of `all` method to `$parameters` array ca94676 chore: fix StyleCi 5ff2a51 chore: minor fix 987a552 Add renovate.json 234a7a2 Merge pull request #1 from haridarshan/renovate/configure be15552 Update renovate.json 7483542 Delete renovate.json
Git stats
Files
Failed to load latest commit information.
README.md
A simple Object Oriented wrapper for GitHub API, written with PHP.
Uses GitHub API v3 & supports GitHub API v4. The object API (v3) is very similar to the RESTful API.
- Light and fast thanks to lazy loading of API classes
- Extensively tested and documented
This command will get you up and running quickly with a Guzzle HTTP client.
composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0
We are decoupled from any HTTP messaging client with help by HTTPlug.
Using a different http client
composer require knplabs/github-api:^3.0 symfony/http-client nyholm/psr7
To set up the Github client with this HTTP client
use Github\Client; use Symfony\Component\HttpClient\HttplugClient; $client = Client::createWithHttpClient(new HttplugClient());
To integrate this library in laravel Graham Campbell created graham-campbell/github. See the installation instructions to get started in laravel.
Basic usage of php-github-api client
// This file is generated by Composer require_once __DIR__ . '/vendor/autoload.php'; $client = new \Github\Client(); $repositories = $client->api('user')->repositories('ornicar');
From $client object, you have access to all available GitHub api endpoints.
This example uses the PSR6 cache pool redis-adapter. See http://www.php-cache.com/ for alternatives.
// This file is generated by Composer require_once __DIR__ . '/vendor/autoload.php'; use Cache\Adapter\Redis\RedisCachePool; $client = new \Redis(); $client->connect('127.0.0.1', 6379); // Create a PSR6 cache pool $pool = new RedisCachePool($client); $client = new \Github\Client(); $client->addCache($pool); // Do some request // Stop using cache $client->removeCache();
Using cache, the client will get cached responses if resources haven’t changed since last time, without reaching the X-Rate-Limit imposed by github.
See the doc directory for more detailed documentation.
php-github-api is licensed under the MIT License — see the LICENSE file for details
This library is maintained by the following people (alphabetically sorted) :
- Thanks to Thibault Duplessis aka. ornicar for his first version of this library.
- Thanks to Joseph Bielawski aka. stloyd for his contributions and support.
- Thanks to noloh for his contribution on the Object API.
- Thanks to bshaffer for his contribution on the Repo API.
- Thanks to Rolf van de Krol for his countless contributions.
- Thanks to Nicolas Pastorino for his contribution on the Pull Request API.
- Thanks to Edoardo Rivello for his contribution on the Gists API.
- Thanks to Miguel Piedrafita for his contribution to the v4 & Apps API.
- Thanks to Emre DEGER for his contribution to the Actions API.
Thanks to GitHub for the high quality API and documentation.
About
A simple PHP GitHub API client, Object Oriented, tested and documented.
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
diversen/simple-php-github-api
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Very simple github API for PHP using OAuth. 37 LOC for the API class. And a curl helper class with 84 LOC.
php composer.phar require diversen/simple-php-github-api:
Or if you have placed composer.phar in your path as composer
composer require diversen/simple-php-github-api
There is really only tree methods you can do. Let us see those three methods first. (Further below is an complete example using the built-in server for easy testing).
$access_config = array ( 'redirect_uri' => GITHUB_CALLBACK_URL, 'client_id' => GITHUB_ID, 'client_secret' => GITHUB_SECRET ); $api = new githubapi(); $res = $api->setAccessToken($access_config); if ($res) < // OK This is where we will call the api header("Location: /api_call.php"); > else < // Not OK. echo errors echo "Could not get access token. Errors:
"; print_r($api->errors); >
// We have a access token and we can now call the api: $api = new githubapi(); // Simple call - API get current users credentials // This can also be done without scope // example // $command = '/user', // $request = 'GET', 'POST' or 'PATCH' or 'DELETE' etc. Se API: // $post = variables to POST array $command = "/user"; $res = $api->apiCall($command, $request = null, $post = null); if (!$res) < print_r($api->errors); die; > else < print_r($res); >
Example you can run right away using the built-in PHP-server.
You will see something like this:
Enter base_dir of the simple-php-github-api :
cd vendor/diversen/simple-php-github-api
cp example/config.php-dist example/config.php
Set config in example/config.php according to above settings and the screenshot above.
Run test-server with example:
php -S localhost:8080 -t example/
For full listing of all API calls check:
I have not tested many calls — but you should be able to use all. E.g. POST, or PATCH, DELETE.
Create an issue, and Let me hear if it does not work out for you.