Skip to content

Commit

Permalink
iml: fix getPostCode & makeRequest methods (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
azgalot authored and gwinn committed Nov 3, 2017
1 parent 7f264cc commit 0215622
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
10 changes: 3 additions & 7 deletions src/SaaS/Service/Iml/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,15 @@ public function getPostRateZone()
*
* @return Responce
*/
public function getPostCode($index)
public function getPostCode($index = null)
{
$parameters = array();

if(empty($index) || !isset($index)){
throw new \InvalidArgumentException(
"index must be established and must be not empty"
);
}else{
if(!is_null($index)){
$parameters = array('index' => $index);
}

return $this->client->makeRequest('PostCode', 'GET',$parameters);
return $this->client->makeRequest('PostCode', 'GET', $parameters);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/SaaS/Service/Iml/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function makeRequest($path, $method, array $parameters = array()){
'GetPrice'
);

$apiLongTimeMethods = array(
'PostCode'
);

if (!in_array($method, $allowedMethods)) {
throw new \InvalidArgumentException(
sprintf(
Expand All @@ -77,11 +81,17 @@ public function makeRequest($path, $method, array $parameters = array()){
);
}

$timeouts = 60;

if (in_array($path, $apiLongTimeMethods) && empty($parameters)) {
$timeouts = 600;
}

if (self::METHOD_GET === $method && in_array($path, $apiListMethods)){
$url = 'https://api.iml.ru/list/';
} elseif(self::METHOD_GET === $method && !in_array($path, $apiListMethods)){
$url = 'https://list.iml.ru/';
}else {
} else {
$url = 'https://api.iml.ru/json/';
}

Expand All @@ -107,8 +117,8 @@ public function makeRequest($path, $method, array $parameters = array()){
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, $timeouts);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, $timeouts);

$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
Expand Down

0 comments on commit 0215622

Please sign in to comment.