Skip to content

Commit 2ea5d50

Browse files
committed
Update Authorizations API
1 parent 3c36776 commit 2ea5d50

File tree

2 files changed

+153
-28
lines changed

2 files changed

+153
-28
lines changed

lib/Github/Api/Authorizations.php

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,122 @@
22

33
namespace Github\Api;
44

5-
use Github\Api\AbstractApi;
6-
75
/**
86
* Creating, deleting and listing authorizations.
97
*
10-
* @link http://developer.github.com/v3/oauth/
8+
* @link http://developer.github.com/v3/oauth_authorizations/
9+
* @author Evgeniy Guseletov <[email protected]>
1110
*/
1211
class Authorizations extends AbstractApi
1312
{
13+
/**
14+
* List all authorizations.
15+
*
16+
* @return array
17+
*/
1418
public function all()
1519
{
1620
return $this->get('authorizations');
1721
}
1822

19-
public function show($number)
23+
/**
24+
* Show a single authorization.
25+
*
26+
* @param $clientId
27+
*
28+
* @return array
29+
*/
30+
public function show($clientId)
2031
{
21-
return $this->get('authorizations/'.rawurlencode($number));
32+
return $this->get('authorizations/'.rawurlencode($clientId));
2233
}
2334

35+
/**
36+
* Create an authorization.
37+
*
38+
* @param array $params
39+
* @param null $OTPCode
40+
*
41+
* @return array
42+
*/
2443
public function create(array $params, $OTPCode = null)
2544
{
2645
$headers = null === $OTPCode ? array() : array('X-GitHub-OTP' => $OTPCode);
2746

2847
return $this->post('authorizations', $params, $headers);
2948
}
3049

31-
public function update($id, array $params)
50+
/**
51+
* Update an authorization.
52+
*
53+
* @param $clientId
54+
* @param array $params
55+
*
56+
* @return array
57+
*/
58+
public function update($clientId, array $params)
59+
{
60+
return $this->patch('authorizations/'.rawurlencode($clientId), $params);
61+
}
62+
63+
/**
64+
* Remove an authorization.
65+
*
66+
* @param $clientId
67+
*
68+
* @return array
69+
*/
70+
public function remove($clientId)
71+
{
72+
return $this->delete('authorizations/'.rawurlencode($clientId));
73+
}
74+
75+
/**
76+
* Check an authorization.
77+
*
78+
* @param $clientId
79+
* @param $token
80+
*
81+
* @return array
82+
*/
83+
public function check($clientId, $token)
84+
{
85+
return $this->get('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
86+
}
87+
88+
/**
89+
* Reset an authorization.
90+
*
91+
* @param $clientId
92+
* @param $token
93+
*
94+
* @return array
95+
*/
96+
public function reset($clientId, $token)
3297
{
33-
return $this->patch('authorizations/'.rawurlencode($id), $params);
98+
return $this->post('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
3499
}
35100

36-
public function remove($id)
101+
/**
102+
* Remove an authorization.
103+
*
104+
* @param $clientId
105+
* @param $token
106+
*
107+
* @return array
108+
*/
109+
public function revoke($clientId, $token)
37110
{
38-
return $this->delete('authorizations/'.rawurlencode($id));
111+
return $this->delete('applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token));
39112
}
40113

41-
public function check($id, $token)
114+
/**
115+
* Revoke all authorizations.
116+
*
117+
* @param $clientId
118+
*/
119+
public function revokeAll($clientId)
42120
{
43-
return $this->get('authorizations/'.rawurlencode($id).'/tokens/'.rawurlencode($token));
121+
$this->delete('applications/'.rawurlencode($clientId).'/tokens');
44122
}
45123
}

test/Github/Tests/Api/AuthorizationsTest.php

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,55 @@ public function shouldShowAuthorization()
3737
$this->assertEquals($expectedArray, $api->show($id));
3838
}
3939

40+
/**
41+
* @test
42+
*/
43+
public function shouldAuthorization()
44+
{
45+
$input = array(
46+
'note' => '',
47+
);
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('post')
52+
->with('authorizations', $input);
53+
54+
$api->create($input);
55+
}
56+
57+
/**
58+
* @test
59+
*/
60+
public function shouldUpdateAuthorization()
61+
{
62+
$id = 123;
63+
$input = array(
64+
'note' => '',
65+
);
66+
67+
$api = $this->getApiMock();
68+
$api->expects($this->once())
69+
->method('patch')
70+
->with('authorizations/'.$id, $input);
71+
72+
$api->update($id, $input);
73+
}
74+
75+
/**
76+
* @test
77+
*/
78+
public function shouldDeleteAuthorization()
79+
{
80+
$id = 123;
81+
$api = $this->getApiMock();
82+
$api->expects($this->once())
83+
->method('delete')
84+
->with('authorizations/'.$id);
85+
86+
$api->remove($id);
87+
}
88+
4089
/**
4190
* @test
4291
*/
@@ -49,7 +98,7 @@ public function shouldCheckAuthorization()
4998
$api = $this->getApiMock();
5099
$api->expects($this->once())
51100
->method('get')
52-
->with('authorizations/'.$id.'/tokens/'.$token)
101+
->with('applications/'.$id.'/tokens/'.$token)
53102
->will($this->returnValue($expectedArray));
54103

55104
$this->assertEquals($expectedArray, $api->check($id, $token));
@@ -58,50 +107,48 @@ public function shouldCheckAuthorization()
58107
/**
59108
* @test
60109
*/
61-
public function shouldAuthorization()
110+
public function shouldResetAuthorization()
62111
{
63-
$input = array(
64-
'note' => '',
65-
);
112+
$id = 123;
113+
$token = 'abcde';
66114

67115
$api = $this->getApiMock();
68116
$api->expects($this->once())
69117
->method('post')
70-
->with('authorizations', $input);
118+
->with('applications/'.$id.'/tokens/'.$token);
71119

72-
$api->create($input);
120+
$api->reset($id, $token);
73121
}
74122

75123
/**
76124
* @test
77125
*/
78-
public function shouldUpdateAuthorization()
126+
public function shouldRevokeAuthorization()
79127
{
80128
$id = 123;
81-
$input = array(
82-
'note' => '',
83-
);
129+
$token = 'abcde';
84130

85131
$api = $this->getApiMock();
86132
$api->expects($this->once())
87-
->method('patch')
88-
->with('authorizations/'.$id, $input);
133+
->method('delete')
134+
->with('applications/'.$id.'/tokens/'.$token);
89135

90-
$api->update($id, $input);
136+
$api->revoke($id, $token);
91137
}
92138

93139
/**
94140
* @test
95141
*/
96-
public function shouldDeleteAuthorization()
142+
public function shouldRevokeAllAuthorizations()
97143
{
98144
$id = 123;
145+
99146
$api = $this->getApiMock();
100147
$api->expects($this->once())
101148
->method('delete')
102-
->with('authorizations/'.$id);
149+
->with('applications/'.$id.'/tokens');
103150

104-
$api->remove($id);
151+
$api->revokeAll($id);
105152
}
106153

107154
protected function getApiClass()

0 commit comments

Comments
 (0)