Skip to content

Commit

Permalink
Merge branch 'hotfix/0.10.1'
Browse files Browse the repository at this point in the history
* hotfix/0.10.1:
  Add boolean value transformations before send request
  • Loading branch information
inakiabt committed Jun 12, 2017
2 parents a95471e + 6c65bff commit 67d7573
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inakiabt/etsy-php",
"version": "0.10.0",
"version": "0.10.1",
"description": "Simple PHP wrapper for Etsy API",
"license": "MIT",
"authors": [
Expand Down
18 changes: 17 additions & 1 deletion src/Etsy/EtsyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ private function request($arguments)
$method = $this->methods[$arguments['method']];
$args = $arguments['args'];
$params = $this->prepareParameters($args['params']);
$data = @$this->prepareData($args['data']);

$uri = preg_replace_callback('@:(.+?)(\/|$)@', function($matches) use ($args) {
return $args["params"][$matches[1]].$matches[2];
Expand All @@ -56,7 +57,7 @@ private function request($arguments)
$uri .= "?" . http_build_query($params);
}

return $this->validateResponse( $args, $this->client->request($uri, @$args['data'], $method['http_method'], $this->returnJson) );
return $this->validateResponse( $args, $this->client->request($uri, $data, $method['http_method'], $this->returnJson) );
}

protected function validateResponse($request_args, $response)
Expand Down Expand Up @@ -92,6 +93,21 @@ protected function validateResponse($request_args, $response)
return $response;
}

private function prepareData($data) {
$result = array();
foreach ($data as $key => $value) {
$type = gettype($value);
if ($type !== 'boolean') {
$result[$key] = $value;
continue;
}

$result[$key] = $value ? 1 : 0;
}

return $result;
}

private function prepareParameters($params) {
$query_pairs = array();
$allowed = array("limit", "offset", "page", "sort_on", "sort_order", "include_private", "language");
Expand Down

0 comments on commit 67d7573

Please sign in to comment.