Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed api version terminal slash #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"authors": [],
"require": {
"php": ">=5.3.3",
"php": ">=5.5.0",
"ext-curl": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.2",
Expand Down
20 changes: 20 additions & 0 deletions data/mocks/lists/StorefrontAccessTokensList.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
10 changes: 10 additions & 0 deletions data/mocks/objects/StorefrontAccessToken.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
25 changes: 25 additions & 0 deletions src/Enum/Fields/StorefrontAccessTokenFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Shopify\Enum\Fields;

class StorefrontAccessTokenFields extends AbstractObjectEnum
{
const ID = 'id';
const ACCESS_TOKEN = 'access_token';
const ACCESS_SCOPE = 'access_scope';
const CREATED_AT = 'created_at';
const TITLE = 'title';
const ADMIN_GRAPHQL_API_ID = 'admin_graphql_api_id';

public function getFieldTypes()
{
return array(
'id' => 'integer',
'access_token' => 'string',
'access_scope ' => 'string',
'created_at' => 'DateTime',
'title' => 'string',
'admin_graphql_api_id' => 'string',
);
}
}
13 changes: 13 additions & 0 deletions src/Object/StorefrontAccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Shopify\Object;

use Shopify\Enum\Fields\StorefrontAccessTokenFields;

class StorefrontAccessToken extends AbstractObject
{
public static function getFieldsEnum()
{
return StorefrontAccessTokenFields::getInstance();
}
}
2 changes: 1 addition & 1 deletion src/PrivateApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function init()
{
$args = array(
'base_uri' => sprintf(
"https://%s/admin/api/%s",
"https://%s/admin/api/%s/",
$this->myshopify_domain,
$this->getApiVersion()
),
Expand Down
58 changes: 58 additions & 0 deletions src/Service/StorefrontAccessTokenService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Shopify\Service;

use Shopify\Object\StorefrontAccessToken;

class StorefrontAccessTokenService extends AbstractService
{
/**
* Receive a list of all storefront access tokens.
*
* @link https://help.shopify.com/api/reference/storefrontaccesstoken#index
* @param array $params
* @return StorefrontAccessToken[]
*/
public function all(array $params = [])
{
$endpoint = 'storefront_access_tokens.json';
$response = $this->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');
}
}
32 changes: 32 additions & 0 deletions test/Service/StorefrontAccessTokenServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Shopify\Test\Service;

use Shopify\Test\TestCase;
use Shopify\Service\StorefrontAccessTokenService;
use Shopify\Object\StorefrontAccessToken;

class StorefrontAccessTokenServiceTest extends TestCase
{
public function testList()
{
$api = $this->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);
}
}