Skip to content

Commit

Permalink
Merge pull request #6 from thewulf7/hotfix/flight-fix
Browse files Browse the repository at this point in the history
execute method fix for flight
  • Loading branch information
thewulf7 committed Dec 7, 2015
2 parents e15a0ec + 7d58ee2 commit af4dc70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/travelPayouts/components/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,28 @@ public function __construct($token)
}

/**
* @param $url
* @param array $options
* @param string $type
* @param string $url
* @param array $options
* @param string $type
* @param bool|true $replaceOptions
*
* @return mixed
* @throws \RuntimeException
*/
public function execute($url, array $options, $type = 'GET')
public function execute($url, array $options, $type = 'GET', $replaceOptions = true)
{
$url = '/' . $this->getApiVersion() . '/' . $url;
$params = [
'http_errors' => false
'http_errors' => false,
];

$paramName = $type === 'GET' ? 'query' : 'body';
$params[$paramName] = $options;
if ($replaceOptions)
{
$paramName = $type === 'GET' ? 'query' : 'body';
$params[$paramName] = $options;
} else
{
$params += $options;
}

/** @var \GuzzleHttp\Psr7\Request $res */
$res = $this->getClient()->request($type, $url, $params);
Expand All @@ -77,7 +83,7 @@ public function execute($url, array $options, $type = 'GET')

if ($statusCode !== 200)
{
$strBody = json_decode((string)$body,true);
$strBody = json_decode((string)$body, true);
throw new \RuntimeException("{$statusCode}:{$strBody['message']}");
}

Expand Down
2 changes: 1 addition & 1 deletion src/travelPayouts/services/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function search($locale = 'ru', $trip_class = 'Y')

$options['json']['signature'] = $this->getSignature($options['json']);

return $this->getClient()->setApiVersion('v1')->execute($url, $options, 'POST');
return $this->getClient()->setApiVersion('v1')->execute($url, $options, 'POST', false);
}

/**
Expand Down

0 comments on commit af4dc70

Please sign in to comment.