Permalink
Browse files

Fixes #12

  • Loading branch information...
1 parent 1de16e8 commit 74be10d61662368c0b85b3672a1f1a7b089a2b9f Chris Kacerguis committed Nov 16, 2013
Showing with 30 additions and 18 deletions.
  1. +9 −17 README.md
  2. +21 −1 libraries/Rest.php
View
26 README.md
@@ -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');
View
22 libraries/Rest.php
@@ -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())
@@ -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'];
+
}
/**
@@ -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 != '')
{
@@ -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);

0 comments on commit 74be10d

Please sign in to comment.