Permalink
Browse files

Merge pull request #1 from l3l0/add-to-travis

Add travis.yml file, fixed some code and tests
  • Loading branch information...
2 parents 73c0d8f + 3253653 commit b9733db4f563bce883c497fa42500e5b613bcc47 @stloyd stloyd committed May 26, 2012
View
@@ -0,0 +1,11 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
+
+before_script:
+ - curl -s http://getcomposer.org/installer | php
+ - php composer.phar update
+
+script: phpunit
View
@@ -1,46 +1,48 @@
-# PHP GitHub API
+# PHP GitHub API [WIP]
+
+[![Build Status](https://secure.travis-ci.org/KnpLabs/php-github-api.png?branch=api_v3)](http://travis-ci.org/KnpLabs/php-github-api)
+
+[WARNING] We are converting that lib into "github api v3" so some stuff is not working yet...
A simple Object Oriented wrapper for GitHub API, written with PHP5.
```php
- $github = new Github_Client();
+ $github = new Github\Client();
$myRepos = $github->getRepoApi()->getUserRepos('ornicar');
```
-Uses [GitHub API v2](http://develop.github.com/). The object API is very similar to the RESTful API.
+Uses [GitHub API v3](http://developer.github.com/v3/). The object API is very similar to the RESTful API.
## Features
-* Covers 100% of GitHub API with PHP methods
-* Supports 3 authentication methods
-* Follows PEAR conventions and coding standard: autoload friendly
+* Follows PSR-0 conventions and coding standard: autoload friendly
* Light and fast thanks to lazy loading of API classes
* Flexible and extensible thanks to dependency injection
* Extensively tested and documented
## Requirements
-* PHP 5.2 or 5.3.
-* [php curl](http://php.net/manual/en/book.curl.php), but it is possible to write another transport layer.
+* PHP >= 5.3
* PHPUnit to run tests.
## Autoload
-The first step to use php-github-api is to register its autoloader:
+The new version of php-github-api using [composer](http://getcomposer.org).
+The first step to use php-github-api is to download composer: `curl -s http://getcomposer.org/installer | php`
+Then we have to install our dependencies using `php composer.phar install`, now we can use autoloader from composer by:
```php
- require_once '/path/to/lib/Github/Autoloader.php';
- Github_Autoloader::register();
+ require_once 'vendor/autoload.php';
```
-Replace the `/path/to/lib/` path with the path you used for php-github-api installation.
+TODO: More examples how to install with composer. Some example of composer.json files. Add to packagist
-> php-github-api follows the PEAR convention names for its classes, which means you can easily integrate php-github-api classes loading in your own autoloader.
+> php-github-api follows the PSR-0 convention names for its classes, which means you can easily integrate php-github-api classes loading in your own autoloader.
## instantiate a new github client
```php
- $github = new Github_Client();
+ $github = new Github\Client();
```
From this object, you can access to all GitHub apis, listed below.
@@ -55,15 +57,9 @@ From this object, you can access to all GitHub apis, listed below.
<a href='#nav' alt='Back to the navigation'>Go back to the Navigation</a>
Searching users, getting user information and managing authenticated user account information.
-Wrap [GitHub User API](http://develop.github.com/p/users.html).
-
-### Search for users by username
-
-```php
- $users = $github->getUserApi()->search('ornicar');
-```
+Wrap [GitHub User API](http://developer.github.com/v3/users).
-Returns an array of users.
+### Search for users by username is depreciated cause of github api limitation.
### Get information about a user
@@ -700,16 +696,16 @@ Wanna change, let's say, the http client User Agent?
$github->getHttpClient()->setOption('user_agent', 'My new User Agent');
```
-See all available options in Github/HttpClient.php
+See all available options in Github/HttpClient/HttpClient.php
### Inject a new http client instance
php-github-api provides a curl-based implementation of a http client.
-If you want to use your own http client implementation, inject it to the Github_Client instance:
+If you want to use your own http client implementation, inject it to the Github\Client instance:
```php
// create a custom http client
- class MyHttpClient extends Github_HttpClient
+ class MyHttpClient extends Github\HttpClient\HttpClient
{
public function doRequest($url, array $parameters = array(), $httpMethod = 'GET', array $options = array())
{
@@ -720,10 +716,10 @@ If you want to use your own http client implementation, inject it to the Github_
> Your http client implementation may not extend Github_HttpClient, but only implement Github_HttpClientInterface.
-You can now inject your http client through Github_Client constructor:
+You can now inject your http client through Github\Client constructor:
```php
- $github = new Github_Client(new MyHttpClient());
+ $github = new Github\Client(new MyHttpClient());
```
Or to an existing Github_Client instance:
@@ -739,7 +735,7 @@ For example, to replace the user API:
```php
// create a custom User API
- class MyGithubApiUser extends Github_Api_User
+ class MyGithubApiUser extends Github\Api\User
{
// overwrite things
}
View
@@ -18,16 +18,24 @@ class Issue extends Api
* @param string $username the username
* @param string $repo the repo
* @param string $state the issue state, can be open or closed
+ * @param array $state the additional parameters like milestone, assignee, lables, sort, direction
* @return array list of issues found
*/
- public function getList($username, $repo, $state = 'open')
+ public function getList($username, $repo, $state = null, $parameters = array())
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues?state='.urlencode($state));
+ $url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/issues';
+ if ($state) {
+ $parameters['state'] = $state;
+ }
+ if ($parameters) {
+ $url .= '?'.http_build_query($parameters);
+ }
+
+ return $this->get($url);
}
/**
* Search issues by username, repo, state and search term
- * http://develop.github.com/p/issues.html#list_a_projects_issues
*
* @param string $username the username
* @param string $repo the repo
@@ -88,7 +96,7 @@ public function open($username, $repo, $title, $body)
/**
* Close an existing issue by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#open_and_close_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -102,7 +110,7 @@ public function close($username, $repo, $number)
/**
* Update issue informations by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#edit_existing_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -113,12 +121,12 @@ public function close($username, $repo, $number)
*/
public function update($username, $repo, $number, array $data)
{
- return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
+ return $this->patch('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
}
/**
* Repoen an existing issue by username, repo and issue number. Requires authentication.
- * http://develop.github.com/p/issues.html#open_and_close_issues
+ * @link http://developer.github.com/v3/issues/
*
* @param string $username the username
* @param string $repo the repo
@@ -132,7 +140,7 @@ public function reOpen($username, $repo, $number)
/**
* List an issue comments by username, repo and issue number
- * http://develop.github.com/p/issues.html#list_an_issues_comments
+ * @link http://developer.github.com/v3/issues/comments/
*
* @param string $username the username
* @param string $repo the repo
@@ -150,13 +158,12 @@ public function getComments($username, $repo, $number)
*
* @param string $username the username
* @param string $repo the repo
- * @param string $number the issue number
* @param string $id the comment id
* @return array list of issue comments
*/
- public function getComment($username, $repo, $number, $id)
+ public function getComment($username, $repo, $id)
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments/'.urlencode($id));
+ return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/comments/'.urlencode($id));
}
/**
@@ -21,9 +21,14 @@ class PullRequest extends Api
* The API seems to automatically default to 'open'
* @return array array of pull requests for the project
*/
- public function listPullRequests($username, $repo, $state = 'open')
+ public function listPullRequests($username, $repo, $state = null)
{
- return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls?state='.urlencode($state));
+ $url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/pulls';
+ if ($state) {
+ $url .= '?state='.urlencode($state);
+ }
+
+ return $this->get($url);
}
/**
@@ -43,7 +48,7 @@ public function show($username, $repo, $id)
/**
* Create a pull request
*
- * @link http://develop.github.com/p/pulls.html
+ * @link http://developer.github.com/v3/pulls/
* @param string $username the username
* @param string $repo the repo
* @param string $base A String of the branch or commit SHA that you want your changes to be pulled to.
@@ -52,15 +57,23 @@ public function show($username, $repo, $id)
* specify the username first: "my-user:some-branch".
* @param string $title The String title of the Pull Request. Used in pair with $body.
* @param string $body The String body of the Pull Request. Used in pair with $title.
+ * @param string $issueNumber The issue number. Used when title and body is not set.
* @return array array of pull requests for the project
*/
- public function create($username, $repo, $base, $head, $title, $body = null)
+ public function create($username, $repo, $base, $head, $title, $body = null, $issueNumber = null)
{
- return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', array(
+ $input = array(
'head' => $head,
'base' => $base,
- 'title' => $title,
- 'body' => $body,
- ));
+ );
+
+ if ($title || $body) {
+ $input['title'] = $title;
+ $input['body'] = $body;
+ } else {
+ $input['issue'] = $issueNumber;
+ }
+
+ return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/pulls', $input);
}
}
Oops, something went wrong.

0 comments on commit b9733db

Please sign in to comment.