Skip to content

Commit

Permalink
Changed post to json
Browse files Browse the repository at this point in the history
  • Loading branch information
cjonstrup committed Jul 20, 2016
1 parent 6d00aee commit aecb60e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
15 changes: 14 additions & 1 deletion Economic/API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Client
* Instantiate object
*
* @access public
* @param string $secret_token
* @param string $grant_token
* @throws Exception
*/
public function __construct($secret_token = '', $grant_token = '')
{
Expand All @@ -36,11 +39,19 @@ public function __construct($secret_token = '', $grant_token = '')
throw new Exception('Lib cURL must be enabled on the server');
}

if (empty($secret_token)) {
throw new Exception('secret token is missing');
}

if (empty($grant_token)) {
throw new Exception('grant token is missing');
}

// Set auth string property
$this->secret_token = $secret_token;
$this->grant_token = $grant_token;

// Instantiate cURL object
// Instantiate cURL object with
$this->authenticate();
}

Expand Down Expand Up @@ -71,6 +82,7 @@ protected function authenticate()

$headers = array(
'Accept: application/json',
'Content-Type: application/json; charset=utf-8'
);

if (!empty($this->secret_token)) {
Expand All @@ -81,6 +93,7 @@ protected function authenticate()
$headers[] = 'X-AgreementGrantToken:' . $this->grant_token;
}

//default headers
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
Expand Down
3 changes: 2 additions & 1 deletion Economic/API/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ protected function execute($request_type, $form = array())

// If additional data is delivered, we will send it along with the API request
if (is_array($form) && ! empty($form)) {
curl_setopt($this->client->ch, CURLOPT_POSTFIELDS, http_build_query($form, '', '&'));
$post = json_encode($form);
curl_setopt($this->client->ch, CURLOPT_POSTFIELDS, $post);
}

// Store received headers in temporary memory file, remember sent headers
Expand Down
25 changes: 9 additions & 16 deletions Economic/API/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ class Response
*/
protected $response_data;


/**
* __construct
*
* Instantiates a new response object
*
* @param int $status_code the HTTP status code
* @param string $sent_headers the headers sent
* @param string $received_headers the headers received
* @param string $response_data the http response body
* Response constructor.
* @param $status_code
* @param $sent_headers
* @param $received_headers
* @param $response_data
*/
public function __construct($status_code, $sent_headers, $received_headers, $response_data)
{
Expand All @@ -52,15 +50,10 @@ public function __construct($status_code, $sent_headers, $received_headers, $res
$this->response_data = $response_data;
}


/**
* asRaw
*
* Returns the HTTP status code, headers and response body.
* Usage: list($status_code, $headers, $response_body) = $response->as_raw().
*
* @param boolan $keep_authorization_value Normally the value of the
* Authorization: header is masked. True keeps the sent value.
* @return array [integer, string[], string]
* @param bool $keep_authorization_value
* @return array
*/
public function asRaw($keep_authorization_value = false)
{
Expand Down

0 comments on commit aecb60e

Please sign in to comment.