Skip to content

Commit

Permalink
API added default projectid
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijnijben committed Aug 3, 2015
1 parent e5eb5fa commit 0b733a8
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ class Api
*/
private $apiKey;

/**
* The API will use this as the default project id.
*
* @var string
*/
private $projectId;

/**
* Create a new API instance.
*
* @param string $apiKey
* @param string $projectId
*/
public function __construct($apiKey)
public function __construct($apiKey, $projectId = null)
{
$this->setApiKey($apiKey);
$this->setProjectId($projectId);
}

/**
Expand Down Expand Up @@ -136,6 +145,10 @@ private function request($url, $opts = array(), $httpMethod = 'GET')
*/
public function GET($method, $action, $query = array())
{
if (!isset($query['projectid']) && !is_null($this->projectId)) {
$query['projectid'] = $this->getProjectId();
}

$query['apikey'] = $this->getApiKey();
$url = $this->getEndpoint($method, $action, $query);
$opts = array();
Expand All @@ -156,6 +169,10 @@ public function GET($method, $action, $query = array())
*/
public function POST($method, $action, $query = array())
{
if (!isset($query['projectid']) && !is_null($this->projectId)) {
$query['projectid'] = $this->getProjectId();
}

$query['apikey'] = $this->getApiKey();
$url = $this->getEndpoint($method, $action);
$opts = array(
Expand Down Expand Up @@ -191,4 +208,24 @@ public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
}

/**
* Get the default project id.
*
* @return string
*/
public function getProjectId()
{
return $this->projectId;
}

/**
* Set the default project id.
*
* @param string $projectId
*/
public function setProjectId($projectId)
{
$this->projectId = $projectId;
}
}

0 comments on commit 0b733a8

Please sign in to comment.