From 6c65bffc4439336f26cdfdab88e53894eef48634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Abete?= Date: Mon, 12 Jun 2017 09:56:20 -0300 Subject: [PATCH] Add boolean value transformations before send request Fix #23 --- composer.json | 2 +- src/Etsy/EtsyApi.php | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index eb13d98..e6af2e7 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/src/Etsy/EtsyApi.php b/src/Etsy/EtsyApi.php index a185235..06b8fa7 100644 --- a/src/Etsy/EtsyApi.php +++ b/src/Etsy/EtsyApi.php @@ -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]; @@ -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) @@ -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");