From c66f517a09c2959ae5859f8850a4ed885105bbc3 Mon Sep 17 00:00:00 2001 From: Khair-ed-Din Husseini Date: Tue, 28 Mar 2017 20:52:03 +0200 Subject: [PATCH 1/2] [WIP]: Preliminary Checkout Generic API --- api.php | 1 + composer.json | 4 +++- data.json | 0 src/ApiResolver.php | 7 +++++++ src/Checkout/GenericApi.php | 40 +++++++++++++++++++++++++++++++++++++ src/GenericApi.php | 9 +++++++-- 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 api.php create mode 100644 data.json create mode 100644 src/Checkout/GenericApi.php diff --git a/api.php b/api.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/api.php @@ -0,0 +1 @@ + @@ -38,6 +39,12 @@ public function __construct(ClientInterface $client, UriMapInterface $uriMap) */ public function getApi($resource) { + if (strpos($resource, 'checkout') === 0) { + return new CheckoutGenericApi( + $this->client, + $this->uriMap->getUri($resource) + ); + } return new GenericApi($this->client, $this->uriMap->getUri($resource)); } } diff --git a/src/Checkout/GenericApi.php b/src/Checkout/GenericApi.php new file mode 100644 index 0000000..a401e7d --- /dev/null +++ b/src/Checkout/GenericApi.php @@ -0,0 +1,40 @@ +getClient() + ->put( + $this->getUri( + $uriParameters, + $body, + $files + ), + $body + ) + ; + + return $response->getStatusCode() === 204; + } + + public function update($id, array $body, array $uriParameters = [], array $files = []) + { + $uri = sprintf('%s%s', $this->getUri($uriParameters), $id); + + $response = $this + ->getClient() + ->put( + $uri, + $body + ) + ; + + return $response->getStatusCode() === 204; + } +} diff --git a/src/GenericApi.php b/src/GenericApi.php index bfcc87a..6ee9f7f 100644 --- a/src/GenericApi.php +++ b/src/GenericApi.php @@ -74,7 +74,7 @@ private function setUri($uri) * @param array $uriParameters * @return string */ - private function getUri(array $uriParameters = []) + protected function getUri(array $uriParameters = []) { $uri = $this->uri; foreach ($uriParameters as $uriParameterKey => $uriParameterValue) { @@ -167,7 +167,7 @@ public function delete($id, array $uriParameters = []) return (204 === $response->getStatusCode()); } - private function responseToArray(ResponseInterface $response) + protected function responseToArray(ResponseInterface $response) { $responseType = $response->getHeader('Content-Type'); if ((false === strpos($responseType, 'application/json')) && (false === strpos($responseType, 'application/xml'))) { @@ -176,4 +176,9 @@ private function responseToArray(ResponseInterface $response) return (strpos($responseType, 'application/json') !== false) ? $response->json() : $response->xml(); } + + protected function getClient() + { + return $this->client; + } } From 2fce9758c26205148992b2b81531a7b0f31e767e Mon Sep 17 00:00:00 2001 From: Khair-ed-Din Husseini Date: Fri, 7 Apr 2017 13:37:09 +0200 Subject: [PATCH 2/2] Removed unneeded files --- api.php | 1 - data.json | 0 2 files changed, 1 deletion(-) delete mode 100644 api.php delete mode 100644 data.json diff --git a/api.php b/api.php deleted file mode 100644 index b3d9bbc..0000000 --- a/api.php +++ /dev/null @@ -1 +0,0 @@ -