Skip to content
This repository has been archived by the owner on May 11, 2018. It is now read-only.

Commit

Permalink
Fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kacerguis committed Nov 16, 2013
1 parent 1de16e8 commit 74be10d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@ Please take a look at the code to see about things like api_key() and other post
// Load the library
$this->load->library('rest');

// Run some setup
$this->rest->initialize(array('server' => 'http://twitter.com/'));

// Pull in an array of tweets
$tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');

## Usage (with API Key)

// Load the rest client spark
$this->load->spark('restclient/2.1.0');

// Load the library
$this->load->library('rest');
// Set config options
$config = array('server' => 'https://example.com/',
//'api_key' => 'Setec_Astronomy'
//'api_name' => 'X-API-KEY'
'http_user' => 'username',
'http_pass' => 'password',
'http_auth' => 'basic',
'ssl_verify_peer' => TRUE,
'ssl_cainfo' => '/certs/cert.pem'));

// Run some setup
$this->rest->initialize(array('server' => 'http://twitter.com/'));

// Set your API Key
// By default, it assumes that the header is: X-API-KEY (which matches the REST Server)
$this->rest->api_key('YOUR_API_KEY');

// Pull in an array of tweets
$tweets = $this->rest->get('statuses/user_timeline/'.$username.'.xml');

Expand Down
22 changes: 21 additions & 1 deletion libraries/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class REST
protected $api_name = 'X-API-KEY';
protected $api_key = null;

protected $ssl_verify_peer = null;
protected $ssl_cainfo = null;

protected $response_string;

function __construct($config = array())
Expand Down Expand Up @@ -95,6 +98,10 @@ public function initialize($config)
isset($config['http_auth']) && $this->http_auth = $config['http_auth'];
isset($config['http_user']) && $this->http_user = $config['http_user'];
isset($config['http_pass']) && $this->http_pass = $config['http_pass'];

isset($config['ssl_verify_peer']) && $this->ssl_verify_peer = $config['ssl_verify_peer'];
isset($config['ssl_cainfo']) && $this->ssl_cainfo = $config['ssl_cainfo'];

}

/**
Expand Down Expand Up @@ -228,6 +235,19 @@ protected function _call($method, $uri, $params = array(), $format = NULL)
// Initialize cURL session
$this->_ci->curl->create($this->rest_server.$uri);


// If using ssl set the ssl verification value and cainfo
// contributed by: https://github.com/paulyasi
if ($this->ssl_verify_peer === FALSE)
{
$this->_ci->curl->ssl(FALSE);
}
elseif ($this->ssl_verify_peer === TRUE)
{
$this->ssl_cainfo = getcwd() . $this->ssl_cainfo;
$this->_ci->curl->ssl(TRUE, 2, $this->ssl_cainfo);
}

// If authentication is enabled use it
if ($this->http_auth != '' && $this->http_user != '')
{
Expand All @@ -240,7 +260,7 @@ protected function _call($method, $uri, $params = array(), $format = NULL)
$this->_ci->curl->http_header($this->api_name, $this->api_key);
}

// Set the Content-Type (contributed by eriklharper)
// Set the Content-Type (contributed by https://github.com/eriklharper)
$this->http_header('Content-type', $this->mime_type);


Expand Down

0 comments on commit 74be10d

Please sign in to comment.