Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed authorizations api
  • Loading branch information
GrahamCampbell committed Feb 19, 2015
commit 50e837eddc8c61fb9f5b5c97491ca669656da336
12 changes: 11 additions & 1 deletion lib/Github/Api/Authorizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public function remove($id)

public function check($id, $token)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest renaming id to clientId to be more explicit about which id it is (the github doc describes it as client_id btw): https://developer.github.com/v3/oauth_authorizations/#check-an-authorization

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GrahamCampbell rename please it would be clear

{
return $this->get('authorizations/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
return $this->get('applications/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
}

public function revoke($id, $token)
{
return $this->delete('applications/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
}

public function revokeAll($id)
{
return $this->delete('applications/'.rawurlencode($id).'/tokens');
}
}
37 changes: 36 additions & 1 deletion test/Github/Tests/Api/AuthorizationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,47 @@ public function shouldCheckAuthorization()
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('authorizations/'.$id.'/tokens/'.$token)
->with('applications/'.$id.'/tokens/'.$token)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->check($id, $token));
}

/**
* @test
*/
public function shouldRevokeAuthorization()
{
$id = 123;
$token = 'abc';
$expectedArray = array('id' => $id);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('applications/'.$id.'/tokens/'.$token)
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->revoke($id, $token));
}

/**
* @test
*/
public function shouldRevokeAllAuthorizations()
{
$id = 123;
$expectedArray = array('id' => $id);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('applications/'.$id.'/tokens')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->revokeAll($id));
}

/**
* @test
*/
Expand Down