-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8c7667
commit e4da745
Showing
11 changed files
with
259 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ APP_ID= | |
CLIENT_ID= | ||
CLIENT_SECRET= | ||
REDIRECT_URI= | ||
TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Shimoning\ColorMeShopApi\Entities\Customer; | ||
|
||
use Shimoning\ColorMeShopApi\Entities\Entity; | ||
use Shimoning\ColorMeShopApi\Values\Furigana; | ||
use Shimoning\ColorMeShopApi\Values\DateTime; | ||
use Shimoning\ColorMeShopApi\Values\Limit; | ||
use Shimoning\ColorMeShopApi\Constants\Sex; | ||
|
||
/** | ||
* before/after は直感的でないためサポートしない。 | ||
* make_date_max/make_date_min を使用すること。 | ||
* | ||
* TODO: fields のサポート | ||
*/ | ||
class SearchParameters extends Entity | ||
{ | ||
const OBJECT_FIELDS = [ | ||
'furigana'=> [ | ||
'value' => Furigana::class, | ||
], | ||
'sex' => [ | ||
'enum' => Sex::class, | ||
], | ||
|
||
'makeDateMin'=> [ | ||
'value' => DateTime::class, | ||
], | ||
'makeDateMax'=> [ | ||
'value' => DateTime::class, | ||
], | ||
'updateDateMin'=> [ | ||
'value' => DateTime::class, | ||
], | ||
'updateDateMax'=> [ | ||
'value' => DateTime::class, | ||
], | ||
|
||
'limit'=> [ | ||
'value' => Limit::class, | ||
], | ||
]; | ||
|
||
protected ?array $ids; | ||
|
||
protected ?string $name; | ||
protected ?Furigana $furigana; | ||
|
||
protected ?string $mail; | ||
protected ?string $postal; | ||
protected ?string $tel; | ||
protected ?Sex $sex; | ||
protected ?bool $member; | ||
|
||
protected ?DateTime $makeDateMin; // after | ||
protected ?DateTime $makeDateMax; // before | ||
protected ?DateTime $updateDateMin; | ||
protected ?DateTime $updateDateMax; | ||
|
||
protected ?Limit $limit; | ||
protected ?int $offset; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Shimoning\ColorMeShopApi\Services; | ||
|
||
use Shimoning\ColorMeShopApi\Communicator\Request; | ||
use Shimoning\ColorMeShopApi\Communicator\RequestOptions; | ||
use Shimoning\ColorMeShopApi\Communicator\Errors; | ||
use Shimoning\ColorMeShopApi\Entities\Customer\SearchParameters; | ||
use Shimoning\ColorMeShopApi\Entities\Collection; | ||
use Shimoning\ColorMeShopApi\Entities\Page; | ||
use Shimoning\ColorMeShopApi\Entities\Pagination; | ||
use Shimoning\ColorMeShopApi\Entities\Customer\Customer as CustomerEntity; | ||
|
||
class Customer | ||
{ | ||
protected string $_accessToken; | ||
|
||
public function __construct(string $accessToken) | ||
{ | ||
$this->_accessToken = $accessToken; | ||
} | ||
|
||
/** | ||
* 顧客データのリストを取得 | ||
* | ||
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/Customer/operation/getCustomers | ||
* @param SearchParameters $searchParameters | ||
* @param string|null $accessToken | ||
* @return Page<CustomerEntity>|Errors | ||
*/ | ||
public function page( | ||
SearchParameters $searchParameters, | ||
?string $accessToken = null, | ||
): Page|Errors { | ||
$response = (new Request(new RequestOptions([ | ||
'authorization' => $accessToken ?? $this->_accessToken, | ||
])))->get( | ||
'https://api.shop-pro.jp/v1/customers', | ||
$searchParameters->toArrayRecursive(), | ||
); | ||
if (! $response->isSuccess()) { | ||
return Errors::build($response); | ||
} | ||
$data = $response->getParsedBody(); | ||
|
||
return new Page( | ||
Collection::cast(CustomerEntity::class, $data['customers'] ?? []), | ||
new Pagination($data['meta'] ?? []), | ||
); | ||
} | ||
|
||
/** | ||
* 顧客データの取得 | ||
* | ||
* @link https://developer.shop-pro.jp/docs/colorme-api#tag/customer/operation/getCustomer | ||
* @param int|string $id | ||
* @param string|null $accessToken | ||
* @return CustomerEntity|Errors | ||
*/ | ||
public function one(int|string $id, ?string $accessToken = null): CustomerEntity|Errors | ||
{ | ||
$response = (new Request(new RequestOptions([ | ||
'authorization' => $accessToken ?? $this->_accessToken, | ||
])))->get( | ||
'https://api.shop-pro.jp/v1/customers/' . $id, | ||
); | ||
if (! $response->isSuccess()) { | ||
return Errors::build($response); | ||
} | ||
$data = $response->getParsedBody(); | ||
return new CustomerEntity($data['customer'] ?? []); | ||
} | ||
|
||
// TODO: create | ||
// https://developer.shop-pro.jp/docs/colorme-api#tag/customer/operation/postCustomers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.