Skip to content

Commit 301c2e4

Browse files
committed
Update code to new http package
1 parent 3ec8943 commit 301c2e4

File tree

18 files changed

+72
-72
lines changed

18 files changed

+72
-72
lines changed

src/AbstractGithubObject.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ protected function fetchUrl($path, $page = 0, $limit = 0)
161161
protected function processResponse(Response $response, $expectedCode = 200)
162162
{
163163
// Validate the response code.
164-
if ($response->code != $expectedCode) {
164+
if ($response->getStatusCode() != $expectedCode) {
165165
// Decode the error response and throw an exception.
166-
$error = json_decode($response->body);
166+
$error = json_decode($response->getBody()->getContents());
167167
$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.';
168168

169-
throw new UnexpectedResponseException($response, $message, $response->code);
169+
throw new UnexpectedResponseException($response, $message, $response->getStatusCode());
170170
}
171171

172-
return json_decode($response->body);
172+
return json_decode($response->getBody()->getContents());
173173
}
174174
}

src/Package/Activity/Starring.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function check($owner, $repo)
110110

111111
$response = $this->client->get($this->fetchUrl($path));
112112

113-
switch ($response->code) {
113+
switch ($response->getStatusCode()) {
114114
case '204':
115115
// This repository is watched by you.
116116
return true;
@@ -120,7 +120,7 @@ public function check($owner, $repo)
120120
return false;
121121
}
122122

123-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
123+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
124124
}
125125

126126
/**

src/Package/Activity/Watching.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function check($owner, $repo)
151151

152152
$response = $this->client->get($this->fetchUrl($path));
153153

154-
switch ($response->code) {
154+
switch ($response->getStatusCode()) {
155155
case '204':
156156
// This repository is watched by you.
157157
return true;
@@ -161,7 +161,7 @@ public function check($owner, $repo)
161161
return false;
162162
}
163163

164-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
164+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
165165
}
166166

167167
/**

src/Package/Authorization.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,19 @@ public function getRateLimit()
242242
$response = $this->client->get($this->fetchUrl($path));
243243

244244
// Validate the response code.
245-
if ($response->code != 200) {
246-
if ($response->code == 404) {
245+
if ($response->getStatusCode() != 200) {
246+
if ($response->getStatusCode() == 404) {
247247
// Unlimited rate for Github Enterprise sites and trusted users.
248248
return (object) ['limit' => false, 'remaining' => null];
249249
}
250250

251251
// Decode the error response and throw an exception.
252-
$error = json_decode($response->body);
252+
$error = json_decode($response->getBody()->getContents());
253253

254-
throw new UnexpectedResponseException($response, $error->message, $response->code);
254+
throw new UnexpectedResponseException($response, $error->message, $response->getStatusCode());
255255
}
256256

257-
return json_decode($response->body);
257+
return json_decode($response->getBody()->getContents());
258258
}
259259

260260
/**

src/Package/Gists.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,19 @@ public function isStarred($gistId)
333333
$response = $this->client->get($this->fetchUrl($path));
334334

335335
// Validate the response code.
336-
if ($response->code == 204) {
336+
if ($response->getStatusCode() == 204) {
337337
return true;
338338
}
339339

340-
if ($response->code == 404) {
340+
if ($response->getStatusCode() == 404) {
341341
return false;
342342
}
343343

344344
// Decode the error response and throw an exception.
345-
$error = json_decode($response->body);
345+
$error = json_decode($response->getBody()->getContents());
346346
$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.';
347347

348-
throw new UnexpectedResponseException($response, $message, $response->code);
348+
throw new UnexpectedResponseException($response, $message, $response->getStatusCode());
349349
}
350350

351351
/**

src/Package/Gitignore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ public function get($name, $raw = false)
6868
$response = $this->client->get($this->fetchUrl($path), $headers);
6969

7070
// Validate the response code.
71-
if ($response->code != 200) {
71+
if ($response->getStatusCode() != 200) {
7272
// Decode the error response and throw an exception.
73-
$error = json_decode($response->body);
73+
$error = json_decode($response->getBody()->getContents());
7474
$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.';
7575

76-
throw new UnexpectedResponseException($response, $message, $response->code);
76+
throw new UnexpectedResponseException($response, $message, $response->getStatusCode());
7777
}
7878

79-
return ($raw) ? $response->body : json_decode($response->body);
79+
return ($raw) ? $response->getBody()->getContents() : json_decode($response->getBody()->getContents());
8080
}
8181
}

src/Package/Issues/Assignees.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public function check($owner, $repo, $assignee)
6868
try {
6969
$response = $this->client->get($this->fetchUrl($path));
7070

71-
if ($response->code == 204) {
71+
if ($response->getStatusCode() == 204) {
7272
return true;
7373
}
7474

75-
throw new UnexpectedResponseException($response, 'Invalid response: ' . $response->code);
75+
throw new UnexpectedResponseException($response, 'Invalid response: ' . $response->getStatusCode());
7676
} catch (\DomainException $e) {
77-
if (isset($response->code) && $response->code == 404) {
77+
if ($response->getStatusCode() == 404) {
7878
return false;
7979
}
8080

src/Package/Markdown.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public function render($text, $mode = 'gfm', $context = null)
6464
$response = $this->client->post($this->fetchUrl($path), $data);
6565

6666
// Validate the response code.
67-
if ($response->code != 200) {
67+
if ($response->getStatusCode() != 200) {
6868
// Decode the error response and throw an exception.
69-
$error = json_decode($response->body);
69+
$error = json_decode($response->getBody()->getContents());
7070
$message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.';
7171

72-
throw new UnexpectedResponseException($response, $message, $response->code);
72+
throw new UnexpectedResponseException($response, $message, $response->getStatusCode());
7373
}
7474

75-
return $response->body;
75+
return $response->getBody()->getContents();
7676
}
7777
}

src/Package/Orgs/Members.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ public function getList($org)
4444

4545
$response = $this->client->get($this->fetchUrl($path));
4646

47-
switch ($response->code) {
47+
switch ($response->getStatusCode()) {
4848
case 302:
4949
// Requester is not an organization member.
5050
return false;
5151

5252
case 200:
53-
return json_decode($response->body);
53+
return json_decode($response->getBody()->getContents());
5454

5555
default:
56-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
56+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
5757
}
5858
}
5959

@@ -77,7 +77,7 @@ public function check($org, $user)
7777

7878
$response = $this->client->get($this->fetchUrl($path));
7979

80-
switch ($response->code) {
80+
switch ($response->getStatusCode()) {
8181
case 204:
8282
// Requester is an organization member and user is a member.
8383
return true;
@@ -92,7 +92,7 @@ public function check($org, $user)
9292
return false;
9393

9494
default:
95-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
95+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
9696
}
9797
}
9898

@@ -165,7 +165,7 @@ public function checkPublic($org, $user)
165165

166166
$response = $this->client->get($this->fetchUrl($path));
167167

168-
switch ($response->code) {
168+
switch ($response->getStatusCode()) {
169169
case 204:
170170
// Response if user is a public member.
171171
return true;
@@ -175,7 +175,7 @@ public function checkPublic($org, $user)
175175
return false;
176176

177177
default:
178-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
178+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
179179
}
180180
}
181181

src/Package/Orgs/Teams.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function isMember($id, $user)
209209

210210
$response = $this->client->get($this->fetchUrl($path));
211211

212-
switch ($response->code) {
212+
switch ($response->getStatusCode()) {
213213
case 204:
214214
// Response if user is a member
215215
return true;
@@ -219,7 +219,7 @@ public function isMember($id, $user)
219219
return false;
220220

221221
default:
222-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
222+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
223223
}
224224
}
225225

@@ -294,10 +294,10 @@ public function getTeamMembership($id, $user)
294294

295295
$response = $this->client->get($this->fetchUrl($path));
296296

297-
switch ($response->code) {
297+
switch ($response->getStatusCode()) {
298298
case 200:
299299
// Response if user is an active member or pending membership
300-
$body = json_decode($response->body);
300+
$body = json_decode($response->getBody()->getContents());
301301

302302
return $body->state;
303303

@@ -306,7 +306,7 @@ public function getTeamMembership($id, $user)
306306
return false;
307307

308308
default:
309-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
309+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
310310
}
311311
}
312312

@@ -403,7 +403,7 @@ public function checkRepo($id, $owner, $repo)
403403

404404
$response = $this->client->get($this->fetchUrl($path));
405405

406-
switch ($response->code) {
406+
switch ($response->getStatusCode()) {
407407
case 204:
408408
// Response if repo is managed by this team.
409409
return true;
@@ -413,7 +413,7 @@ public function checkRepo($id, $owner, $repo)
413413
return false;
414414

415415
default:
416-
throw new \UnexpectedValueException('Unexpected response code: ' . $response->code);
416+
throw new \UnexpectedValueException('Unexpected response code: ' . $response->getStatusCode());
417417
}
418418
}
419419

0 commit comments

Comments
 (0)