Skip to content

Commit 8380ce4

Browse files
committed
add more configure methods to address missing custom media types
- also fixes the Issue/Comments default configure value - also adds support for polaris-preview in PullRequest - also adds support for squirrel-girl-preview in PullRequest/Comments - replaces switch case with in_array in Repository/Comments to standardize
1 parent 962beba commit 8380ce4

File tree

8 files changed

+112
-18
lines changed

8 files changed

+112
-18
lines changed

lib/Github/Api/Gist/Comments.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
namespace Github\Api\Gist;
44

55
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
67

78
/**
89
* @link https://developer.github.com/v3/gists/comments/
910
* @author Kayla Daniels <kayladnls@gmail.com>
1011
*/
1112
class Comments extends AbstractApi
1213
{
14+
use AcceptHeaderTrait;
15+
16+
/**
17+
* Configure the body type.
18+
*
19+
* @link https://developer.github.com/v3/gists/comments/#custom-media-types
20+
* @param string|null $bodyType
21+
*/
22+
public function configure($bodyType = null)
23+
{
24+
if (!in_array($bodyType, array('text', 'html', 'full'))) {
25+
$bodyType = 'raw';
26+
}
27+
28+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
29+
}
30+
1331
/**
1432
* Get all comments for a gist.
1533
*

lib/Github/Api/Gists.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
*/
1515
class Gists extends AbstractApi
1616
{
17+
use AcceptHeaderTrait;
18+
19+
/**
20+
* Configure the body type.
21+
*
22+
* @link https://developer.github.com/v3/gists/#custom-media-types
23+
* @param string|null $bodyType
24+
*/
25+
public function configure($bodyType = null)
26+
{
27+
if (!in_array($bodyType, array('base64'))) {
28+
$bodyType = 'raw';
29+
}
30+
31+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType);
32+
}
33+
1734
public function all($type = null)
1835
{
1936
if (!in_array($type, array('public', 'starred'))) {

lib/Github/Api/Issue.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function configure($bodyType = null)
3131
if (!in_array($bodyType, array('text', 'html', 'full'))) {
3232
$bodyType = 'raw';
3333
}
34+
3435
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
3536
}
3637

lib/Github/Api/Issue/Comments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Comments extends AbstractApi
2323
*/
2424
public function configure($bodyType = null)
2525
{
26-
if (!in_array($bodyType, array('raw', 'text', 'html'))) {
27-
$bodyType = 'full';
26+
if (!in_array($bodyType, array('text', 'html', 'full'))) {
27+
$bodyType = 'raw';
2828
}
2929

3030
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);

lib/Github/Api/PullRequest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,31 @@
1414
*/
1515
class PullRequest extends AbstractApi
1616
{
17+
use AcceptHeaderTrait;
18+
19+
/**
20+
* Configure the body type.
21+
*
22+
* @link https://developer.github.com/v3/pulls/#custom-media-types
23+
* @param string|null $bodyType
24+
*/
25+
public function configure($apiVersion = null, $bodyType = null)
26+
{
27+
if (!in_array($apiVersion, array('polaris-preview'))) {
28+
$apiVersion = $this->client->getApiVersion();
29+
}
30+
31+
if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) {
32+
$bodyType = 'raw';
33+
}
34+
35+
if (!in_array($bodyType, array('diff', 'patch'))) {
36+
$bodyType .= '+json';
37+
}
38+
39+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType);
40+
}
41+
1742
/**
1843
* Get a listing of a project's pull requests by the username, repository and (optionally) state.
1944
*

lib/Github/Api/PullRequest/Comments.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\Api\PullRequest;
44

55
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
67
use Github\Exception\MissingArgumentException;
78

89
/**
@@ -11,6 +12,27 @@
1112
*/
1213
class Comments extends AbstractApi
1314
{
15+
use AcceptHeaderTrait;
16+
17+
/**
18+
* Configure the body type.
19+
*
20+
* @link https://developer.github.com/v3/pulls/comments/#custom-media-types
21+
* @param string|null $bodyType
22+
*/
23+
public function configure($apiVersion = null, $bodyType = null)
24+
{
25+
if (!in_array($apiVersion, array('squirrel-girl-preview'))) {
26+
$apiVersion = $this->client->getApiVersion();
27+
}
28+
29+
if (!in_array($bodyType, array('text', 'html', 'full'))) {
30+
$bodyType = 'raw';
31+
}
32+
33+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $apiVersion, $bodyType);
34+
}
35+
1436
public function all($username, $repository, $pullRequest = null)
1537
{
1638
if (null !== $pullRequest) {

lib/Github/Api/Repository/Comments.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,19 @@ class Comments extends AbstractApi
1515
{
1616
use AcceptHeaderTrait;
1717

18+
/**
19+
* Configure the body type.
20+
*
21+
* @link https://developer.github.com/v3/repos/comments/#custom-media-types
22+
* @param string|null $bodyType
23+
*/
1824
public function configure($bodyType = null)
1925
{
20-
switch ($bodyType) {
21-
case 'raw':
22-
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getApiVersion());
23-
break;
24-
25-
case 'text':
26-
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getApiVersion());
27-
break;
28-
29-
case 'html':
30-
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getApiVersion());
31-
break;
32-
33-
default:
34-
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getApiVersion());
26+
if (!in_array($bodyType, array('text', 'html', 'full'))) {
27+
$bodyType = 'raw';
3528
}
3629

37-
$this->acceptHeaderValue = $header;
30+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType);
3831
}
3932

4033
public function all($username, $repository, $sha = null)

lib/Github/Api/Repository/Contents.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Github\Api\Repository;
44

55
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
67
use Github\Exception\InvalidArgumentException;
78
use Github\Exception\ErrorException;
89
use Github\Exception\MissingArgumentException;
@@ -14,6 +15,23 @@
1415
*/
1516
class Contents extends AbstractApi
1617
{
18+
use AcceptHeaderTrait;
19+
20+
/**
21+
* Configure the body type.
22+
*
23+
* @link https://developer.github.com/v3/repo/contents/#custom-media-types
24+
* @param string|null $bodyType
25+
*/
26+
public function configure($bodyType = null)
27+
{
28+
if (!in_array($bodyType, array('html', 'object'))) {
29+
$bodyType = 'raw';
30+
}
31+
32+
$this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType);
33+
}
34+
1735
/**
1836
* Get content of README file in a repository.
1937
*

0 commit comments

Comments
 (0)