Skip to content

Commit

Permalink
Merge pull request #143 from AidasK/master
Browse files Browse the repository at this point in the history
lazyload http client for rest api
  • Loading branch information
Tom Walder authored Sep 30, 2016
2 parents b000638 + 536ddf1 commit 059438a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/GDS/Gateway/RESTv1.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function __construct($str_project_id, $str_namespace = null)
{
$this->str_dataset_id = $str_project_id;
$this->str_namespace = $str_namespace;
$this->obj_http_client = $this->initHttpClient();
}

/**
Expand All @@ -58,6 +57,14 @@ public function setHttpClient(ClientInterface $obj_client)
return $this;
}

protected function httpClient()
{
if (!$this->obj_http_client) {
$this->obj_http_client = $this->initHttpClient();
}
return $this->obj_http_client;
}

/**
* Configure HTTP Client
*
Expand Down Expand Up @@ -129,7 +136,7 @@ private function executePostRequest($str_action, $obj_request_body = null)
if(null !== $obj_request_body) {
$arr_options['json'] = $obj_request_body;
}
$obj_response = $this->obj_http_client->post($this->actionUrl($str_action), $arr_options);
$obj_response = $this->httpClient()->post($this->actionUrl($str_action), $arr_options);
$this->obj_last_response = json_decode((string)$obj_response->getBody());
}

Expand Down

0 comments on commit 059438a

Please sign in to comment.