Skip to content

Commit ef4ee3a

Browse files
committed
Changed user and repo api. Added patch and delete and put methods
1 parent efd69fa commit ef4ee3a

File tree

7 files changed

+295
-94
lines changed

7 files changed

+295
-94
lines changed

lib/Github/Api/Api.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,42 @@ protected function post($path, array $parameters = array(), $requestOptions = ar
5353
{
5454
return $this->client->post($path, $parameters, $requestOptions);
5555
}
56+
57+
/**
58+
* Call any path, PATCH method
59+
* Ex: $api->patch('repos/show/my-username/my-repo')
60+
*
61+
* @param string $path the GitHub path
62+
* @param array $parameters PATCH parameters
63+
* @param array $requestOptions reconfigure the request
64+
* @return array data returned
65+
*/
66+
protected function patch($path, array $parameters = array(), $requestOptions = array())
67+
{
68+
return $this->client->patch($path, $parameters, $requestOptions);
69+
}
70+
71+
/**
72+
* Call any path, PUT method
73+
*
74+
* @param string $path the GitHub path
75+
* @param array $requestOptions reconfigure the request
76+
* @return array data returned
77+
*/
78+
protected function put($path, array $parameters = array(), $requestOptions = array())
79+
{
80+
return $this->client->put($path, $parameters, $requestOptions);
81+
}
82+
83+
/**
84+
* Call any path, DELETE method
85+
*
86+
* @param string $path the GitHub path
87+
* @param array $requestOptions reconfigure the request
88+
* @return array data returned
89+
*/
90+
protected function delete($path, array $parameters = array(), $requestOptions = array())
91+
{
92+
return $this->client->delete($path, $parameters, $requestOptions);
93+
}
5694
}

lib/Github/Api/Repo.php

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Repo extends Api
2323
*/
2424
public function search($query, $language = '', $startPage = 1)
2525
{
26+
//todo old api
2627
$response = $this->get('repos/search/'.urlencode($query), array(
2728
'language' => strtolower($language),
2829
'start_page' => $startPage
@@ -43,18 +44,6 @@ public function getUserRepos($username)
4344
return $this->get('users/'.urlencode($username).'/repos');
4445
}
4546

46-
/**
47-
* Get a list of the repositories that the authenticated user can push to
48-
*
49-
* @return array list of repositories
50-
*/
51-
public function getPushableRepos()
52-
{
53-
$response = $this->get('repos/pushable');
54-
55-
return $response['repositories'];
56-
}
57-
5847
/**
5948
* Get extended information about a repository by its username and repo name
6049
*
@@ -69,7 +58,6 @@ public function show($username, $repo)
6958

7059
/**
7160
* create repo
72-
* http://develop.github.com/p/repo.html
7361
*
7462
* @param string $name name of the repository
7563
* @param string $description repo description
@@ -79,19 +67,16 @@ public function show($username, $repo)
7967
*/
8068
public function create($name, $description = '', $homepage = '', $public = true)
8169
{
82-
$response = $this->post('repos/create', array(
70+
return $this->post('user/repos', array(
8371
'name' => $name,
8472
'description' => $description,
8573
'homepage' => $homepage,
86-
'public' => $public
74+
'private' => !$public
8775
));
88-
89-
return $response['repository'];
9076
}
9177

9278
/**
9379
* delete repo
94-
* http://develop.github.com/p/repo.html
9580
*
9681
* @param string $name name of the repository
9782
* @param string $token delete token
@@ -101,6 +86,7 @@ public function create($name, $description = '', $homepage = '', $public = true)
10186
*/
10287
public function delete($name, $token = null, $force = false)
10388
{
89+
//todo old api
10490
if ($token === null) {
10591
$response = $this->post('repos/delete/'.urlencode($name));
10692

@@ -120,7 +106,6 @@ public function delete($name, $token = null, $force = false)
120106

121107
/**
122108
* Set information of a repository
123-
* http://develop.github.com/p/repo.html
124109
*
125110
* @param string $username the user who owns the repo
126111
* @param string $repo the name of the repo
@@ -129,89 +114,77 @@ public function delete($name, $token = null, $force = false)
129114
*/
130115
public function setRepoInfo($username, $repo, $values)
131116
{
132-
$response = $this->post('repos/show/'.urlencode($username).'/'.urlencode($repo), array('values' => $values));
133-
134-
return $response['repository'];
117+
return $this->patch('repos/'.urlencode($username).'/'.urlencode($repo), $values);
135118
}
136119

137120
/**
138121
* Set the visibility of a repostory to public
139-
* http://develop.github.com/p/repo.html
140122
*
123+
* @param string $username the user who owns the repo
141124
* @param string $repo the name of the repo
142125
* @return array informations about the repo
143126
*/
144-
public function setPublic($repo)
127+
public function setPublic($username, $repo)
145128
{
146-
$response = $this->get('repos/set/public/'.urlencode($repo));
147-
148-
return $response['repository'];
129+
$this->setRepoInfo($username, $repo, array('private' => false));
149130
}
150131

151132
/**
152133
* Set the visibility of a repostory to private
153-
* http://develop.github.com/p/repo.html
154134
*
135+
* @param string $username the user who owns the repo
155136
* @param string $repo the name of the repo
156137
* @return array informations about the repo
157138
*/
158-
public function setPrivate($repo)
139+
public function setPrivate($username, $repo)
159140
{
160-
$response = $this->get('repos/set/private/'.urlencode($repo));
161-
162-
return $response['repository'];
141+
$this->setRepoInfo($username, $repo, array('private' => true));
163142
}
164143

165144
/**
166145
* Get the list of deploy keys for a repository
167146
*
147+
* @param string $username the user who owns the repo
168148
* @param string $repo the name of the repo
169149
* @return array the list of deploy keys
170150
*/
171-
public function getDeployKeys($repo)
151+
public function getDeployKeys($username, $repo)
172152
{
173-
$response = $this->get('repos/keys/'.urlencode($repo));
174-
175-
return $response['public_keys'];
153+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/keys');
176154
}
177155

178156
/**
179157
* Add a deploy key for a repository
180158
*
159+
* @param string $username the user who owns the repo
181160
* @param string $repo the name of the repo
182161
* @param string $title the title of the key
183162
* @param string $key the public key data
184163
* @return array the list of deploy keys
185164
*/
186-
public function addDeployKey($repo, $title, $key)
165+
public function addDeployKey($username, $repo, $title, $key)
187166
{
188-
$response = $this->post('repos/key/'.urlencode($repo).'/add', array(
167+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/keys', array(
189168
'title' => $title,
190169
'key' => $key
191170
));
192-
193-
return $response['public_keys'];
194171
}
195172

196173
/**
197174
* Delete a deploy key from a repository
198175
*
176+
* @param string $username the user who owns the repo
199177
* @param string $repo the name of the repo
200178
* @param string $id the the id of the key to remove
201179
* @return array the list of deploy keys
202180
*/
203-
public function removeDeployKey($repo, $id)
181+
public function removeDeployKey($username, $repo, $id)
204182
{
205-
$response = $this->post('repos/key/'.urlencode($repo).'/remove', array(
206-
'id' => $id,
207-
));
208-
209-
return $response['public_keys'];
183+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/keys/'.urlencode($id));
210184
}
211185

212186
/**
213187
* Get the collaborators of a repository
214-
* http://develop.github.com/p/repo.html
215188
*
216189
* @param string $username the user who owns the repo
217190
* @param string $repo the name of the repo

lib/Github/Api/User.php

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class User extends Api
2121
*/
2222
public function search($username)
2323
{
24+
//old api to do
2425
$response = $this->get('user/search/'.urlencode($username));
2526

2627
return $response['users'];
@@ -35,81 +36,68 @@ public function search($username)
3536
*/
3637
public function show($username)
3738
{
38-
$response = $this->get('user/show/'.urlencode($username));
39-
40-
return $response['user'];
39+
return $this->get('users/'.urlencode($username));
4140
}
4241

4342
/**
4443
* Update user informations. Requires authentication.
45-
* http://develop.github.com/p/users.html#authenticated_user_management
44+
* http://developer.github.com/v3/users/
4645
*
47-
* @param string $username the username to update
4846
* @param array $data key=>value user attributes to update.
4947
* key can be name, email, blog, company or location
5048
* @return array informations about the user
5149
*/
52-
public function update($username, array $data)
50+
public function update(array $data)
5351
{
54-
$response = $this->post('user/show/'.urlencode($username), array('values' => $data));
55-
56-
return $response['user'];
52+
return $this->patch('user', $data);
5753
}
5854

5955
/**
6056
* Request the users that a specific user is following
61-
* http://develop.github.com/p/users.html#following_network
57+
* http://developer.github.com/v3/users/followers/
6258
*
6359
* @param string $username the username
6460
* @return array list of followed users
6561
*/
6662
public function getFollowing($username)
6763
{
68-
$response = $this->get('user/show/'.urlencode($username).'/following');
69-
70-
return $response['users'];
64+
return $this->get('users/'.urlencode($username).'/following');
7165
}
7266

7367
/**
7468
* Request the users following a specific user
75-
* http://develop.github.com/p/users.html#following_network
69+
* http://developer.github.com/v3/users/followers/
7670
*
7771
* @param string $username the username
7872
* @return array list of following users
7973
*/
8074
public function getFollowers($username)
8175
{
82-
$response = $this->get('user/show/'.urlencode($username).'/followers');
83-
84-
return $response['users'];
76+
return $this->get('users/'.urlencode($username).'/followers');
8577
}
8678

8779
/**
8880
* Make the authenticated user follow the specified user. Requires authentication.
89-
* http://develop.github.com/p/users.html#following_network
81+
* http://developer.github.com/v3/users/followers/
9082
*
9183
* @param string $username the username to follow
9284
* @return array list of followed users
9385
*/
9486
public function follow($username)
9587
{
96-
$response = $this->post('user/follow/'.urlencode($username));
97-
98-
return $response['users'];
88+
return $this->put('user/following/'.urlencode($username));
9989
}
10090

10191
/**
10292
* Make the authenticated user unfollow the specified user. Requires authentication.
103-
* http://develop.github.com/p/users.html#following_network
93+
* http://developer.github.com/v3/users/followers/
10494
*
10595
* @param string $username the username to unfollow
10696
* @return array list of followed users
10797
*/
10898
public function unFollow($username)
10999
{
110-
$response = $this->post('user/unfollow/'.urlencode($username));
111-
112-
return $response['users'];
100+
return $this->delete('user/following/'.urlencode($username));
113101
}
114102

115103
/**
@@ -121,9 +109,7 @@ public function unFollow($username)
121109
*/
122110
public function getWatchedRepos($username)
123111
{
124-
$response = $this->get('repos/watched/'.urlencode($username));
125-
126-
return $response['repositories'];
112+
return $this->get('users/'.urlencode($username).'/watched');
127113
}
128114

129115
/**
@@ -133,9 +119,7 @@ public function getWatchedRepos($username)
133119
*/
134120
public function getKeys()
135121
{
136-
$response = $this->get('user/keys');
137-
138-
return $response['public_keys'];
122+
return $this->get('user/keys');
139123
}
140124

141125
/**
@@ -145,9 +129,7 @@ public function getKeys()
145129
*/
146130
public function addKey($title, $key)
147131
{
148-
$response = $this->post('user/key/add', array('title' => $title, 'key' => $key));
149-
150-
return $response['public_keys'];
132+
return $this->post('user/keys', array('title' => $title, 'key' => $key));
151133
}
152134

153135
/**
@@ -157,9 +139,7 @@ public function addKey($title, $key)
157139
*/
158140
public function removeKey($id)
159141
{
160-
$response = $this->post('user/key/remove', array('id' => $id));
161-
162-
return $response['public_keys'];
142+
return $this->delete('user/keys/'.urlencode($id));
163143
}
164144

165145
/**
@@ -169,9 +149,7 @@ public function removeKey($id)
169149
*/
170150
public function getEmails()
171151
{
172-
$response = $this->get('user/emails');
173-
174-
return $response['emails'];
152+
return $this->get('user/emails');
175153
}
176154

177155
/**
@@ -181,9 +159,7 @@ public function getEmails()
181159
*/
182160
public function addEmail($email)
183161
{
184-
$response = $this->post('user/email/add', array('email' => $email));
185-
186-
return $response['emails'];
162+
return $this->post('user/emails', array($email));
187163
}
188164

189165
/**
@@ -193,8 +169,6 @@ public function addEmail($email)
193169
*/
194170
public function removeEmail($email)
195171
{
196-
$response = $this->post('user/email/remove', array('email' => $email));
197-
198-
return $response['emails'];
172+
return $this->delete('user/emails', array($email));
199173
}
200174
}

0 commit comments

Comments
 (0)