Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Move abstract classes to root dir
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 12, 2011
1 parent fcd249f commit 01d054b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/Github/Api/Abstract.php → lib/Github/Api.php
Expand Up @@ -6,7 +6,7 @@
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
* @license MIT License
*/
abstract class Github_Api_Abstract implements Github_ApiInterface
abstract class Github_Api implements Github_ApiInterface
{
/**
* The client
Expand Down
51 changes: 13 additions & 38 deletions lib/Github/HttpClient/Abstract.php → lib/Github/HttpClient.php
Expand Up @@ -6,7 +6,7 @@
* @author Thibault Duplessis <thibault.duplessis at gmail dot com>
* @license MIT License
*/
abstract class Github_HttpClient_Abstract implements Github_HttpClientInterface
abstract class Github_HttpClient implements Github_HttpClientInterface
{
/**
* The request options
Expand All @@ -32,70 +32,70 @@ abstract class Github_HttpClient_Abstract implements Github_HttpClientInterface
*/
public function __construct(array $options = array())
{
$this->configure($options);
$this->options = array_merge($this->options, $options);
}

/**
* Send a request to the server, receive a response
*
* @param string $url Request API url
* @param string $path Request API path
* @param array $parameters Parameters
* @param string $httpMethod HTTP method to use
* @param array $options Request options
*
* @return string HTTP response
*/
abstract protected function doSend($url, array $parameters = array(), $httpMethod = 'GET', array $options);
abstract protected function doSend($path, array $parameters = array(), $httpMethod = 'GET', array $options);

/**
* Send a GET request
*
* @param string $url Request URL
* @param string $path Request path
* @param array $parameters GET Parameters
* @param string $httpMethod HTTP method to use
* @param array $options Request options
*
* @return array Data
*/
public function get($apiPath, array $parameters = array(), array $options = array())
public function get($path, array $parameters = array(), array $options = array())
{
return $this->send($apiPath, $parameters, 'GET', $options);
return $this->send($path, $parameters, 'GET', $options);
}

/**
* Send a POST request
*
* @param string $url Request URL
* @param string $path Request path
* @param array $parameters POST Parameters
* @param string $httpMethod HTTP method to use
* @param array $options reconfigure the request for this call only
*
* @return array Data
*/
public function post($apiPath, array $parameters = array(), array $options = array())
public function post($path, array $parameters = array(), array $options = array())
{
return $this->send($apiPath, $parameters, 'POST', $options);
return $this->send($path, $parameters, 'POST', $options);
}

/**
* Send a request to the server, receive a response,
* decode the response and returns an associative array
*
* @param string $url Request API url
* @param string $path Request API path
* @param array $parameters Parameters
* @param string $httpMethod HTTP method to use
* @param array $options Request options
*
* @return array Data
*/
protected function send($url, array $parameters = array(), $httpMethod = 'GET', array $options = array())
protected function send($path, array $parameters = array(), $httpMethod = 'GET', array $options = array())
{
$this->updateHistory();

$requestOptions = array_merge($this->options, $options);

// get encoded response
$response = $this->doSend($apiPath, $parameters, $httpMethod, $options);
$response = $this->doSend($path, $parameters, $httpMethod, $options);

// decode response
$response = $this->decodeResponse($response);
Expand All @@ -119,19 +119,6 @@ protected function decodeResponse($response)
throw new Exception(__CLASS__.' only supports json format, '.$this->options['format'].' given.');
}

/**
* Configure the request
*
* @param array $options Request options
* @return Github_HttpClientInterface $this Fluent interface
*/
public function configure(array $options)
{
$this->options = array_merge($this->options, $options);

return $this;
}

/**
* Change an option value.
*
Expand All @@ -147,18 +134,6 @@ public function setOption($name, $value)
return $this;
}

/**
* Get an option value.
*
* @param string $name The option name
*
* @return mixed The option value
*/
public function getOption($name, $default = null)
{
return isset($this->options[$name]) ? $this->options[$name] : $default;
}

/**
* Records the requests times
* When 30 request have been sent in less than a minute,
Expand Down

0 comments on commit 01d054b

Please sign in to comment.