Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions src/FreshMail/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RestApi
const HOST = 'https://api.freshmail.com/';
const PREFIX = 'rest/';

CONST DEFAULT_FILE_PATH = '/tmp/';
const DEFAULT_FILE_PATH = '/tmp/';

/**
* @var string
Expand All @@ -27,7 +27,14 @@ class RestApi
*/
private $strApiKey;

/**
* @var array
*/
private $response = null;

/**
* @var string
*/
private $rawResponse = null;

/**
Expand All @@ -48,7 +55,7 @@ class RestApi
/**
* Get errors.
*
* @return array
* @return array|null
*/
public function getErrors()
{
Expand All @@ -59,30 +66,30 @@ public function getErrors()
return null;
}

/**
* Get response.
*
/**
* Get response.
*
* @return array
*/
public function getResponse()
{
return $this->response;
}

/**
* Get raw response.
*
* @return array
/**
* Get raw response.
*
* @return string
*/
public function getRawResponse()
{
return $this->rawResponse;
}

/**
* Get HTTP code.
*
* @return array
/**
* Get HTTP code.
*
* @return int
*/
public function getHttpCode()
{
Expand Down Expand Up @@ -131,6 +138,18 @@ public function setContentType($contentType)
return $this;
}

/**
* Fire request
*
* @param string $strUrl - URL path
* @param array $arrParams - Data
* @param bool $returnRawResponse - Return raw response
*
* @return array|string - Response
*
* @throws \FreshMail\RestException
* @throws \Exception
*/
public function doRequest($strUrl, $arrParams = array(), $returnRawResponse = false)
{
if (empty($arrParams)) {
Expand Down Expand Up @@ -188,6 +207,13 @@ public function doRequest($strUrl, $arrParams = array(), $returnRawResponse = fa
return $this->response;
}

/**
* Parse Curl response
*
* @param resource $cUrl
*
* @return void
*/
private function getResponseFromHeaders($cUrl)
{
$headerSize = curl_getinfo($cUrl, CURLINFO_HEADER_SIZE);
Expand Down