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

Added ability to pass in the API Key, and API header name via the #36

Merged
merged 1 commit into from Nov 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions libraries/Rest.php
Expand Up @@ -42,6 +42,9 @@ class REST
protected $http_auth = null;
protected $http_user = null;
protected $http_pass = null;

protected $api_name = 'X-API-KEY';
protected $api_key = null;

protected $response_string;

Expand Down Expand Up @@ -76,7 +79,10 @@ public function initialize($config)
{
$this->rest_server .= '/';
}


isset($config['api_name']) && $this->api_name = $config['api_name'];
isset($config['api_key']) && $this->api_key = $config['api_key'];

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'];
Expand Down Expand Up @@ -111,9 +117,15 @@ public function delete($uri, $params = array(), $format = NULL)
return $this->_call('delete', $uri, $params, $format);
}

public function api_key($key, $name = 'X-API-KEY')
public function api_key($key, $name = FALSE)
{
$this->_ci->curl->http_header($name, $key);
$this->api_key = $key;

if ($name !== FALSE)
{
$this->api_name = $name;
}

}

public function language($lang)
Expand Down Expand Up @@ -143,6 +155,13 @@ protected function _call($method, $uri, $params = array(), $format = NULL)
{
$this->_ci->curl->http_login($this->http_user, $this->http_pass, $this->http_auth);
}

// If we have an API Key, then use it
if ($this->api_key != '')
{
$this->_ci->curl->http_header($this->api_name, $this->api_key);
}


// We still want the response even if there is an error code over 400
$this->_ci->curl->option('failonerror', FALSE);
Expand Down