Skip to content
This repository was archived by the owner on May 7, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand Down
236 changes: 234 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/CurlRequest.php → src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/CurlResponse.php → src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Shopify;

class CurlResponse implements HttpResponseInterface
class Response implements HttpResponseInterface
{
private $headers;
private $responseBody;
Expand Down
2 changes: 1 addition & 1 deletion src/ShopifyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 2 additions & 2 deletions test/CurlRequestTest.php → test/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
18 changes: 9 additions & 9 deletions test/CurlResponseTest.php → test/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Shopify;

class CurlResponseTest extends \PHPUnit_Framework_TestCase
class ResponseTest extends \PHPUnit_Framework_TestCase
{
private $mockResponse;

Expand All @@ -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" => "",
Expand Down Expand Up @@ -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());
}
}