-
-
Notifications
You must be signed in to change notification settings - Fork 600
Gists API #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Gists API #5
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
826fb3f
Gists API integration: get list by username and
erivello c53e1ba
added gist api to client
erivello 8de6339
gist create api
erivello 5245ad5
create gist api refactor
erivello 4baecb7
delete gist api
erivello 5acc889
gist api functional test for getList method
erivello 690a969
gist api refactor: renamed delete method in remove method
erivello 1d3d647
unit tests for gist api
erivello 58bc417
functional test for gist api: get by id
erivello b8c1502
comment fix for gist api
erivello 36701a5
fix gist api documentation
erivello 2adb045
added delete method to gist api
erivello 2dc6c87
readme update
erivello a617177
readme update
erivello 4812621
pull request fixes
erivello 49bb59e
Gists API integration
erivello 870ab57
Merge branch 'master' of https://github.com/erivello/php-github-api
erivello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
namespace Github\Api; | ||
|
||
/** | ||
* Creating, editing, deleting and listing gists | ||
* | ||
* @link http://developer.github.com/v3/gists/ | ||
* @author Edoardo Rivello <edoardo.rivello at gmail dot com> | ||
* @license MIT License | ||
*/ | ||
class Gist extends Api | ||
{ | ||
/** | ||
* List gists by username | ||
* @link http://developer.github.com/v3/gists/ | ||
* | ||
* @param string $username the username | ||
* @return array list of gist found | ||
*/ | ||
public function getList($username) | ||
{ | ||
return $this->get('users/'.urlencode($username).'/gists'); | ||
} | ||
|
||
/** | ||
* Show a specific gist | ||
* @link http://developer.github.com/v3/gists/ | ||
* | ||
* @param string $id the gist id | ||
* @return array data from gist | ||
*/ | ||
public function getGist($id) | ||
{ | ||
return $this->get('gists/'.urlencode($id)); | ||
} | ||
|
||
/** | ||
* Create a new gist. | ||
* @link http://developer.github.com/v3/gists/ | ||
* | ||
* @param string $filename gist filename | ||
* @param string $content gist file contents | ||
* @param bool $public 1 for public, 0 for private | ||
* @param string $description gist description | ||
* @return array returns gist data | ||
*/ | ||
public function create($filename, $content, $public = false, $description = '') | ||
{ | ||
$input = array( | ||
'description' => $description, | ||
'public' => $public, | ||
'files' => array( | ||
$filename => array( | ||
'content' => $content | ||
) | ||
) | ||
); | ||
|
||
return $this->post('gists', $input); | ||
} | ||
|
||
/** | ||
* Edit a gist | ||
* @link http://developer.github.com/v3/gists/ | ||
* | ||
* @param string $id the gist id | ||
* @param array $values the key => value pairs to post | ||
* @return array informations about the gist | ||
*/ | ||
public function update($id, $values) | ||
{ | ||
return $this->patch('gists/'.urlencode($id), $values); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be changed as |
||
} | ||
|
||
/** | ||
* Remove a gist by id | ||
* @link http://developer.github.com/v3/gists/ | ||
* | ||
* @param int $id the gist id | ||
* @return Response | ||
*/ | ||
public function remove($id) | ||
{ | ||
return $this->delete('gists/'.urlencode($id)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api; | ||
|
||
use Github\Tests\ApiTestCase; | ||
|
||
class GistTest extends ApiTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldCreateGist() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$input = array( | ||
'description' => '', | ||
'public' => false, | ||
'files' => array( | ||
'filename.txt' => array( | ||
'content' => 'content' | ||
) | ||
) | ||
); | ||
|
||
$filename = 'filename.txt'; | ||
$content = 'content'; | ||
|
||
$api->expects($this->once()) | ||
->method('post') | ||
->with('gists', $input); | ||
|
||
$gist = $api->create($filename, $content); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUpdateGist() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$input = array( | ||
'description' => '', | ||
'files' => array( | ||
'filename.txt' => array( | ||
'filename' => 'new_name.txt', | ||
'content' => 'content' | ||
), | ||
'filename_new.txt' => array( | ||
'content' => 'content new' | ||
) | ||
) | ||
); | ||
|
||
$api->expects($this->once()) | ||
->method('patch') | ||
->with('gists/5', $input); | ||
|
||
$gist = $api->update(5, $input); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDeleteGist() | ||
{ | ||
$api = $this->getApiMock(); | ||
|
||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('gists/5'); | ||
|
||
$api->remove(5); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\Gist'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Functional; | ||
|
||
use Github\Client; | ||
|
||
class GistTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldRetrieveGistsListByUser() | ||
{ | ||
$username = 'KnpLabs'; | ||
|
||
$github = new Client(); | ||
$gists = $github->getGistApi()->getList($username); | ||
$gist = array_pop($gists); | ||
|
||
$this->assertArrayHasKey('url', $gist); | ||
$this->assertArrayHasKey('files', $gist); | ||
$this->assertArrayHasKey('comments', $gist); | ||
$this->assertArrayHasKey('created_at', $gist); | ||
$this->assertArrayHasKey('updated_at', $gist); | ||
$this->assertArrayHasKey('user', $gist); | ||
$this->assertEquals('KnpLabs', $gist['user']['login']); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldRetrieveGistById() | ||
{ | ||
$id = 1; | ||
|
||
$github = new Client(); | ||
$gist = $github->getGistApi()->getGist($id); | ||
|
||
$this->assertArrayHasKey('url', $gist); | ||
$this->assertArrayHasKey('files', $gist); | ||
$this->assertArrayHasKey('comments', $gist); | ||
$this->assertArrayHasKey('created_at', $gist); | ||
$this->assertArrayHasKey('updated_at', $gist); | ||
$this->assertArrayHasKey('user', $gist); | ||
$this->assertArrayHasKey('gistfile1.txt', $gist['files']); | ||
$this->assertEquals('schacon', $gist['user']['login']); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add functionality for types listings (all, public, starred) for authenticated user ?