From 2f9fecc3c2d09cb2f5cb84e1bc4c622889ed178f Mon Sep 17 00:00:00 2001 From: shimonhaga Date: Thu, 15 Dec 2022 23:39:56 +0900 Subject: [PATCH] Refactor about options --- composer.json | 2 +- src/Communicator/Request.php | 4 ++-- .../{Options.php => RequestOptions.php} | 2 +- src/Services/OAuth.php | 13 +++++-------- src/Services/Sales.php | 14 +++++++------- 5 files changed, 16 insertions(+), 19 deletions(-) rename src/Communicator/{Options.php => RequestOptions.php} (98%) diff --git a/composer.json b/composer.json index edb565f..3dc4706 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "minimum-stability": "dev", "prefer-stable": true, - "version": "0.0.10", + "version": "0.0.11", "license": "MIT", "authors": [ { diff --git a/src/Communicator/Request.php b/src/Communicator/Request.php index a9ede8e..7f150d6 100644 --- a/src/Communicator/Request.php +++ b/src/Communicator/Request.php @@ -6,10 +6,10 @@ class Request { - private Options $_options; + private RequestOptions $_options; private Client $_client; - public function __construct(?Options $options = new Options) + public function __construct(?RequestOptions $options = new RequestOptions) { $this->_options = $options; $this->_client = new Client(); diff --git a/src/Communicator/Options.php b/src/Communicator/RequestOptions.php similarity index 98% rename from src/Communicator/Options.php rename to src/Communicator/RequestOptions.php index d742d91..5f9e851 100644 --- a/src/Communicator/Options.php +++ b/src/Communicator/RequestOptions.php @@ -2,7 +2,7 @@ namespace Shimoning\ColorMeShopApi\Communicator; -class Options +class RequestOptions { private float $_timeout = 0; private float $_connectTimeout = 0; diff --git a/src/Services/OAuth.php b/src/Services/OAuth.php index 96ebffa..948f91e 100644 --- a/src/Services/OAuth.php +++ b/src/Services/OAuth.php @@ -3,19 +3,16 @@ namespace Shimoning\ColorMeShopApi\Services; use Shimoning\ColorMeShopApi\Communicator\Request; -use Shimoning\ColorMeShopApi\Communicator\Options as RequestOption; -use Shimoning\ColorMeShopApi\Entities\OAuth\Options; +use Shimoning\ColorMeShopApi\Communicator\RequestOptions; +use Shimoning\ColorMeShopApi\Entities\OAuth\Options as OAuthOptions; use Shimoning\ColorMeShopApi\Entities\OAuth\AccessToken; use Shimoning\ColorMeShopApi\Values\Scopes; class OAuth { - private Options $_options; + private OAuthOptions $_options; - /** - * @param Options $options - */ - public function __construct(Options $options) + public function __construct(OAuthOptions $options) { $this->_options = $options; } @@ -44,7 +41,7 @@ public function getOAuthUrl(Scopes $scopes): string */ public function exchangeCode2Token(string $code): AccessToken|bool { - $response = (new Request(new RequestOption(['form' => true])))->post( + $response = (new Request(new RequestOptions(['form' => true])))->post( $this->_options->getEndpointUri() . '/token', [ 'client_id' => $this->_options->getClientId(), diff --git a/src/Services/Sales.php b/src/Services/Sales.php index 49cb297..1b68d61 100644 --- a/src/Services/Sales.php +++ b/src/Services/Sales.php @@ -4,7 +4,7 @@ use DateTimeInterface; use Shimoning\ColorMeShopApi\Communicator\Request; -use Shimoning\ColorMeShopApi\Communicator\Options as RequestOption; +use Shimoning\ColorMeShopApi\Communicator\RequestOptions; use Shimoning\ColorMeShopApi\Communicator\Errors; use Shimoning\ColorMeShopApi\Entities\Sales\SearchParameters; use Shimoning\ColorMeShopApi\Entities\Sales\Sale; @@ -34,7 +34,7 @@ public function page( SearchParameters $searchParameters, ?string $accessToken = null, ): Page|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, ])))->get( 'https://api.shop-pro.jp/v1/sales', @@ -59,7 +59,7 @@ public function page( */ public function one(int|string $id, ?string $accessToken = null): Sale|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, ])))->get( 'https://api.shop-pro.jp/v1/sales/' . $id, @@ -82,7 +82,7 @@ public function stat( DateTimeInterface $dateTime, ?string $accessToken = null, ): Stat|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, ])))->get( 'https://api.shop-pro.jp/v1/sales/stat?', @@ -107,7 +107,7 @@ public function update( SaleUpdater $updater, ?string $accessToken = null, ): Sale|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, 'json' => true, ])))->put( @@ -135,7 +135,7 @@ public function cancel( ?bool $restock = false, ?string $accessToken = null, ): Sale|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, 'json' => true, ])))->put( @@ -163,7 +163,7 @@ public function sendMail( MailType $mailType, ?string $accessToken = null, ): bool|Errors { - $response = (new Request(new RequestOption([ + $response = (new Request(new RequestOptions([ 'authorization' => $accessToken ?? $this->_accessToken, 'json' => true, ])))->post(