From 3fc6371c9a3d4d097c2721f322b40656b6927c36 Mon Sep 17 00:00:00 2001 From: rodolfobandeira Date: Sat, 8 Apr 2017 16:11:44 -0400 Subject: [PATCH 1/3] Add composer install instructions --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8ee7223..a1007c2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ [![Build Status](https://travis-ci.org/Shopify/shopify-php.svg?branch=master)](https://travis-ci.org/Shopify/shopify-php) [![codecov](https://codecov.io/gh/Shopify/shopify-php/branch/master/graph/badge.svg)](https://codecov.io/gh/Shopify/shopify-php) +## Installation via [composer](https://getcomposer.org/download/) + +``` +composer require shopify/shopify-php +``` ## Getting started From 5bd36500c4a4d0e6f58b051922ebd48219feed26 Mon Sep 17 00:00:00 2001 From: rodolfobandeira Date: Sat, 8 Apr 2017 16:12:40 -0400 Subject: [PATCH 2/3] Rename license for Github pattern --- LICENSE.txt => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE.txt => LICENSE (100%) diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE From dfecd314df970b54fb6854ea8ecc21df430c0c2e Mon Sep 17 00:00:00 2001 From: rodolfobandeira Date: Sun, 9 Jul 2017 05:36:16 -0400 Subject: [PATCH 3/3] Install Guzzle and Renamed CURL Classes - Installs Guzzle latest version on Composer; - Renamed CurlRequest and CurlResponse to just Request/Response; - Changed all references to CurlRequest/Response to the reespective new name; --- composer.json | 3 +- composer.lock | 236 +++++++++++++++++- src/{CurlRequest.php => Request.php} | 4 +- src/{CurlResponse.php => Response.php} | 2 +- src/ShopifyClient.php | 2 +- test/{CurlRequestTest.php => RequestTest.php} | 4 +- ...{CurlResponseTest.php => ResponseTest.php} | 18 +- 7 files changed, 251 insertions(+), 18 deletions(-) rename src/{CurlRequest.php => Request.php} (92%) rename src/{CurlResponse.php => Response.php} (96%) rename test/{CurlRequestTest.php => RequestTest.php} (93%) rename test/{CurlResponseTest.php => ResponseTest.php} (89%) diff --git a/composer.json b/composer.json index 4a1aa39..2d0a219 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "description": "PHP library for the Shopify API", "require": { "php": ">=5.5.9", - "ext-curl": "*" + "ext-curl": "*", + "guzzlehttp/guzzle": "^6.3" }, "require-dev": { "phpunit/phpunit": "4.8.*", diff --git a/composer.lock b/composer.lock index 590355d..c96ceed 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,240 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "c034fbde1e8727c0dc95bc157419fcc5", - "packages": [], + "content-hash": "1f4ec33f5849e02aac16b9b6e1f0b3a9", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "6.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.4", + "php": ">=5.5" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0 || ^5.0", + "psr/log": "^1.0" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.2-dev" + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2017-06-22T18:50:49+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.4.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2017-03-20T17:10:46+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + } + ], "packages-dev": [ { "name": "doctrine/instantiator", diff --git a/src/CurlRequest.php b/src/Request.php similarity index 92% rename from src/CurlRequest.php rename to src/Request.php index 94e8ecd..e0c93cb 100644 --- a/src/CurlRequest.php +++ b/src/Request.php @@ -6,7 +6,7 @@ namespace Shopify; -class CurlRequest implements HttpRequestInterface +class Request implements HttpRequestInterface { public function request($method, $endpoint, array $headers = [], $payload = null, array $parameters = []) { @@ -24,7 +24,7 @@ public function request($method, $endpoint, array $headers = [], $payload = null $this->setCurlOpt($ch, CURLOPT_RETURNTRANSFER, true); $this->setCurlOpt($ch, CURLOPT_HEADER, 1); $response = $this->execute($ch); - return new CurlResponse($response); + return new Response($response); } protected function execute($ch) diff --git a/src/CurlResponse.php b/src/Response.php similarity index 96% rename from src/CurlResponse.php rename to src/Response.php index 3856275..f5138a8 100644 --- a/src/CurlResponse.php +++ b/src/Response.php @@ -6,7 +6,7 @@ namespace Shopify; -class CurlResponse implements HttpResponseInterface +class Response implements HttpResponseInterface { private $headers; private $responseBody; diff --git a/src/ShopifyClient.php b/src/ShopifyClient.php index fc44ba6..a81fb5e 100644 --- a/src/ShopifyClient.php +++ b/src/ShopifyClient.php @@ -88,6 +88,6 @@ public function call($method, $resource, $payload = null, $parameters = []) public function setHttpClient(HttpRequestInterface $client = null) { - $this->httpClient = ($client ? $client : new CurlRequest()); + $this->httpClient = ($client ? $client : new Request()); } } diff --git a/test/CurlRequestTest.php b/test/RequestTest.php similarity index 93% rename from test/CurlRequestTest.php rename to test/RequestTest.php index aaed754..686edb4 100644 --- a/test/CurlRequestTest.php +++ b/test/RequestTest.php @@ -6,12 +6,12 @@ namespace Shopify; -class CurlRequestTest extends \PHPUnit_Framework_TestCase +class RequestTest extends \PHPUnit_Framework_TestCase { public function testRequest() { $stub = $this-> - getMockBuilder('Shopify\CurlRequest') + getMockBuilder('Shopify\Request') ->setMethods(['setCurlOpt', 'execute', 'curlInit']) ->getMock(); $stub->method('execute')->willReturn("HTTP/1.1 201 Created\r\nServer: nginx\r\n\r\n{\"count\": 1}"); diff --git a/test/CurlResponseTest.php b/test/ResponseTest.php similarity index 89% rename from test/CurlResponseTest.php rename to test/ResponseTest.php index 90f67a5..7f604d5 100644 --- a/test/CurlResponseTest.php +++ b/test/ResponseTest.php @@ -6,7 +6,7 @@ namespace Shopify; -class CurlResponseTest extends \PHPUnit_Framework_TestCase +class ResponseTest extends \PHPUnit_Framework_TestCase { private $mockResponse; @@ -17,13 +17,13 @@ public function setUp() public function testHttpStatus() { - $response = new CurlResponse($this->mockResponse); + $response = new Response($this->mockResponse); $this->assertEquals(201, $response->httpStatus()); } public function testParsedResponse() { - $newResponse = new CurlResponse($this->mockResponse); + $newResponse = new Response($this->mockResponse); $object = (object)[ "id" => 4455820553, "email" => "", @@ -110,38 +110,38 @@ public function testParsedResponse() public function testJsonSmall() { - $newResponse = new CurlResponse("HTTP/1.1 201 Created\r\nServer: nginx\r\n\r\n{\"count\": 1}", 201); + $newResponse = new Response("HTTP/1.1 201 Created\r\nServer: nginx\r\n\r\n{\"count\": 1}", 201); $this->assertEquals(1, $newResponse->parsedResponse()); } public function testGetJsonNumerousRootElements() { - $newResponse = new CurlResponse("HTTP/1.1 201 Created\r\nServer: nginx\r\n\r\n{\"count\": 1, \"something_else\": \"cats\"}"); + $newResponse = new Response("HTTP/1.1 201 Created\r\nServer: nginx\r\n\r\n{\"count\": 1, \"something_else\": \"cats\"}"); $this->assertEquals(json_decode('{"count": 1, "something_else": "cats"}'), $newResponse->parsedResponse()); } public function testBody() { - $response = new CurlResponse($this->mockResponse); + $response = new Response($this->mockResponse); $rawBody = '{"order":{"id":4455820553,"email":"","closed_at":null,"created_at":"2017-01-16T16:46:24-05:00","updated_at":"2017-01-16T16:46:24-05:00","number":13,"note":null,"token":"3a62258de3dd34c4bf180d3fb63fb299","gateway":"","test":false,"total_price":"0.00","subtotal_price":"0.00","total_weight":0,"total_tax":"0.00","taxes_included":false,"currency":"CAD","financial_status":"paid","confirmed":true,"total_discounts":"0.00","total_line_items_price":"0.00","cart_token":null,"buyer_accepts_marketing":false,"name":"#1013","referring_site":null,"landing_site":null,"cancelled_at":null,"cancel_reason":null,"total_price_usd":"0.00","checkout_token":null,"reference":null,"user_id":null,"location_id":null,"source_identifier":null,"source_url":null,"processed_at":"2017-01-16T16:46:24-05:00","device_id":null,"browser_ip":null,"landing_site_ref":null,"order_number":1013,"discount_codes":[],"note_attributes":[],"payment_gateway_names":[],"processing_method":"","checkout_id":null,"source_name":"1223938","fulfillment_status":null,"tax_lines":[],"tags":"","contact_email":null,"order_status_url":null,"line_items":[{"id":8662293577,"variant_id":null,"title":"cool","quantity":0,"price":"4.00","grams":0,"sku":null,"variant_title":null,"vendor":null,"fulfillment_service":"manual","product_id":null,"requires_shipping":true,"taxable":true,"gift_card":false,"name":"cool","variant_inventory_management":null,"properties":[],"product_exists":false,"fulfillable_quantity":0,"total_discount":"0.00","fulfillment_status":null,"tax_lines":[]}],"shipping_lines":[],"fulfillments":[],"refunds":[]}}'; $this->assertEquals($rawBody, $response->body()); } public function testCreditLeft() { - $response = new CurlResponse($this->mockResponse); + $response = new Response($this->mockResponse); $this->assertEquals(39, $response->creditLeft()); } public function testCreditLimit() { - $response = new CurlResponse($this->mockResponse); + $response = new Response($this->mockResponse); $this->assertEquals(40, $response->creditLimit()); } public function testCreditUsed() { - $response = new CurlResponse($this->mockResponse); + $response = new Response($this->mockResponse); $this->assertEquals(1, $response->creditUsed()); } }