Source for file gists.php
Documentation is available at gists.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* GitHub API Gists class for the Joomla Platform.
* @package Joomla.Platform
* Method to create a gist.
* @param mixed $files Either an array of file paths or a single file path as a string.
* @param boolean $public True if the gist should be public.
* @param string $description The optional description of the gist.
public function create($files, $public =
false, $description =
null)
// Build the request path.
// Build the request data.
'public' => (bool)
$public,
'description' =>
$description
// Validate the response code.
if ($response->code !=
201)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to create a comment on a gist.
* @param integer $gistId The gist number.
* @param string $body The comment body text.
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/comments';
// Build the request data.
// Validate the response code.
if ($response->code !=
201)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to delete a gist.
* @param integer $gistId The gist number.
public function delete($gistId)
// Build the request path.
$path =
'/gists/' . (int)
$gistId;
// Validate the response code.
if ($response->code !=
204)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to delete a comment on a gist.
* @param integer $commentId The id of the comment to delete.
// Build the request path.
$path =
'/gists/comments/' . (int)
$commentId;
// Validate the response code.
if ($response->code !=
204)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to update a gist.
* @param integer $gistId The gist number.
* @param mixed $files Either an array of file paths or a single file path as a string.
* @param boolean $public True if the gist should be public.
* @param string $description The description of the gist.
public function edit($gistId, $files =
null, $public =
null, $description =
null)
// Build the request path.
$path =
'/gists/' . (int)
$gistId;
// Craete the data object.
// If a description is set add it to the data object.
$data->description =
$description;
// If the public flag is set add it to the data object.
// If a state is set add it to the data object.
// Encode the request data.
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to update a comment on a gist.
* @param integer $commentId The id of the comment to update.
* @param string $body The new body text for the comment.
// Build the request path.
$path =
'/gists/comments/' . (int)
$commentId;
// Build the request data.
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* @param integer $gistId The gist number.
public function fork($gistId)
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/fork';
// Validate the response code.
if ($response->code !=
201)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get a single gist.
* @param integer $gistId The gist number.
public function get($gistId)
// Build the request path.
$path =
'/gists/' . (int)
$gistId;
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get a specific comment on a gist.
* @param integer $commentId The comment id to get.
// Build the request path.
$path =
'/gists/comments/' . (int)
$commentId;
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get the list of comments on a gist.
* @param integer $gistId The gist number.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
public function getComments($gistId, $page =
0, $limit =
0)
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/comments';
$response =
$this->client->get($this->fetchUrl($path, $page, $limit));
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to list gists. If a user is authenticated it will return the user's gists, otherwise
* it will return all public gists.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
public function getList($page =
0, $limit =
0)
// Build the request path.
$response =
$this->client->get($this->fetchUrl($path, $page, $limit));
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get a list of gists belonging to a given user.
* @param string $user The name of the GitHub user from which to list gists.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
// Build the request path.
$path =
'/users/' .
$user .
'/gists';
$response =
$this->client->get($this->fetchUrl($path, $page, $limit));
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get a list of all public gists.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
// Build the request path.
$response =
$this->client->get($this->fetchUrl($path, $page, $limit));
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to get a list of the authenticated users' starred gists.
* @param integer $page The page number from which to get items.
* @param integer $limit The number of items on a page.
// Build the request path.
$path =
'/gists/starred';
$response =
$this->client->get($this->fetchUrl($path, $page, $limit));
// Validate the response code.
if ($response->code !=
200)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to check if a gist has been starred.
* @param integer $gistId The gist number.
* @return boolean True if the gist is starred.
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/star';
// Validate the response code.
if ($response->code ==
204)
elseif ($response->code ==
404)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* @param integer $gistId The gist number.
public function star($gistId)
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/star';
// Validate the response code.
if ($response->code !=
204)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* @param integer $gistId The gist number.
public function unstar($gistId)
// Build the request path.
$path =
'/gists/' . (int)
$gistId .
'/star';
// Validate the response code.
if ($response->code !=
204)
// Decode the error response and throw an exception.
throw
new DomainException($error->message, $response->code);
* Method to fetch a data array for transmitting to the GitHub API for a list of files based on
* an input array of file paths or filename and content pairs.
* @param array $files The list of file paths or filenames and content.
foreach ($files as $key =>
$file)
// If the key isn't numeric, then we are dealing with a file whose content has been supplied
$data[$key] =
array('content' =>
$file);
// Otherwise, we have been given a path and we have to load the content
// Verify that the each file exists.
throw
new InvalidArgumentException('The file ' .
$file .
' does not exist.');
Documentation generated on Tue, 19 Nov 2013 15:03:59 +0100 by phpDocumentor 1.4.3