diff --git a/composer.json b/composer.json index d116104..951090c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "license": "MIT", "authors": [], "require": { - "php": ">=5.3.3", + "php": ">=5.5.0", "ext-curl": "*", "ext-json": "*", "guzzlehttp/guzzle": "^6.2", diff --git a/data/mocks/lists/StorefrontAccessTokensList.json b/data/mocks/lists/StorefrontAccessTokensList.json new file mode 100644 index 0000000..359e213 --- /dev/null +++ b/data/mocks/lists/StorefrontAccessTokensList.json @@ -0,0 +1,20 @@ +{ + "storefront_access_tokens":[ + { + "access_token":"5ba5eadd69da851d9d8a3dbdff700000", + "access_scope":"unauthenticated_read_content,unauthenticated_read_product_listings,unauthenticated_write_checkouts,unauthenticated_read_checkouts,unauthenticated_write_customers,unauthenticated_read_customers", + "created_at":"2020-07-15T13:28:36-04:00", + "id":12345678901, + "admin_graphql_api_id":"gid:\/\/shopify\/StorefrontAccessToken\/12345678901", + "title":"Access Token for Test 1" + }, + { + "access_token":"5ba5eadd69da851d9d8a3dbdff701111", + "access_scope":"unauthenticated_read_content,unauthenticated_read_product_listings,unauthenticated_write_checkouts,unauthenticated_read_checkouts,unauthenticated_write_customers,unauthenticated_read_customers", + "created_at":"2020-07-15T13:28:36-04:00", + "id":12345678902, + "admin_graphql_api_id":"gid:\/\/shopify\/StorefrontAccessToken\/12345678902", + "title":"Access Token for Test 2" + } + ] +} \ No newline at end of file diff --git a/data/mocks/objects/StorefrontAccessToken.json b/data/mocks/objects/StorefrontAccessToken.json new file mode 100644 index 0000000..4b42eb7 --- /dev/null +++ b/data/mocks/objects/StorefrontAccessToken.json @@ -0,0 +1,10 @@ +{ + "storefront_access_token":{ + "access_token":"5ba5eadd69da851d9d8a3dbdff70ac9a", + "access_scope":"unauthenticated_read_content,unauthenticated_read_product_listings,unauthenticated_write_checkouts,unauthenticated_read_checkouts,unauthenticated_write_customers,unauthenticated_read_customers", + "created_at":"2020-10-02T09:34:31-04:00", + "id":12345678901, + "admin_graphql_api_id":"gid:\/\/shopify\/StorefrontAccessToken\/12345678901", + "title":"New Token" + } +} \ No newline at end of file diff --git a/src/Enum/Fields/StorefrontAccessTokenFields.php b/src/Enum/Fields/StorefrontAccessTokenFields.php new file mode 100644 index 0000000..c8f4e4b --- /dev/null +++ b/src/Enum/Fields/StorefrontAccessTokenFields.php @@ -0,0 +1,25 @@ + 'integer', + 'access_token' => 'string', + 'access_scope ' => 'string', + 'created_at' => 'DateTime', + 'title' => 'string', + 'admin_graphql_api_id' => 'string', + ); + } +} diff --git a/src/Object/StorefrontAccessToken.php b/src/Object/StorefrontAccessToken.php new file mode 100644 index 0000000..1b82bde --- /dev/null +++ b/src/Object/StorefrontAccessToken.php @@ -0,0 +1,13 @@ + sprintf( - "https://%s/admin/api/%s", + "https://%s/admin/api/%s/", $this->myshopify_domain, $this->getApiVersion() ), diff --git a/src/Service/StorefrontAccessTokenService.php b/src/Service/StorefrontAccessTokenService.php new file mode 100644 index 0000000..956642c --- /dev/null +++ b/src/Service/StorefrontAccessTokenService.php @@ -0,0 +1,58 @@ +request($endpoint, 'GET', $params); + + return $this->createCollection( + StorefrontAccessToken::class, + $response['storefront_access_tokens'] + ); + } + + /** + * Create a new storefront access token. + * + * @link https://help.shopify.com/api/reference/storefrontaccesstoken#create + * @param StorefrontAccessToken $storefrontaccesstoken + * @return void + */ + public function create(StorefrontAccessToken &$storefrontaccesstoken) + { + $endpoint = 'storefront_access_tokens.json'; + $data = $storefrontaccesstoken->exportData(); + $response = $this->request( + $endpoint, 'POST', [ + 'storefront_access_token' => $data, + ] + ); + $storefrontaccesstoken->setData($response['storefront_access_tokens']); + } + + /** + * Remove a storefront access token. + * + * @link https://help.shopify.com/api/reference/storefrontaccesstoken#destroy + * @param StorefrontAccessToken $storefrontaccesstoken + * @return void + */ + public function delete(StorefrontAccessToken $storefrontaccesstoken) + { + $endpoint = 'storefront_access_tokens/'.$storefrontaccesstoken->id.'.json'; + $this->request($endpoint, 'DELETE'); + } +} diff --git a/test/Service/StorefrontAccessTokenServiceTest.php b/test/Service/StorefrontAccessTokenServiceTest.php new file mode 100644 index 0000000..bf1fa5d --- /dev/null +++ b/test/Service/StorefrontAccessTokenServiceTest.php @@ -0,0 +1,32 @@ +getApiMock('lists/StorefrontAccessTokensList.json'); + $service = new StorefrontAccessTokenService($api); + $tokens = $service->all(); + $this->assertContainsOnlyInstancesOf( + StorefrontAccessToken::class, + $tokens + ); + } + + public function _testCreate() + { + $api = $this->getApiMock('objects/StorefrontAccessToken.json'); + $service = new StorefrontAccessTokenService($api); + + $token = new StorefrontAccessToken(); + $token->setData(['title' => 'Test']); + $results = $service->create($token); + $this->assertInstanceOf(StorefrontAccessToken::class, $results); + } +}