Remove library files, now in core
This commit is contained in:
parent
edfce5445f
commit
55943f8e31
|
@ -1,193 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* A cURL client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since ?
|
||||
*/
|
||||
class JCurl extends JURI
|
||||
{
|
||||
/**
|
||||
* @var array curlOptions.
|
||||
*/
|
||||
protected $curlOptions = array();
|
||||
|
||||
/**
|
||||
* @var string Target path where to save the response
|
||||
*/
|
||||
protected $target = '';
|
||||
|
||||
/**
|
||||
* Get a cURL adapter.
|
||||
*
|
||||
* @param string $uri The URI to work with.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return JCurl
|
||||
*/
|
||||
public static function getAdapter($uri = null)
|
||||
{
|
||||
if ( ! function_exists('curl_init'))
|
||||
{
|
||||
throw new Exception('cURL is not available');
|
||||
}
|
||||
|
||||
return new JCurl($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* You should pass a URI string to the constructor to initialise a specific URI.
|
||||
*
|
||||
* @param string $uri The URI string
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct($uri = null)
|
||||
{
|
||||
if ( ! function_exists('curl_init'))
|
||||
{
|
||||
throw new Exception('cURL is not available');
|
||||
}
|
||||
|
||||
parent::__construct($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cURL options.
|
||||
*
|
||||
* @param array $options The cURL options.
|
||||
*
|
||||
* @return JCurl
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->curlOptions = (array)$options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read URL contents.
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
* @return object The cURL response.
|
||||
*/
|
||||
public function fetch()
|
||||
{
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt_array($ch, $this->curlOptions);
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $this->_uri);
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_SSL_VERIFYHOST, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
|
||||
}
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_SSL_VERIFYPEER, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
}
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_FOLLOWLOCATION, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
}
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_MAXREDIRS, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
|
||||
}
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_TIMEOUT, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
}
|
||||
|
||||
if ( ! array_key_exists(CURLOPT_RETURNTRANSFER, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
if ($this->target)
|
||||
{
|
||||
// Write the response to a file
|
||||
$fp = fopen($this->target, 'w');
|
||||
|
||||
if ( ! $fp)
|
||||
{
|
||||
throw new Exception('Can not open target file at: '.$this->target);
|
||||
}
|
||||
|
||||
// Use CURLOPT_FILE to speed things up
|
||||
curl_setopt($ch, CURLOPT_FILE, $fp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return the response
|
||||
if ( ! array_key_exists(CURLOPT_RETURNTRANSFER, $this->curlOptions))
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
}
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (curl_errno($ch))
|
||||
{
|
||||
throw new Exception('Curl Error: '.curl_error($ch));
|
||||
}
|
||||
|
||||
$info = curl_getinfo($ch);
|
||||
|
||||
if (isset($info['http_code']) && $info['http_code'] != 200)
|
||||
{
|
||||
$response = false;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$return = JArrayHelper::toObject($info);
|
||||
$return->body = $response;
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the response to a file.
|
||||
*
|
||||
* @param string $target Target path
|
||||
*
|
||||
* @return boolean true on success
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function saveToFile($target)
|
||||
{
|
||||
$this->target = $target;
|
||||
|
||||
$response = $this->fetch();
|
||||
|
||||
if (false === $response)
|
||||
{
|
||||
throw new Exception('File cannot be downloaded');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
jimport('joomla.environment.uri');
|
||||
jimport('joomla.client.http');
|
||||
jimport('joomla.client.curl');
|
||||
JLoader::register('JHttpResponse', JPATH_PLATFORM.'/joomla/client/http.php');
|
||||
jimport('joomla.client.github.githubpulls');
|
||||
jimport('joomla.client.github.githubgists');
|
||||
jimport('joomla.client.github.githubissues');
|
||||
jimport('joomla.client.githubobject');
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithub
|
||||
{
|
||||
const AUTHENTICATION_NONE = 0;
|
||||
const AUTHENTICATION_BASIC = 1;
|
||||
const AUTHENTICATION_OAUTH = 2;
|
||||
|
||||
/**
|
||||
* Authentication Method
|
||||
*
|
||||
* Possible values are 0 - no authentication, 1 - basic authentication, 2 - OAuth
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
protected $authentication_method = 0;
|
||||
|
||||
protected $gists = null;
|
||||
|
||||
protected $issues = null;
|
||||
|
||||
protected $pulls = null;
|
||||
|
||||
protected $credentials = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (isset($options['username']) && isset($options['password'])) {
|
||||
$this->credentials['username'] = $options['username'];
|
||||
$this->credentials['password'] = $options['password'];
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_BASIC;
|
||||
} elseif (isset($options['token'])) {
|
||||
$this->credentials['token'] = $options['token'];
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_OAUTH;
|
||||
} else {
|
||||
$this->authentication_method = JGithub::AUTHENTICATION_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name == 'gists') {
|
||||
if ($this->gists == null) {
|
||||
$this->gists = new JGithubGists($this);
|
||||
}
|
||||
return $this->gists;
|
||||
}
|
||||
|
||||
if ($name == 'issues') {
|
||||
if ($this->issues == null) {
|
||||
$this->issues = new JGithubIssues($this);
|
||||
}
|
||||
return $this->issues;
|
||||
}
|
||||
|
||||
if ($name == 'pulls') {
|
||||
if ($this->pulls == null) {
|
||||
$this->pulls = new JGithubPulls($this);
|
||||
}
|
||||
return $this->pulls;
|
||||
}
|
||||
}
|
||||
|
||||
public function sendRequest($url, $method = 'get', $data = array(), $options = array())
|
||||
{
|
||||
$curl_options = array(
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_FOLLOWLOCATION => false,
|
||||
CURLOPT_USERAGENT => 'JGithub',
|
||||
CURLOPT_CONNECTTIMEOUT => 120,
|
||||
CURLINFO_HEADER_OUT => true,
|
||||
CURLOPT_HTTPHEADER => array('Content-type: application/json'),
|
||||
CURLOPT_CAINFO => dirname(__FILE__) . '/github/cacert.pem',
|
||||
CURLOPT_SSL_VERIFYPEER => true,
|
||||
CURLOPT_SSL_VERIFYHOST => 2,
|
||||
);
|
||||
|
||||
switch ($this->authentication_method)
|
||||
{
|
||||
case JGithub::AUTHENTICATION_BASIC:
|
||||
$curl_options[CURLOPT_USERPWD] = $this->credentials['username'].':'.$this->credentials['password'];
|
||||
break;
|
||||
|
||||
case JGithub::AUTHENTICATION_OAUTH:
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?access_token='.$this->credentials['token'];
|
||||
} else {
|
||||
$url .= '&access_token='.$this->credentials['token'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($method) {
|
||||
case 'post':
|
||||
$curl_options[CURLOPT_POST] = 1;
|
||||
$curl_options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||
break;
|
||||
|
||||
case 'put':
|
||||
$curl_options[CURLOPT_POST] = 1;
|
||||
$curl_options[CURLOPT_POSTFIELDS] = '';
|
||||
$curl_options[CURLOPT_CUSTOMREQUEST] = 'PUT';
|
||||
$curl_options[CURLOPT_HTTPGET] = false;
|
||||
break;
|
||||
|
||||
case 'patch':
|
||||
$curl_options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||
|
||||
case 'delete':
|
||||
$curl_options[CURLOPT_CUSTOMREQUEST] = strtoupper($method);
|
||||
$curl_options[CURLOPT_POST] = false;
|
||||
$curl_options[CURLOPT_HTTPGET] = false;
|
||||
break;
|
||||
|
||||
case 'get':
|
||||
$curl_options[CURLOPT_POSTFIELDS] = null;
|
||||
$curl_options[CURLOPT_POST] = false;
|
||||
$curl_options[CURLOPT_HTTPGET] = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$curlResponse = JCurl::getAdapter('https://api.github.com'.$url)
|
||||
->setOptions($curl_options)->fetch();
|
||||
|
||||
$response = new JHttpResponse;
|
||||
|
||||
$response->code = $curlResponse->http_code;
|
||||
$response->headers = $curlResponse->request_header;
|
||||
$response->body = json_decode($curlResponse->body);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,182 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubGists
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getAll($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getByUser($user, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/users/'.$user.'/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getPublic($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/public';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getStarred($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/starred';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id)->body;
|
||||
}
|
||||
|
||||
public function create($files, $public = false, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->public = $public;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists', 'post', $gist)->body;
|
||||
}
|
||||
|
||||
public function edit($gist_id, $files, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'patch', $gist)->body;
|
||||
}
|
||||
|
||||
public function star($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'put')->body;
|
||||
}
|
||||
|
||||
public function unstar($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'delete')->body;
|
||||
}
|
||||
|
||||
public function isStarred($gist_id)
|
||||
{
|
||||
$response = $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star');
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function fork($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/fork', 'put')->body;
|
||||
}
|
||||
|
||||
public function delete($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'delete')->body;
|
||||
}
|
||||
|
||||
public function getComments($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments')->body;
|
||||
}
|
||||
|
||||
public function getComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($gist_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments', 'post', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function editComment($comment_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'patch', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubIssues
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public function getAll($parameters = array(), $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/issues';
|
||||
|
||||
$queryString = '';
|
||||
|
||||
foreach ($parameters AS $parameter) {
|
||||
$queryString .= '';
|
||||
}
|
||||
if (isset($options['filter'])) {
|
||||
}
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getByUser($user, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/users/'.$user.'/gists';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getPublic($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/public';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getStarred($page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/gists/starred';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id)->body;
|
||||
}
|
||||
|
||||
public function create($files, $public = false, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->public = $public;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists', 'post', $gist)->body;
|
||||
}
|
||||
|
||||
public function edit($gist_id, $files, $description = null)
|
||||
{
|
||||
$gist = new stdClass;
|
||||
$gist->files = $files;
|
||||
|
||||
if (!empty($description)) {
|
||||
$gist->description = $description;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'patch', $gist)->body;
|
||||
}
|
||||
|
||||
public function star($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'put')->body;
|
||||
}
|
||||
|
||||
public function unstar($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star', 'delete')->body;
|
||||
}
|
||||
|
||||
public function isStarred($gist_id)
|
||||
{
|
||||
$response = $this->connector->sendRequest('/gists/'.(int)$gist_id.'/star');
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function fork($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/fork', 'put')->body;
|
||||
}
|
||||
|
||||
public function delete($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id, 'delete')->body;
|
||||
}
|
||||
|
||||
public function getComments($gist_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments')->body;
|
||||
}
|
||||
|
||||
public function getComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($gist_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/'.(int)$gist_id.'/comments', 'post', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function editComment($comment_id, $comment)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'patch', array('body' => $comment))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/gists/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
jimport('joomla.client.githubobject');
|
||||
|
||||
/**
|
||||
* Github Pull Request Class
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubPulls extends JGithubObject
|
||||
{
|
||||
public function getAll($user, $repo, $state = 'open', $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls'.($state == 'closed' ? '?state=closed' : '');
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function get($user, $repo, $pull_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id)->body;
|
||||
}
|
||||
|
||||
public function create($user, $repo, $title, $base, $head, $body = '')
|
||||
{
|
||||
$pull = new stdClass;
|
||||
$pull->title = $title;
|
||||
$pull->base = $base;
|
||||
$pull->head = $head;
|
||||
$pull->body = $body;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls', 'post', $pull)->body;
|
||||
}
|
||||
|
||||
public function createFromIssue($user, $repo, $issue, $base, $head)
|
||||
{
|
||||
$pull = new stdClass;
|
||||
$pull->issue = (int)$issue;
|
||||
$pull->base = $base;
|
||||
$pull->head = $head;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls', 'post', $pull)->body;
|
||||
}
|
||||
|
||||
public function edit($user, $repo, $id, $title = null, $body = null, $state = null)
|
||||
{
|
||||
$pull = new stdClass;
|
||||
|
||||
if (isset($title)) {
|
||||
$pull->title = $title;
|
||||
}
|
||||
|
||||
if (isset($body)) {
|
||||
$pull->body = $body;
|
||||
}
|
||||
|
||||
if (isset($state)) {
|
||||
$pull->state = $state;
|
||||
}
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$id, 'patch', $pull)->body;
|
||||
}
|
||||
|
||||
public function getCommits($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/commits';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getFiles($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/files';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function isMerged($user, $repo, $pull_id)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/merge';
|
||||
$response = $this->connector->sendRequest($url);
|
||||
|
||||
if ($response->code == '204') {
|
||||
return true;
|
||||
} else { // the code should be 404
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function merge($user, $repo, $pull_id, $commit_message = '')
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/merge', 'put', array('commit_message' => $commit_message))->body;
|
||||
}
|
||||
|
||||
public function getComments($user, $repo, $pull_id, $page = 0, $per_page = 0)
|
||||
{
|
||||
$url = '/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments';
|
||||
return $this->connector->sendRequest($this->paginate($url, $page, $per_page))->body;
|
||||
}
|
||||
|
||||
public function getComment($user, $repo, $comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id)->body;
|
||||
}
|
||||
|
||||
public function createComment($user, $repo, $pull_id, $body, $commit_id, $path, $position)
|
||||
{
|
||||
$comment = new stdClass;
|
||||
$comment->body = $body;
|
||||
$comment->commit_id = $commit_id;
|
||||
$comment->path = $path;
|
||||
$comment->position = $position;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments', 'post', $comment)->body;
|
||||
}
|
||||
|
||||
public function createCommentReply($user, $repo, $pull_id, $body, $in_reply_to)
|
||||
{
|
||||
$comment = new stdClass;
|
||||
$comment->body = $body;
|
||||
$comment->in_reply_to = (int)$in_reply_to;
|
||||
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/'.(int)$pull_id.'/comments', 'post', $comment)->body;
|
||||
}
|
||||
|
||||
public function editComment($user, $repo, $comment_id, $body)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id, 'patch', array('body' => $body))->body;
|
||||
}
|
||||
|
||||
public function deleteComment($user, $repo, $comment_id)
|
||||
{
|
||||
return $this->connector->sendRequest('/repos/'.$user.'/'.$repo.'/pulls/comments/'.(int)$comment_id, 'delete')->body;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* HTTP client class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Client
|
||||
* @since 11.1
|
||||
*/
|
||||
class JGithubObject
|
||||
{
|
||||
/**
|
||||
* Github Connector
|
||||
*
|
||||
* @var JGithub
|
||||
* @since 11.3
|
||||
*/
|
||||
protected $connector = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $options Array of configuration options for the client.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($connector, $options = array())
|
||||
{
|
||||
$this->connector = $connector;
|
||||
}
|
||||
|
||||
protected function paginate($url, $page = 0, $per_page = 0)
|
||||
{
|
||||
//TODO: Make a new base class and move paginate into it
|
||||
$query_string = array();
|
||||
|
||||
if ($page > 0) {
|
||||
$query_string[] = 'page='.(int)$page;
|
||||
}
|
||||
|
||||
if ($per_page > 0) {
|
||||
$query_string[] = 'per_page='.(int)$per_page;
|
||||
}
|
||||
|
||||
if (isset($query_string[0])) {
|
||||
$query = implode('&', $query_string);
|
||||
} else {
|
||||
$query = '';
|
||||
}
|
||||
|
||||
if (strlen($query) > 0) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?'.$query;
|
||||
} else {
|
||||
$url .= '&'.$query;
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue