Skip to content

Commit

Permalink
Added possibility to use Guzzle Request Options
Browse files Browse the repository at this point in the history
  • Loading branch information
allanvb committed Apr 5, 2023
1 parent d21dcdc commit 637a64f
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 91 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"type": "library",
"license": "MIT",
"version": "1.0.1",
"version": "1.0.2",
"require": {
"php": ">=7.4",
"guzzlehttp/guzzle": "^6|^7",
Expand All @@ -21,7 +21,7 @@
},
"autoload": {
"psr-4": {
"MerchOne\\PhpSdk\\": "src/"
"MerchOne\\PhpApiSdk\\": "src/"
}
},
"authors": [
Expand Down
19 changes: 13 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ composer require merch-one/php-api-sdk

### Basic Usage

**Create an instance of `MerchOne\PhpSdk\Http\Client`**
**Create an instance of `MerchOne\PhpApiSdk\Http\Client`**

```php
use MerchOne\PhpSdk\Http\Client;
use MerchOne\PhpApiSdk\Http\Client;

class MyService
{
Expand All @@ -59,15 +59,15 @@ class MyService
);

/* Interact with Catalog API */
/** @var \MerchOne\PhpSdk\Contracts\Clients\CatalogApi $catalogApi */
/** @var \MerchOne\PhpApiSdk\Contracts\Clients\CatalogApi $catalogApi */
$catalogApi = $this->httpClient->catalog();

/* Interact with Orders API */
/** @var \MerchOne\PhpSdk\Contracts\Clients\OrdersApi $ordersApi */
/** @var \MerchOne\PhpApiSdk\Contracts\Clients\OrdersApi $ordersApi */
$ordersApi = $this->httpClient->orders();

/* Interact with Shipping API */
/** @var \MerchOne\PhpSdk\Contracts\Clients\ShippingApi $shippingApi */
/** @var \MerchOne\PhpApiSdk\Contracts\Clients\ShippingApi $shippingApi */
$shippingApi = $this->httpClient->shipping();

// switch API version you interact with
Expand All @@ -78,13 +78,20 @@ class MyService
}
}
```
- The `Client` class accepts two parameters:
- `$version` - API version to interact with. Default value is `beta`.
- See [Helpers](#helpers) for available versions.
- `$clientOptions` - Custom options to use with request.
- See [Guzzle Documentation](https://docs.guzzlephp.org/en/stable/request-options.html) for available options.
- The `User-Agent`, `Accept` and `Content-Type` headers, as well as `http_error` properties **CAN NOT** be overwritten !


---

### Helpers

```php
use MerchOne\PhpSdk\Util\MerchOneApi;
use MerchOne\PhpApiSdk\Util\MerchOneApi;

// get the list of all available API versions
MerchOneApi::getVersions();
Expand Down
12 changes: 6 additions & 6 deletions src/Clients/BaseApiClient.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php

namespace MerchOne\PhpSdk\Clients;
namespace MerchOne\PhpApiSdk\Clients;

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response as PsrResponse;
use MerchOne\PhpSdk\Exceptions\InvalidCredentialsException;
use MerchOne\PhpSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpSdk\Http\Response;
use MerchOne\PhpSdk\Util\Data;
use MerchOne\PhpApiSdk\Exceptions\InvalidCredentialsException;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpApiSdk\Http\Response;
use MerchOne\PhpApiSdk\Util\Data;
use Tightenco\Collect\Support\Collection;
use Tightenco\Collect\Support\Enumerable;

Expand Down
10 changes: 5 additions & 5 deletions src/Clients/Beta/Catalog.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MerchOne\PhpSdk\Clients\Beta;
namespace MerchOne\PhpApiSdk\Clients\Beta;

use MerchOne\PhpSdk\Clients\BaseApiClient;
use MerchOne\PhpSdk\Contracts\Clients\CatalogApi;
use MerchOne\PhpSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpApiSdk\Clients\BaseApiClient;
use MerchOne\PhpApiSdk\Contracts\Clients\CatalogApi;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiServerException;
use Tightenco\Collect\Support\Enumerable;

class Catalog extends BaseApiClient implements CatalogApi
Expand Down
12 changes: 6 additions & 6 deletions src/Clients/Beta/Orders.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace MerchOne\PhpSdk\Clients\Beta;
namespace MerchOne\PhpApiSdk\Clients\Beta;

use MerchOne\PhpSdk\Clients\BaseApiClient;
use MerchOne\PhpSdk\Contracts\Clients\OrdersApi;
use MerchOne\PhpSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpSdk\Util\Data;
use MerchOne\PhpApiSdk\Clients\BaseApiClient;
use MerchOne\PhpApiSdk\Contracts\Clients\OrdersApi;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpApiSdk\Util\Data;
use Tightenco\Collect\Support\Enumerable;

class Orders extends BaseApiClient implements OrdersApi
Expand Down
10 changes: 5 additions & 5 deletions src/Clients/Beta/Shipping.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MerchOne\PhpSdk\Clients\Beta;
namespace MerchOne\PhpApiSdk\Clients\Beta;

use MerchOne\PhpSdk\Clients\BaseApiClient;
use MerchOne\PhpSdk\Contracts\Clients\ShippingApi;
use MerchOne\PhpSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpSdk\Exceptions\MerchOneApiServerException;
use MerchOne\PhpApiSdk\Clients\BaseApiClient;
use MerchOne\PhpApiSdk\Contracts\Clients\ShippingApi;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiClientException;
use MerchOne\PhpApiSdk\Exceptions\MerchOneApiServerException;
use Tightenco\Collect\Support\Enumerable;

class Shipping extends BaseApiClient implements ShippingApi
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Clients/CatalogApi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Contracts\Clients;
namespace MerchOne\PhpApiSdk\Contracts\Clients;

use Tightenco\Collect\Support\Enumerable;

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Clients/OrdersApi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Contracts\Clients;
namespace MerchOne\PhpApiSdk\Contracts\Clients;

use Tightenco\Collect\Support\Enumerable;

Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Clients/ShippingApi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Contracts\Clients;
namespace MerchOne\PhpApiSdk\Contracts\Clients;

use Tightenco\Collect\Support\Enumerable;

Expand Down
11 changes: 6 additions & 5 deletions src/Contracts/Http/HttpClient.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php

namespace MerchOne\PhpSdk\Contracts\Http;
namespace MerchOne\PhpApiSdk\Contracts\Http;

use MerchOne\PhpSdk\Contracts\Clients\CatalogApi;
use MerchOne\PhpSdk\Contracts\Clients\OrdersApi;
use MerchOne\PhpSdk\Contracts\Clients\ShippingApi;
use MerchOne\PhpApiSdk\Contracts\Clients\CatalogApi;
use MerchOne\PhpApiSdk\Contracts\Clients\OrdersApi;
use MerchOne\PhpApiSdk\Contracts\Clients\ShippingApi;

interface HttpClient
{
/**
* @param string $version
* @param array $clientOptions
*/
public function __construct(string $version);
public function __construct(string $version, array $clientOptions = []);

/**
* @param string $user
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidApiVersionException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Exceptions;
namespace MerchOne\PhpApiSdk\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidCredentialsException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Exceptions;
namespace MerchOne\PhpApiSdk\Exceptions;

class InvalidCredentialsException extends MerchOneApiClientException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/MerchOneApiClientException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Exceptions;
namespace MerchOne\PhpApiSdk\Exceptions;

use Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/MerchOneApiServerException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MerchOne\PhpSdk\Exceptions;
namespace MerchOne\PhpApiSdk\Exceptions;

use Exception;

Expand Down
Loading

0 comments on commit 637a64f

Please sign in to comment.