Skip to content

Commit

Permalink
Merge pull request #5 from xiatechs/upstream-upgrade
Browse files Browse the repository at this point in the history
Upgrade upstream to v3.12.0
  • Loading branch information
canni authored Dec 9, 2022
2 parents 07a8ae4 + 0ea37e4 commit 0a5852c
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 12 deletions.
28 changes: 28 additions & 0 deletions access_scopes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package goshopify

type AccessScopesService interface {
List(interface{}) ([]AccessScope, error)
}

type AccessScope struct {
Handle string `json:"handle,omitempty"`
}

// AccessScopesResource represents the result from the oauth/access_scopes.json endpoint
type AccessScopesResource struct {
AccessScopes []AccessScope `json:"access_scopes,omitempty"`
}

// AccessScopesServiceOp handles communication with the Access Scopes
// related methods of the Shopify API
type AccessScopesServiceOp struct {
client *Client
}

// List gets access scopes based on used oauth token
func (s *AccessScopesServiceOp) List(options interface{}) ([]AccessScope, error) {
path := "oauth/access_scopes.json"
resource := new(AccessScopesResource)
err := s.client.Get(path, resource, options)
return resource.AccessScopes, err
}
37 changes: 37 additions & 0 deletions access_scopes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package goshopify

import (
"testing"
"fmt"
"reflect"

"github.com/jarcoal/httpmock"
)

func TestAccessScopesServiceOp_List(t *testing.T) {
setup()
defer teardown()

httpmock.RegisterResponder(
"GET",
fmt.Sprintf("https://fooshop.myshopify.com/%s/oauth/access_scopes.json", client.pathPrefix),
httpmock.NewBytesResponder(200, loadFixture("access_scopes.json")),
)

scopeResponse, err := client.AccessScopes.List(nil)
if err != nil {
t.Errorf("AccessScopes.List returned an error: %v", err)
}

expected := []AccessScope{
{
Handle: "scope_1",
},
{
Handle: "scope_2",
},
}
if !reflect.DeepEqual(scopeResponse, expected) {
t.Errorf("AccessScopes.List returned %+v, expected %+v", expected, expected)
}
}
2 changes: 2 additions & 0 deletions customcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func TestCustomCollectionCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -261,6 +262,7 @@ func TestCustomCollectionUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
2 changes: 2 additions & 0 deletions customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func TestCustomerCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -518,6 +519,7 @@ func TestCustomerUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
10 changes: 10 additions & 0 deletions fixtures/access_scopes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"access_scopes": [
{
"handle": "scope_1"
},
{
"handle": "scope_2"
}
]
}
1 change: 1 addition & 0 deletions fixtures/metafield.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"key": "app_key",
"value": "app_value",
"value_type": "string",
"type": "single_line_text_field",
"description": "some amaaazing app's value",
"owner_id": 1,
"created_at": "2016-01-01T00:00:00Z",
Expand Down
4 changes: 3 additions & 1 deletion goshopify.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type Client struct {
InventoryItem InventoryItemService
ShippingZone ShippingZoneService
ProductListing ProductListingService
AccessScopes AccessScopesService
}

// A general response error that follows a similar layout to Shopify's response
Expand Down Expand Up @@ -289,6 +290,7 @@ func NewClient(app App, shopName, token string, opts ...Option) *Client {
c.InventoryItem = &InventoryItemServiceOp{client: c}
c.ShippingZone = &ShippingZoneServiceOp{client: c}
c.ProductListing = &ProductListingServiceOp{client: c}
c.AccessScopes = &AccessScopesServiceOp{client: c}

// apply any options
for _, opt := range opts {
Expand Down Expand Up @@ -323,7 +325,7 @@ func (c *Client) doGetHeaders(req *http.Request, v interface{}) (http.Header, er
resp, err = c.Client.Do(req)
c.logResponse(resp)
if err != nil {
return nil, err //http client errors, not api responses
return nil, err // http client errors, not api responses
}

respErr := CheckResponseError(resp)
Expand Down
23 changes: 12 additions & 11 deletions metafield.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ type MetafieldServiceOp struct {

// Metafield represents a Shopify metafield.
type Metafield struct {
ID int64 `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Value interface{} `json:"value,omitempty"`
ValueType string `json:"value_type,omitempty"`
Namespace string `json:"namespace,omitempty"`
Description string `json:"description,omitempty"`
OwnerId int64 `json:"owner_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
OwnerResource string `json:"owner_resource,omitempty"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
ID int64 `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Value interface{} `json:"value,omitempty"`
ValueType string `json:"value_type,omitempty"`
Type string `json:"type,omitempty"`
Namespace string `json:"namespace,omitempty"`
Description string `json:"description,omitempty"`
OwnerId int64 `json:"owner_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
OwnerResource string `json:"owner_resource,omitempty"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
}

// MetafieldResource represents the result from the metafields/X.json endpoint
Expand Down
3 changes: 3 additions & 0 deletions metafield_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func TestMetafieldGet(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
Description: "some amaaazing app's value",
OwnerId: 1,
Expand All @@ -115,6 +116,7 @@ func TestMetafieldCreate(t *testing.T) {
Key: "warehouse",
Value: "25",
ValueType: "integer",
Type: "single_line_text_field",
}

returnedMetafield, err := client.Metafield.Create(metafield)
Expand All @@ -136,6 +138,7 @@ func TestMetafieldUpdate(t *testing.T) {
ID: 1,
Value: "something new",
ValueType: "string",
Type: "single_line_text_field",
}

returnedMetafield, err := client.Metafield.Update(metafield)
Expand Down
2 changes: 2 additions & 0 deletions order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ func TestOrderCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -572,6 +573,7 @@ func TestOrderUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
2 changes: 2 additions & 0 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func TestPageCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -247,6 +248,7 @@ func TestPageUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
2 changes: 2 additions & 0 deletions product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func TestProductCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -416,6 +417,7 @@ func TestProductUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
2 changes: 2 additions & 0 deletions smartcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func TestSmartCollectionCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -264,6 +265,7 @@ func TestSmartCollectionUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down
2 changes: 2 additions & 0 deletions variant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func TestVariantCreateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand All @@ -344,6 +345,7 @@ func TestVariantUpdateMetafield(t *testing.T) {
Key: "app_key",
Value: "app_value",
ValueType: "string",
Type: "single_line_text_field",
Namespace: "affiliates",
}

Expand Down

0 comments on commit 0a5852c

Please sign in to comment.