Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/Github/Api/Gist/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@
namespace Github\Api\Gist;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;

/**
* @link https://developer.github.com/v3/gists/comments/
* @author Kayla Daniels <[email protected]>
*/
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.
*
Expand Down
21 changes: 21 additions & 0 deletions lib/Github/Api/Gists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down
21 changes: 21 additions & 0 deletions lib/Github/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
30 changes: 30 additions & 0 deletions lib/Github/Api/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
27 changes: 27 additions & 0 deletions lib/Github/Api/PullRequest/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Api\PullRequest;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\MissingArgumentException;

/**
Expand All @@ -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) {
Expand Down
22 changes: 6 additions & 16 deletions lib/Github/Api/Repository/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 22 additions & 0 deletions lib/Github/Api/Repository/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down