diff --git a/lib/Github/Api/Gist/Comments.php b/lib/Github/Api/Gist/Comments.php index 521e4d03bb4..e77428c1a53 100644 --- a/lib/Github/Api/Gist/Comments.php +++ b/lib/Github/Api/Gist/Comments.php @@ -3,6 +3,7 @@ namespace Github\Api\Gist; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; /** * @link https://developer.github.com/v3/gists/comments/ @@ -10,6 +11,27 @@ */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/gists/comments/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get all comments for a gist. * diff --git a/lib/Github/Api/Gists.php b/lib/Github/Api/Gists.php index 9710e6de683..c661dfebbc2 100644 --- a/lib/Github/Api/Gists.php +++ b/lib/Github/Api/Gists.php @@ -14,6 +14,27 @@ */ class Gists extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/gists/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('base64'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + public function all($type = null) { if (!in_array($type, array('public', 'starred'))) { diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 4c30783473d..fa79ffa63cc 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -19,6 +19,27 @@ */ class Issue extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/issues/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * List issues by username, repo and state. * diff --git a/lib/Github/Api/PullRequest.php b/lib/Github/Api/PullRequest.php index c732b362b09..a47509197c3 100644 --- a/lib/Github/Api/PullRequest.php +++ b/lib/Github/Api/PullRequest.php @@ -15,6 +15,36 @@ */ class PullRequest extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/pulls/#custom-media-types + * @param string|null $bodyType + * @param string|null $apiVersion + * + * @return self + */ + public function configure($bodyType = null, $apiVersion = null) + { + if (!in_array($apiVersion, array('polaris-preview'))) { + $apiVersion = $this->client->getApiVersion(); + } + + if (!in_array($bodyType, array('text', 'html', 'full', 'diff', 'patch'))) { + $bodyType = 'raw'; + } + + if (!in_array($bodyType, array('diff', 'patch'))) { + $bodyType .= '+json'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get a listing of a project's pull requests by the username, repository and (optionally) state. * diff --git a/lib/Github/Api/PullRequest/Comments.php b/lib/Github/Api/PullRequest/Comments.php index b2de809ed7a..161c629909e 100644 --- a/lib/Github/Api/PullRequest/Comments.php +++ b/lib/Github/Api/PullRequest/Comments.php @@ -3,6 +3,7 @@ namespace Github\Api\PullRequest; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\MissingArgumentException; /** @@ -11,6 +12,32 @@ */ class Comments extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/pulls/comments/#custom-media-types + * @param string|null $bodyType + * @param string|null @apiVersion + * + * @return self + */ + public function configure($bodyType = null, $apiVersion = null) + { + if (!in_array($apiVersion, array('squirrel-girl-preview'))) { + $apiVersion = $this->client->getApiVersion(); + } + + if (!in_array($bodyType, array('text', 'html', 'full'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $apiVersion, $bodyType); + + return $this; + } + public function all($username, $repository, $pullRequest = null) { if (null !== $pullRequest) { diff --git a/lib/Github/Api/Repository/Comments.php b/lib/Github/Api/Repository/Comments.php index 2827ee8ad5f..4e993720296 100644 --- a/lib/Github/Api/Repository/Comments.php +++ b/lib/Github/Api/Repository/Comments.php @@ -16,30 +16,20 @@ class Comments extends AbstractApi use AcceptHeaderTrait; /** + * Configure the body type. + * + * @link https://developer.github.com/v3/repos/comments/#custom-media-types * @param string|null $bodyType * * @return self */ public function configure($bodyType = null) { - switch ($bodyType) { - case 'raw': - $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getApiVersion()); - break; - - case 'text': - $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getApiVersion()); - break; - - case 'html': - $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getApiVersion()); - break; - - default: - $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getApiVersion()); + if (!in_array($bodyType, array('raw', 'text', 'html'))) { + $bodyType = 'full'; } - $this->acceptHeaderValue = $header; + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s+json', $this->client->getApiVersion(), $bodyType); return $this; } diff --git a/lib/Github/Api/Repository/Contents.php b/lib/Github/Api/Repository/Contents.php index 064f68490ff..387413bb053 100644 --- a/lib/Github/Api/Repository/Contents.php +++ b/lib/Github/Api/Repository/Contents.php @@ -3,6 +3,7 @@ namespace Github\Api\Repository; use Github\Api\AbstractApi; +use Github\Api\AcceptHeaderTrait; use Github\Exception\InvalidArgumentException; use Github\Exception\ErrorException; use Github\Exception\MissingArgumentException; @@ -14,6 +15,27 @@ */ class Contents extends AbstractApi { + use AcceptHeaderTrait; + + /** + * Configure the body type. + * + * @link https://developer.github.com/v3/repo/contents/#custom-media-types + * @param string|null $bodyType + * + * @return self + */ + public function configure($bodyType = null) + { + if (!in_array($bodyType, array('html', 'object'))) { + $bodyType = 'raw'; + } + + $this->acceptHeaderValue = sprintf('application/vnd.github.%s.%s', $this->client->getApiVersion(), $bodyType); + + return $this; + } + /** * Get content of README file in a repository. *