•DS://
About

A complete PHP library for GitHub API v3

 • 3 minutes read

GitHub is a popular web-based Git repository hosting service, which offers all of the distributed revision control and source code management functionality of Git as well as adding its own features.

Since may 2013, GitHub announced Octokit, a new lineup of GitHub-maintained client libraries for the GitHub API. This means Octokit provide officially 3 libraries written in Ruby, Objective-C and .NET.

However, third-party libraries are available in other languages and particularly in PHP. At this time you can find at least 9 libraries to interact with GitHub API in PHP but none of this libraries provide a full support for all GitHub API features.

This library as been developed to help you to use all the features of GitHub API v3 easily as possible. This library, like the GitHub API is sparate in 2 distinct parts:

  1. The Client part who will be used to get informations about a repository, a user, a commit, …
  2. The Server part, called WebHooks that can be used to get events from GitHub API

Features

This library provide the next features:

  • Supports all methods (Activity, Enterprise, Gists, Git Data, Issues, Miscellaneous, Organizations, Pull Requests, Repositories, Search, Users)
  • Supports Basic, OAuth and OAuth2 authentications.
  • Able to create a WebHooks server.

Minimum requirements

To run this library in your web server, you’ll need the most recent PHP version of the branch 5.6.x. for some security and dependencies reasons.

This library is only compatible with PHP 5.6.1 or above. So please upgrade your PHP version if you have a lower version installed.

You will also need the cURL extension enabled in your web server.

Dependencies

This library use some dependencies to work with.

Here are the dependencies this library need to be installed with:

Installation

To get the latest version of this GitHub API library simply use composer.

  1. You need to add this library to composer.json file:
1$ php composer.phar require scion/githubapi
  1. Then you can install this library and all the dependencies using:
1$ php composer.phar install

Client

1<?php 2// This file is generated by Composer 3require 'vendor/autoload.php'; 4 5// Create a Client object 6$client = new \Scion\GitHub\Client();

WebHook

Webhooks allow you to build or set up integrations which subscribe to certain events on GitHub.com.

Complete documentation is available at https://developer.github.com/webhooks/.

For using a WebHook, you need an instance of Scion\GitHub\WebHook class like:

1<?php 2// This file is generated by Composer 3require 'vendor/autoload.php'; 4 5// Creating WebHook instance 6$webhook = new \Scion\GitHub\WebHook();

Authentication

This library supports all authentications provided by the GitHub API v3. You can use the Basic Authentication, OAuth Token or the OAuth2 Key/Secret pair authentication for the Client and WebHook classes, like described here:

Basic Authentication

1// Username only 2$client->setHttpAuth('username'); 3 4// Username & password 5$client->setHttpAuth('username', 'password');

OAuth Token

Go to Authorized applications to Generate new token, then you will be able to provide your 'token'.

1// sent in userpwd 2$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); 3 4// sent in a header 5$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', \Scion\Github\Client::OAUTH2_HEADER_AUTH); 6 7// sent as a parameter 8$client->setToken('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', \Scion\Github\Client::OAUTH2_PARAMETERS_AUTH);

OAuth2 Key/Secret pair

Go to Authorized applications to Register new application, then you will be able to provide yours client_id and client_secret.

1$client->setClientId(''); // Set client_id 2$client->setClientSecret(''); // Set client_secret

You can find the full documentation of this library in the wiki section of the GitHub repository.


© 2013-2024 All rights reserved.

Built with Next.js. Designed with in Montreal