forked from imokyou/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storefrontaccesstoken.go
65 lines (55 loc) · 2.58 KB
/
storefrontaccesstoken.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package goshopify
import (
"fmt"
"time"
)
const storefrontAccessTokensBasePath = "storefront_access_tokens"
// StorefrontAccessTokenService is an interface for interfacing with the storefront access
// token endpoints of the Shopify API.
// See: https://help.shopify.com/api/reference/access/storefrontaccesstoken
type StorefrontAccessTokenService interface {
List(interface{}) ([]StorefrontAccessToken, error)
Create(StorefrontAccessToken) (*StorefrontAccessToken, error)
Delete(int64) error
}
// StorefrontAccessTokenServiceOp handles communication with the storefront access token
// related methods of the Shopify API.
type StorefrontAccessTokenServiceOp struct {
client *Client
}
// StorefrontAccessToken represents a Shopify storefront access token
type StorefrontAccessToken struct {
ID int64 `json:"id,omitempty"`
Title string `json:"title,omitempty"`
AccessToken string `json:"access_token,omitempty"`
AccessScope string `json:"access_scope,omitempty"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
}
// StorefrontAccessTokenResource represents the result from the admin/storefront_access_tokens.json endpoint
type StorefrontAccessTokenResource struct {
StorefrontAccessToken *StorefrontAccessToken `json:"storefront_access_token"`
}
// StorefrontAccessTokensResource is the root object for a storefront access tokens get request.
type StorefrontAccessTokensResource struct {
StorefrontAccessTokens []StorefrontAccessToken `json:"storefront_access_tokens"`
}
// List storefront access tokens
func (s *StorefrontAccessTokenServiceOp) List(options interface{}) ([]StorefrontAccessToken, error) {
path := fmt.Sprintf("%s.json", storefrontAccessTokensBasePath)
resource := new(StorefrontAccessTokensResource)
err := s.client.Get(path, resource, options)
return resource.StorefrontAccessTokens, err
}
// Create a new storefront access token
func (s *StorefrontAccessTokenServiceOp) Create(storefrontAccessToken StorefrontAccessToken) (*StorefrontAccessToken, error) {
path := fmt.Sprintf("%s.json", storefrontAccessTokensBasePath)
wrappedData := StorefrontAccessTokenResource{StorefrontAccessToken: &storefrontAccessToken}
resource := new(StorefrontAccessTokenResource)
err := s.client.Post(path, wrappedData, resource)
return resource.StorefrontAccessToken, err
}
// Delete an existing storefront access token
func (s *StorefrontAccessTokenServiceOp) Delete(ID int64) error {
return s.client.Delete(fmt.Sprintf("%s/%d.json", storefrontAccessTokensBasePath, ID))
}