From f0085a416718443d32fa0f7b3ad8fcdd7c8857fd Mon Sep 17 00:00:00 2001 From: Doug Moore Date: Thu, 25 Apr 2019 14:00:28 -0700 Subject: [PATCH] Shopify API versioning support (#48) * Build an Options function struct to optionally pass into the NewClient function in order to optionally prefix all API calls made with that function with a version. This is to adhere to the new Shopify API versioning changes, without making this a breaking change. --- applicationcharge.go | 12 ++--- applicationcharge_test.go | 12 ++--- asset.go | 10 ++-- asset_test.go | 9 ++-- blog.go | 14 ++--- blog_test.go | 13 ++--- collect.go | 6 +-- collect_test.go | 9 ++-- customcollection.go | 14 ++--- customcollection_test.go | 31 +++++------ customer.go | 48 ++++++++--------- customer_address.go | 10 ++-- customer_address_test.go | 13 ++--- customer_test.go | 39 +++++++------- discount_code.go | 12 ++--- discount_code_test.go | 13 ++--- draft_order.go | 18 +++---- draft_order_test.go | 37 +++++++------- fixtures/applicationcharge.json | 2 +- .../reccuringapplicationcharge.json | 2 +- ...applicationcharge_all_fields_affected.json | 2 +- .../reccuringapplicationcharge_bad.json | 2 +- ...ingapplicationcharge_bad_activated_on.json | 2 +- ...uringapplicationcharge_bad_billing_on.json | 2 +- ...ingapplicationcharge_bad_cancelled_on.json | 2 +- ...uringapplicationcharge_bad_created_at.json | 2 +- ...ngapplicationcharge_bad_trial_ends_on.json | 2 +- ...uringapplicationcharge_bad_updated_at.json | 2 +- fulfillment_test.go | 21 ++++---- goshopify.go | 34 +++++++++++-- goshopify_test.go | 46 +++++++++++++---- image.go | 12 ++--- image_test.go | 15 +++--- inventory_item.go | 8 +-- inventory_item_test.go | 11 ++-- location.go | 8 +-- location_test.go | 7 +-- metafield_test.go | 17 ++++--- order.go | 12 ++--- order_test.go | 51 ++++++++++--------- page.go | 14 ++--- page_test.go | 31 +++++------ product.go | 14 ++--- product_test.go | 31 +++++------ recurringapplicationcharge.go | 16 +++--- recurringapplicationcharge_test.go | 24 ++++----- redirect.go | 14 ++--- redirect_test.go | 17 ++++--- scripttag.go | 14 ++--- scripttag_test.go | 13 ++--- shop.go | 7 ++- shop_test.go | 3 +- smartcollection.go | 14 ++--- smartcollection_test.go | 31 +++++------ storefrontaccesstoken.go | 8 +-- storefrontaccesstoken_test.go | 9 ++-- theme.go | 4 +- theme_test.go | 5 +- transaction.go | 8 +-- transaction_test.go | 11 ++-- usagecharge.go | 6 +-- usagecharge_test.go | 11 ++-- util.go | 8 +-- util_test.go | 13 +++-- variant.go | 14 ++--- variant_test.go | 17 ++++--- webhook.go | 14 ++--- webhook_test.go | 15 +++--- 68 files changed, 527 insertions(+), 441 deletions(-) diff --git a/applicationcharge.go b/applicationcharge.go index b380a7da..4666f8f5 100644 --- a/applicationcharge.go +++ b/applicationcharge.go @@ -7,7 +7,7 @@ import ( "github.com/shopspring/decimal" ) -const applicationChargesBasePath = "admin/application_charges" +const applicationChargesBasePath = "application_charges" // ApplicationChargeService is an interface for interacting with the // ApplicationCharge endpoints of the Shopify API. @@ -26,7 +26,7 @@ type ApplicationChargeServiceOp struct { type ApplicationCharge struct { ID int64 `json:"id"` Name string `json:"name"` - APIClientID int64 `json:"api_client_id"` + APIClientID int64 `json:"api_client_id"` Price *decimal.Decimal `json:"price"` Status string `json:"status"` ReturnURL string `json:"return_url"` @@ -52,28 +52,28 @@ type ApplicationChargesResource struct { // Create creates new application charge. func (a ApplicationChargeServiceOp) Create(charge ApplicationCharge) (*ApplicationCharge, error) { - path := fmt.Sprintf("%s.json", applicationChargesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, applicationChargesBasePath) resource := &ApplicationChargeResource{} return resource.Charge, a.client.Post(path, ApplicationChargeResource{Charge: &charge}, resource) } // Get gets individual application charge. func (a ApplicationChargeServiceOp) Get(chargeID int64, options interface{}) (*ApplicationCharge, error) { - path := fmt.Sprintf("%s/%d.json", applicationChargesBasePath, chargeID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, applicationChargesBasePath, chargeID) resource := &ApplicationChargeResource{} return resource.Charge, a.client.Get(path, resource, options) } // List gets all application charges. func (a ApplicationChargeServiceOp) List(options interface{}) ([]ApplicationCharge, error) { - path := fmt.Sprintf("%s.json", applicationChargesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, applicationChargesBasePath) resource := &ApplicationChargesResource{} return resource.Charges, a.client.Get(path, resource, options) } // Activate activates application charge. func (a ApplicationChargeServiceOp) Activate(charge ApplicationCharge) (*ApplicationCharge, error) { - path := fmt.Sprintf("%s/%d/activate.json", applicationChargesBasePath, charge.ID) + path := fmt.Sprintf("%s/%s/%d/activate.json", globalApiPathPrefix, applicationChargesBasePath, charge.ID) resource := &ApplicationChargeResource{} return resource.Charge, a.client.Post(path, ApplicationChargeResource{Charge: &charge}, resource) } diff --git a/applicationcharge_test.go b/applicationcharge_test.go index 24e83e9d..c90ba7c4 100644 --- a/applicationcharge_test.go +++ b/applicationcharge_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -33,8 +34,7 @@ func applicationChargeTests(t *testing.T, charge ApplicationCharge) { }, { "ConfirmationURL", - "https://apple.myshopify.com/admin/charges/1017262355/confirm_application_charge?sign" + - "ature=BAhpBBMxojw%3D--1139a82a3433b1a6771786e03f02300440e11883", + fmt.Sprintf("https://apple.myshopify.com/%s/charges/1017262355/confirm_application_charge?signature=BAhpBBMxojw%%3D--1139a82a3433b1a6771786e03f02300440e11883", globalApiPathPrefix), charge.ConfirmationURL, }, } @@ -52,7 +52,7 @@ func TestApplicationChargeServiceOp_Create(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/application_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/application_charges.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("applicationcharge.json")), ) @@ -77,7 +77,7 @@ func TestApplicationChargeServiceOp_Get(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/application_charges/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/application_charges/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"application_charge": {"id":1}}`), ) @@ -98,7 +98,7 @@ func TestApplicationChargeServiceOp_List(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/application_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/application_charges.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"application_charges": [{"id":1},{"id":2}]}`), ) @@ -119,7 +119,7 @@ func TestApplicationChargeServiceOp_Activate(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/application_charges/455696195/activate.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/application_charges/455696195/activate.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"application_charge":{"id":455696195,"status":"active"}}`, diff --git a/asset.go b/asset.go index 580fb0c8..f64c5246 100644 --- a/asset.go +++ b/asset.go @@ -5,7 +5,7 @@ import ( "time" ) -const assetsBasePath = "admin/themes" +const assetsBasePath = "themes" // AssetService is an interface for interfacing with the asset endpoints // of the Shopify API. @@ -55,7 +55,7 @@ type assetGetOptions struct { // List the metadata for all assets in the given theme func (s *AssetServiceOp) List(themeID int64, options interface{}) ([]Asset, error) { - path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID) + path := fmt.Sprintf("%s/%s/%d/assets.json", globalApiPathPrefix, assetsBasePath, themeID) resource := new(AssetsResource) err := s.client.Get(path, resource, options) return resource.Assets, err @@ -63,7 +63,7 @@ func (s *AssetServiceOp) List(themeID int64, options interface{}) ([]Asset, erro // Get an asset by key from the given theme func (s *AssetServiceOp) Get(themeID int64, key string) (*Asset, error) { - path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID) + path := fmt.Sprintf("%s/%s/%d/assets.json", globalApiPathPrefix, assetsBasePath, themeID) options := assetGetOptions{ Key: key, ThemeID: themeID, @@ -75,7 +75,7 @@ func (s *AssetServiceOp) Get(themeID int64, key string) (*Asset, error) { // Update an asset func (s *AssetServiceOp) Update(themeID int64, asset Asset) (*Asset, error) { - path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID) + path := fmt.Sprintf("%s/%s/%d/assets.json", globalApiPathPrefix, assetsBasePath, themeID) wrappedData := AssetResource{Asset: &asset} resource := new(AssetResource) err := s.client.Put(path, wrappedData, resource) @@ -84,6 +84,6 @@ func (s *AssetServiceOp) Update(themeID int64, asset Asset) (*Asset, error) { // Delete an asset func (s *AssetServiceOp) Delete(themeID int64, key string) error { - path := fmt.Sprintf("%s/%d/assets.json?asset[key]=%s", assetsBasePath, themeID, key) + path := fmt.Sprintf("%s/%s/%d/assets.json?asset[key]=%s", globalApiPathPrefix, assetsBasePath, themeID, key) return s.client.Delete(path) } diff --git a/asset_test.go b/asset_test.go index 13f6699c..d0359530 100644 --- a/asset_test.go +++ b/asset_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" @@ -20,7 +21,7 @@ func TestAssetList(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/themes/1/assets.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"assets": [{"key":"assets\/1.liquid"},{"key":"assets\/2.liquid"}]}`, @@ -47,7 +48,7 @@ func TestAssetGet(t *testing.T) { } httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/themes/1/assets.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", globalApiPathPrefix), params, httpmock.NewStringResponder( 200, @@ -72,7 +73,7 @@ func TestAssetUpdate(t *testing.T) { httpmock.RegisterResponder( "PUT", - "https://fooshop.myshopify.com/admin/themes/1/assets.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("asset.json"), @@ -100,7 +101,7 @@ func TestAssetDelete(t *testing.T) { params := map[string]string{"asset[key]": "foo/bar.liquid"} httpmock.RegisterResponderWithQuery( "DELETE", - "https://fooshop.myshopify.com/admin/themes/1/assets.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes/1/assets.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, "{}"), ) diff --git a/blog.go b/blog.go index 871b328d..8d3c06ff 100644 --- a/blog.go +++ b/blog.go @@ -5,7 +5,7 @@ import ( "time" ) -const blogsBasePath = "admin/blogs" +const blogsBasePath = "blogs" // BlogService is an interface for interfacing with the blogs endpoints // of the Shopify API. @@ -52,7 +52,7 @@ type BlogResource struct { // List all blogs func (s *BlogServiceOp) List(options interface{}) ([]Blog, error) { - path := fmt.Sprintf("%s.json", blogsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, blogsBasePath) resource := new(BlogsResource) err := s.client.Get(path, resource, options) return resource.Blogs, err @@ -60,13 +60,13 @@ func (s *BlogServiceOp) List(options interface{}) ([]Blog, error) { // Count blogs func (s *BlogServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", blogsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, blogsBasePath) return s.client.Count(path, options) } // Get single blog func (s *BlogServiceOp) Get(blogId int64, options interface{}) (*Blog, error) { - path := fmt.Sprintf("%s/%d.json", blogsBasePath, blogId) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, blogsBasePath, blogId) resource := new(BlogResource) err := s.client.Get(path, resource, options) return resource.Blog, err @@ -74,7 +74,7 @@ func (s *BlogServiceOp) Get(blogId int64, options interface{}) (*Blog, error) { // Create a new blog func (s *BlogServiceOp) Create(blog Blog) (*Blog, error) { - path := fmt.Sprintf("%s.json", blogsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, blogsBasePath) wrappedData := BlogResource{Blog: &blog} resource := new(BlogResource) err := s.client.Post(path, wrappedData, resource) @@ -83,7 +83,7 @@ func (s *BlogServiceOp) Create(blog Blog) (*Blog, error) { // Update an existing blog func (s *BlogServiceOp) Update(blog Blog) (*Blog, error) { - path := fmt.Sprintf("%s/%d.json", blogsBasePath, blog.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, blogsBasePath, blog.ID) wrappedData := BlogResource{Blog: &blog} resource := new(BlogResource) err := s.client.Put(path, wrappedData, resource) @@ -92,5 +92,5 @@ func (s *BlogServiceOp) Update(blog Blog) (*Blog, error) { // Delete an blog func (s *BlogServiceOp) Delete(blogId int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", blogsBasePath, blogId)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, blogsBasePath, blogId)) } diff --git a/blog_test.go b/blog_test.go index 9dc8f02c..ade05e7d 100644 --- a/blog_test.go +++ b/blog_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" @@ -13,7 +14,7 @@ func TestBlogList(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/blogs.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"blogs": [{"id":1},{"id":2}]}`, @@ -38,7 +39,7 @@ func TestBlogCount(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/blogs/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs/count.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"count": 5}`, @@ -63,7 +64,7 @@ func TestBlogGet(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/blogs/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs/1.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"blog": {"id":1}}`, @@ -88,7 +89,7 @@ func TestBlogCreate(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/blogs.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("blog.json"), @@ -117,7 +118,7 @@ func TestBlogUpdate(t *testing.T) { httpmock.RegisterResponder( "PUT", - "https://fooshop.myshopify.com/admin/blogs/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs/1.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("blog.json"), @@ -144,7 +145,7 @@ func TestBlogDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/blogs/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/blogs/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Blog.Delete(1) diff --git a/collect.go b/collect.go index e8345331..2d5b0dfc 100644 --- a/collect.go +++ b/collect.go @@ -5,7 +5,7 @@ import ( "time" ) -const collectsBasePath = "admin/collects" +const collectsBasePath = "collects" // CollectService is an interface for interfacing with the collect endpoints // of the Shopify API. @@ -45,7 +45,7 @@ type CollectsResource struct { // List collects func (s *CollectServiceOp) List(options interface{}) ([]Collect, error) { - path := fmt.Sprintf("%s.json", collectsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, collectsBasePath) resource := new(CollectsResource) err := s.client.Get(path, resource, options) return resource.Collects, err @@ -53,6 +53,6 @@ func (s *CollectServiceOp) List(options interface{}) ([]Collect, error) { // Count collects func (s *CollectServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", collectsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, collectsBasePath) return s.client.Count(path, options) } diff --git a/collect_test.go b/collect_test.go index 5b232135..2e15b841 100644 --- a/collect_test.go +++ b/collect_test.go @@ -1,10 +1,11 @@ package goshopify import ( + "fmt" "reflect" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func collectTests(t *testing.T, collect Collect) { @@ -33,7 +34,7 @@ func TestCollectList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collects.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collects.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"collects": [{"id":1},{"id":2}]}`)) collects, err := client.Collect.List(nil) @@ -51,12 +52,12 @@ func TestCollectCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collects/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collects/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 5}`)) params := map[string]string{"since_id": "123"} httpmock.RegisterResponderWithQuery("GET", - "https://fooshop.myshopify.com/admin/collects/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/collects/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) diff --git a/customcollection.go b/customcollection.go index c321aa9d..660bb76e 100644 --- a/customcollection.go +++ b/customcollection.go @@ -5,7 +5,7 @@ import ( "time" ) -const customCollectionsBasePath = "admin/custom_collections" +const customCollectionsBasePath = "custom_collections" const customCollectionsResourceName = "collections" // CustomCollectionService is an interface for interacting with the custom @@ -57,7 +57,7 @@ type CustomCollectionsResource struct { // List custom collections func (s *CustomCollectionServiceOp) List(options interface{}) ([]CustomCollection, error) { - path := fmt.Sprintf("%s.json", customCollectionsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, customCollectionsBasePath) resource := new(CustomCollectionsResource) err := s.client.Get(path, resource, options) return resource.Collections, err @@ -65,13 +65,13 @@ func (s *CustomCollectionServiceOp) List(options interface{}) ([]CustomCollectio // Count custom collections func (s *CustomCollectionServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", customCollectionsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, customCollectionsBasePath) return s.client.Count(path, options) } // Get individual custom collection func (s *CustomCollectionServiceOp) Get(collectionID int64, options interface{}) (*CustomCollection, error) { - path := fmt.Sprintf("%s/%d.json", customCollectionsBasePath, collectionID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, customCollectionsBasePath, collectionID) resource := new(CustomCollectionResource) err := s.client.Get(path, resource, options) return resource.Collection, err @@ -80,7 +80,7 @@ func (s *CustomCollectionServiceOp) Get(collectionID int64, options interface{}) // Create a new custom collection // See Image for the details of the Image creation for a collection. func (s *CustomCollectionServiceOp) Create(collection CustomCollection) (*CustomCollection, error) { - path := fmt.Sprintf("%s.json", customCollectionsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, customCollectionsBasePath) wrappedData := CustomCollectionResource{Collection: &collection} resource := new(CustomCollectionResource) err := s.client.Post(path, wrappedData, resource) @@ -89,7 +89,7 @@ func (s *CustomCollectionServiceOp) Create(collection CustomCollection) (*Custom // Update an existing custom collection func (s *CustomCollectionServiceOp) Update(collection CustomCollection) (*CustomCollection, error) { - path := fmt.Sprintf("%s/%d.json", customCollectionsBasePath, collection.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, customCollectionsBasePath, collection.ID) wrappedData := CustomCollectionResource{Collection: &collection} resource := new(CustomCollectionResource) err := s.client.Put(path, wrappedData, resource) @@ -98,7 +98,7 @@ func (s *CustomCollectionServiceOp) Update(collection CustomCollection) (*Custom // Delete an existing custom collection. func (s *CustomCollectionServiceOp) Delete(collectionID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", customCollectionsBasePath, collectionID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, customCollectionsBasePath, collectionID)) } // List metafields for a custom collection diff --git a/customcollection_test.go b/customcollection_test.go index e73dc45f..abfc19ea 100644 --- a/customcollection_test.go +++ b/customcollection_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func customCollectionTests(t *testing.T, collection CustomCollection) { @@ -34,7 +35,7 @@ func TestCustomCollectionList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/custom_collections.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"custom_collections": [{"id":1},{"id":2}]}`)) products, err := client.CustomCollection.List(nil) @@ -52,13 +53,13 @@ func TestCustomCollectionCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/custom_collections/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 5}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/custom_collections/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -88,7 +89,7 @@ func TestCustomCollectionGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/custom_collections/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"custom_collection": {"id":1}}`)) product, err := client.CustomCollection.Get(1, nil) @@ -106,7 +107,7 @@ func TestCustomCollectionCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/custom_collections.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customcollection.json"))) collection := CustomCollection{ @@ -125,7 +126,7 @@ func TestCustomCollectionUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/custom_collections/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customcollection.json"))) collection := CustomCollection{ @@ -145,7 +146,7 @@ func TestCustomCollectionDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/custom_collections/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/custom_collections/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.CustomCollection.Delete(1) @@ -158,7 +159,7 @@ func TestCustomCollectionListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.CustomCollection.ListMetafields(1, nil) @@ -176,13 +177,13 @@ func TestCustomCollectionCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -212,7 +213,7 @@ func TestCustomCollectionGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.CustomCollection.GetMetafield(1, 2, nil) @@ -230,7 +231,7 @@ func TestCustomCollectionCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/collections/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -252,7 +253,7 @@ func TestCustomCollectionUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -275,7 +276,7 @@ func TestCustomCollectionDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.CustomCollection.DeleteMetafield(1, 2) diff --git a/customer.go b/customer.go index 67c34264..d550c225 100644 --- a/customer.go +++ b/customer.go @@ -7,7 +7,7 @@ import ( "github.com/shopspring/decimal" ) -const customersBasePath = "admin/customers" +const customersBasePath = "customers" const customersResourceName = "customers" // CustomerService is an interface for interfacing with the customers endpoints @@ -85,7 +85,7 @@ type CustomerSearchOptions struct { // List customers func (s *CustomerServiceOp) List(options interface{}) ([]Customer, error) { - path := fmt.Sprintf("%s.json", customersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, customersBasePath) resource := new(CustomersResource) err := s.client.Get(path, resource, options) return resource.Customers, err @@ -93,13 +93,13 @@ func (s *CustomerServiceOp) List(options interface{}) ([]Customer, error) { // Count customers func (s *CustomerServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", customersBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, customersBasePath) return s.client.Count(path, options) } // Get customer func (s *CustomerServiceOp) Get(customerID int64, options interface{}) (*Customer, error) { - path := fmt.Sprintf("%s/%v.json", customersBasePath, customerID) + path := fmt.Sprintf("%s/%s/%v.json", globalApiPathPrefix, customersBasePath, customerID) resource := new(CustomerResource) err := s.client.Get(path, resource, options) return resource.Customer, err @@ -107,7 +107,7 @@ func (s *CustomerServiceOp) Get(customerID int64, options interface{}) (*Custome // Create a new customer func (s *CustomerServiceOp) Create(customer Customer) (*Customer, error) { - path := fmt.Sprintf("%s.json", customersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, customersBasePath) wrappedData := CustomerResource{Customer: &customer} resource := new(CustomerResource) err := s.client.Post(path, wrappedData, resource) @@ -116,7 +116,7 @@ func (s *CustomerServiceOp) Create(customer Customer) (*Customer, error) { // Update an existing customer func (s *CustomerServiceOp) Update(customer Customer) (*Customer, error) { - path := fmt.Sprintf("%s/%d.json", customersBasePath, customer.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, customersBasePath, customer.ID) wrappedData := CustomerResource{Customer: &customer} resource := new(CustomerResource) err := s.client.Put(path, wrappedData, resource) @@ -125,18 +125,34 @@ func (s *CustomerServiceOp) Update(customer Customer) (*Customer, error) { // Delete an existing customer func (s *CustomerServiceOp) Delete(customerID int64) error { - path := fmt.Sprintf("%s/%d.json", customersBasePath, customerID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, customersBasePath, customerID) return s.client.Delete(path) } // Search customers func (s *CustomerServiceOp) Search(options interface{}) ([]Customer, error) { - path := fmt.Sprintf("%s/search.json", customersBasePath) + path := fmt.Sprintf("%s/%s/search.json", globalApiPathPrefix, customersBasePath) resource := new(CustomersResource) err := s.client.Get(path, resource, options) return resource.Customers, err } +// ListOrders retrieves all orders from a customer +func (s *CustomerServiceOp) ListOrders(customerID int64, options interface{}) ([]Order, error) { + path := fmt.Sprintf("%s/%s/%d/orders.json", globalApiPathPrefix, customersBasePath, customerID) + resource := new(OrdersResource) + err := s.client.Get(path, resource, options) + return resource.Orders, err +} + +// ListTags retrieves all unique tags across all customers +func (s *CustomerServiceOp) ListTags(options interface{}) ([]string, error) { + path := fmt.Sprintf("%s/%s/tags.json", globalApiPathPrefix, customersBasePath) + resource := new(CustomerTagsResource) + err := s.client.Get(path, resource, options) + return resource.Tags, err +} + // List metafields for a customer func (s *CustomerServiceOp) ListMetafields(customerID int64, options interface{}) ([]Metafield, error) { metafieldService := &MetafieldServiceOp{client: s.client, resource: customersResourceName, resourceID: customerID} @@ -172,19 +188,3 @@ func (s *CustomerServiceOp) DeleteMetafield(customerID int64, metafieldID int64) metafieldService := &MetafieldServiceOp{client: s.client, resource: customersResourceName, resourceID: customerID} return metafieldService.Delete(metafieldID) } - -// ListOrders retrieves all orders from a customer -func (s *CustomerServiceOp) ListOrders(customerID int64, options interface{}) ([]Order, error) { - path := fmt.Sprintf("%s/%d/orders.json", customersBasePath, customerID) - resource := new(OrdersResource) - err := s.client.Get(path, resource, options) - return resource.Orders, err -} - -// ListTags retrieves all unique tags across all customers -func (s *CustomerServiceOp) ListTags(options interface{}) ([]string, error) { - path := fmt.Sprintf("%s/tags.json", customersBasePath) - resource := new(CustomerTagsResource) - err := s.client.Get(path, resource, options) - return resource.Tags, err -} diff --git a/customer_address.go b/customer_address.go index d34096a9..e7335721 100644 --- a/customer_address.go +++ b/customer_address.go @@ -54,7 +54,7 @@ type CustomerAddressesResource struct { // List addresses func (s *CustomerAddressServiceOp) List(customerID int64, options interface{}) ([]CustomerAddress, error) { - path := fmt.Sprintf("%s/%d/addresses.json", customersBasePath, customerID) + path := fmt.Sprintf("%s/%s/%d/addresses.json", globalApiPathPrefix, customersBasePath, customerID) resource := new(CustomerAddressesResource) err := s.client.Get(path, resource, options) return resource.Addresses, err @@ -62,7 +62,7 @@ func (s *CustomerAddressServiceOp) List(customerID int64, options interface{}) ( // Get address func (s *CustomerAddressServiceOp) Get(customerID, addressID int64, options interface{}) (*CustomerAddress, error) { - path := fmt.Sprintf("%s/%d/addresses/%d.json", customersBasePath, customerID, addressID) + path := fmt.Sprintf("%s/%s/%d/addresses/%d.json", globalApiPathPrefix, customersBasePath, customerID, addressID) resource := new(CustomerAddressResource) err := s.client.Get(path, resource, options) return resource.Address, err @@ -70,7 +70,7 @@ func (s *CustomerAddressServiceOp) Get(customerID, addressID int64, options inte // Create a new address for given customer func (s *CustomerAddressServiceOp) Create(customerID int64, address CustomerAddress) (*CustomerAddress, error) { - path := fmt.Sprintf("%s/%d/addresses.json", customersBasePath, customerID) + path := fmt.Sprintf("%s/%s/%d/addresses.json", globalApiPathPrefix, customersBasePath, customerID) wrappedData := CustomerAddressResource{Address: &address} resource := new(CustomerAddressResource) err := s.client.Post(path, wrappedData, resource) @@ -79,7 +79,7 @@ func (s *CustomerAddressServiceOp) Create(customerID int64, address CustomerAddr // Create a new address for given customer func (s *CustomerAddressServiceOp) Update(customerID int64, address CustomerAddress) (*CustomerAddress, error) { - path := fmt.Sprintf("%s/%d/addresses/%d.json", customersBasePath, customerID, address.ID) + path := fmt.Sprintf("%s/%s/%d/addresses/%d.json", globalApiPathPrefix, customersBasePath, customerID, address.ID) wrappedData := CustomerAddressResource{Address: &address} resource := new(CustomerAddressResource) err := s.client.Put(path, wrappedData, resource) @@ -88,5 +88,5 @@ func (s *CustomerAddressServiceOp) Update(customerID int64, address CustomerAddr // Delete an existing address func (s *CustomerAddressServiceOp) Delete(customerID, addressID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d/addresses/%d.json", customersBasePath, customerID, addressID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d/addresses/%d.json", globalApiPathPrefix, customersBasePath, customerID, addressID)) } diff --git a/customer_address_test.go b/customer_address_test.go index 39741f6a..ad526f6b 100644 --- a/customer_address_test.go +++ b/customer_address_test.go @@ -1,9 +1,10 @@ package goshopify import ( + "fmt" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func verifyAddress(t *testing.T, address CustomerAddress) { @@ -97,7 +98,7 @@ func TestList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/addresses.json", httpmock.NewBytesResponder(200, loadFixture("customer_addresses.json"))) + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_addresses.json"))) addresses, err := client.CustomerAddress.List(1, nil) if err != nil { @@ -114,7 +115,7 @@ func TestGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/addresses/1.json", httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) address, err := client.CustomerAddress.Get(1, 1, nil) if err != nil { @@ -128,7 +129,7 @@ func TestCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/customers/1/addresses.json", httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) address, err := client.CustomerAddress.Create(1, CustomerAddress{}) if err != nil { @@ -142,7 +143,7 @@ func TestUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/customers/1/addresses/1.json", httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_address.json"))) address, err := client.CustomerAddress.Update(1, CustomerAddress{ID: 1}) if err != nil { @@ -156,7 +157,7 @@ func TestDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/customers/1/addresses/1.json", httpmock.NewStringResponder(200, "{}")) + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/addresses/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.CustomerAddress.Delete(1, 1) if err != nil { diff --git a/customer_test.go b/customer_test.go index 2f306f27..aee8f4ce 100644 --- a/customer_test.go +++ b/customer_test.go @@ -1,19 +1,20 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" "github.com/shopspring/decimal" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func TestCustomerList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"customers": [{"id":1},{"id":2}]}`)) customers, err := client.Customer.List(nil) @@ -31,13 +32,13 @@ func TestCustomerCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 5}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/customers/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -67,7 +68,7 @@ func TestCustomerSearch(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/search.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/search.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"customers": [{"id":1},{"id":2}]}`)) customers, err := client.Customer.Search(nil) @@ -85,7 +86,7 @@ func TestCustomerGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer.json"))) customer, err := client.Customer.Get(1, nil) @@ -234,7 +235,7 @@ func TestCustomerUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/customers/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer.json"))) customer := Customer{ @@ -257,7 +258,7 @@ func TestCustomerCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/customers.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer.json"))) customer := Customer{ @@ -280,7 +281,7 @@ func TestCustomerDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/customers/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "")) err := client.Customer.Delete(1) @@ -293,7 +294,7 @@ func TestCustomerListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.Customer.ListMetafields(1, nil) @@ -311,13 +312,13 @@ func TestCustomerCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/customers/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -347,7 +348,7 @@ func TestCustomerGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/customers/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.Customer.GetMetafield(1, 2, nil) @@ -365,7 +366,7 @@ func TestCustomerCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/customers/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -387,7 +388,7 @@ func TestCustomerUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/customers/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -410,7 +411,7 @@ func TestCustomerDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/customers/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Customer.DeleteMetafield(1, 2) @@ -425,13 +426,13 @@ func TestCustomerListOrders(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/customers/1/orders.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/orders.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{\"orders\":[]}"), ) params := map[string]string{"status": "any"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/customers/1/orders.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/1/orders.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("orders.json")), ) @@ -466,7 +467,7 @@ func TestCustomerListTags(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/customers/tags.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/customers/tags.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("customer_tags.json")), ) diff --git a/discount_code.go b/discount_code.go index 14abd04a..76783b2b 100644 --- a/discount_code.go +++ b/discount_code.go @@ -5,7 +5,7 @@ import ( "time" ) -const discountCodeBasePath = "/admin/price_rules/%d/discount_codes" +const discountCodeBasePath = "price_rules/%d/discount_codes" // DiscountCodeService is an interface for interfacing with the discount endpoints // of the Shopify API. @@ -46,7 +46,7 @@ type DiscountCodeResource struct { // Create a discount code func (s *DiscountCodeServiceOp) Create(priceRuleID int64, dc PriceRuleDiscountCode) (*PriceRuleDiscountCode, error) { - path := fmt.Sprintf(discountCodeBasePath+".json", priceRuleID) + path := fmt.Sprintf("%s/"+discountCodeBasePath+".json", globalApiPathPrefix, priceRuleID) wrappedData := DiscountCodeResource{PriceRuleDiscountCode: &dc} resource := new(DiscountCodeResource) err := s.client.Post(path, wrappedData, resource) @@ -55,7 +55,7 @@ func (s *DiscountCodeServiceOp) Create(priceRuleID int64, dc PriceRuleDiscountCo // Update an existing discount code func (s *DiscountCodeServiceOp) Update(priceRuleID int64, dc PriceRuleDiscountCode) (*PriceRuleDiscountCode, error) { - path := fmt.Sprintf(discountCodeBasePath+"/%d.json", priceRuleID, dc.ID) + path := fmt.Sprintf("%s/"+discountCodeBasePath+"/%d.json", globalApiPathPrefix, priceRuleID, dc.ID) wrappedData := DiscountCodeResource{PriceRuleDiscountCode: &dc} resource := new(DiscountCodeResource) err := s.client.Put(path, wrappedData, resource) @@ -64,7 +64,7 @@ func (s *DiscountCodeServiceOp) Update(priceRuleID int64, dc PriceRuleDiscountCo // List of discount codes func (s *DiscountCodeServiceOp) List(priceRuleID int64) ([]PriceRuleDiscountCode, error) { - path := fmt.Sprintf(discountCodeBasePath+".json", priceRuleID) + path := fmt.Sprintf("%s/"+discountCodeBasePath+".json", globalApiPathPrefix, priceRuleID) resource := new(DiscountCodesResource) err := s.client.Get(path, resource, nil) return resource.DiscountCodes, err @@ -72,7 +72,7 @@ func (s *DiscountCodeServiceOp) List(priceRuleID int64) ([]PriceRuleDiscountCode // Get a single discount code func (s *DiscountCodeServiceOp) Get(priceRuleID int64, discountCodeID int64) (*PriceRuleDiscountCode, error) { - path := fmt.Sprintf(discountCodeBasePath+"/%d.json", priceRuleID, discountCodeID) + path := fmt.Sprintf("%s/"+discountCodeBasePath+"/%d.json", globalApiPathPrefix, priceRuleID, discountCodeID) resource := new(DiscountCodeResource) err := s.client.Get(path, resource, nil) return resource.PriceRuleDiscountCode, err @@ -80,5 +80,5 @@ func (s *DiscountCodeServiceOp) Get(priceRuleID int64, discountCodeID int64) (*P // Delete a discount code func (s *DiscountCodeServiceOp) Delete(priceRuleID int64, discountCodeID int64) error { - return s.client.Delete(fmt.Sprintf(discountCodeBasePath+"/%d.json", priceRuleID, discountCodeID)) + return s.client.Delete(fmt.Sprintf("%s/"+discountCodeBasePath+"/%d.json", globalApiPathPrefix, priceRuleID, discountCodeID)) } diff --git a/discount_code_test.go b/discount_code_test.go index b3212f24..f236b5fc 100644 --- a/discount_code_test.go +++ b/discount_code_test.go @@ -1,9 +1,10 @@ package goshopify import ( + "fmt" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func TestDiscountCodeList(t *testing.T) { @@ -12,7 +13,7 @@ func TestDiscountCodeList(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/price_rules/507328175/discount_codes.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/price_rules/507328175/discount_codes.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"discount_codes":[{"id":507328175,"price_rule_id":507328175,"code":"SUMMERSALE10OFF","usage_count":0,"created_at":"2018-07-05T12:41:00-04:00","updated_at":"2018-07-05T12:41:00-04:00"}]}`, @@ -37,7 +38,7 @@ func TestDiscountCodeGet(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/price_rules/507328175/discount_codes/507328175.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/price_rules/507328175/discount_codes/507328175.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"discount_code":{"id":507328175,"price_rule_id":507328175,"code":"SUMMERSALE10OFF","usage_count":0,"created_at":"2018-07-05T12:41:00-04:00","updated_at":"2018-07-05T12:41:00-04:00"}}`, @@ -63,7 +64,7 @@ func TestDiscountCodeCreate(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/price_rules/507328175/discount_codes.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/price_rules/507328175/discount_codes.json", globalApiPathPrefix), httpmock.NewBytesResponder( 201, loadFixture("discount_code.json"), @@ -92,7 +93,7 @@ func TestDiscountCodeUpdate(t *testing.T) { httpmock.RegisterResponder( "PUT", - "https://fooshop.myshopify.com/admin/price_rules/507328175/discount_codes/1054381139.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/price_rules/507328175/discount_codes/1054381139.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("discount_code.json"), @@ -119,7 +120,7 @@ func TestDiscountCodeDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/price_rules/507328175/discount_codes/507328175.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/price_rules/507328175/discount_codes/507328175.json", globalApiPathPrefix), httpmock.NewStringResponder(204, "{}")) err := client.DiscountCode.Delete(507328175, 507328175) diff --git a/draft_order.go b/draft_order.go index 91c5d088..4ca68822 100644 --- a/draft_order.go +++ b/draft_order.go @@ -8,7 +8,7 @@ import ( ) const ( - draftOrdersBasePath = "admin/draft_orders" + draftOrdersBasePath = "draft_orders" draftOrdersResourceName = "draft_orders" ) @@ -119,7 +119,7 @@ type DraftOrderCountOptions struct { // Create draft order func (s *DraftOrderServiceOp) Create(draftOrder DraftOrder) (*DraftOrder, error) { - path := fmt.Sprintf("%s.json", draftOrdersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, draftOrdersBasePath) wrappedData := DraftOrderResource{DraftOrder: &draftOrder} resource := new(DraftOrderResource) err := s.client.Post(path, wrappedData, resource) @@ -128,7 +128,7 @@ func (s *DraftOrderServiceOp) Create(draftOrder DraftOrder) (*DraftOrder, error) // List draft orders func (s *DraftOrderServiceOp) List(options interface{}) ([]DraftOrder, error) { - path := fmt.Sprintf("%s.json", draftOrdersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, draftOrdersBasePath) resource := new(DraftOrdersResource) err := s.client.Get(path, resource, options) return resource.DraftOrders, err @@ -136,19 +136,19 @@ func (s *DraftOrderServiceOp) List(options interface{}) ([]DraftOrder, error) { // Count draft orders func (s *DraftOrderServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", draftOrdersBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, draftOrdersBasePath) return s.client.Count(path, options) } // Delete draft orders func (s *DraftOrderServiceOp) Delete(draftOrderID int64) error { - path := fmt.Sprintf("%s/%d.json", draftOrdersBasePath, draftOrderID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, draftOrdersBasePath, draftOrderID) return s.client.Delete(path) } // Invoice a draft order func (s *DraftOrderServiceOp) Invoice(draftOrderID int64, draftOrderInvoice DraftOrderInvoice) (*DraftOrderInvoice, error) { - path := fmt.Sprintf("%s/%d/send_invoice.json", draftOrdersBasePath, draftOrderID) + path := fmt.Sprintf("%s/%s/%d/send_invoice.json", globalApiPathPrefix, draftOrdersBasePath, draftOrderID) wrappedData := DraftOrderInvoiceResource{DraftOrderInvoice: &draftOrderInvoice} resource := new(DraftOrderInvoiceResource) err := s.client.Post(path, wrappedData, resource) @@ -157,7 +157,7 @@ func (s *DraftOrderServiceOp) Invoice(draftOrderID int64, draftOrderInvoice Draf // Get individual draft order func (s *DraftOrderServiceOp) Get(draftOrderID int64, options interface{}) (*DraftOrder, error) { - path := fmt.Sprintf("%s/%d.json", draftOrdersBasePath, draftOrderID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, draftOrdersBasePath, draftOrderID) resource := new(DraftOrderResource) err := s.client.Get(path, resource, options) return resource.DraftOrder, err @@ -165,7 +165,7 @@ func (s *DraftOrderServiceOp) Get(draftOrderID int64, options interface{}) (*Dra // Update draft order func (s *DraftOrderServiceOp) Update(draftOrder DraftOrder) (*DraftOrder, error) { - path := fmt.Sprintf("%s/%d.json", draftOrdersBasePath, draftOrder.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, draftOrdersBasePath, draftOrder.ID) wrappedData := DraftOrderResource{DraftOrder: &draftOrder} resource := new(DraftOrderResource) err := s.client.Put(path, wrappedData, resource) @@ -174,7 +174,7 @@ func (s *DraftOrderServiceOp) Update(draftOrder DraftOrder) (*DraftOrder, error) // Complete draft order func (s *DraftOrderServiceOp) Complete(draftOrderID int64, paymentPending bool) (*DraftOrder, error) { - path := fmt.Sprintf("%s/%d/complete.json?payment_pending=%t", draftOrdersBasePath, draftOrderID, paymentPending) + path := fmt.Sprintf("%s/%s/%d/complete.json?payment_pending=%t", globalApiPathPrefix, draftOrdersBasePath, draftOrderID, paymentPending) resource := new(DraftOrderResource) err := s.client.Put(path, nil, resource) return resource.DraftOrder, err diff --git a/draft_order_test.go b/draft_order_test.go index ed5fdd41..361b6bf6 100644 --- a/draft_order_test.go +++ b/draft_order_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -54,7 +55,7 @@ func TestDraftOrderGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders/994118539.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/994118539.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("draft_order.json"))) draftOrder, err := client.DraftOrder.Get(994118539, nil) @@ -68,7 +69,7 @@ func TestDraftOrderCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/draft_orders.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders.json", globalApiPathPrefix), httpmock.NewStringResponder(201, `{"draft_order":{"id": 1}}`)) draftOrder := DraftOrder{ @@ -95,7 +96,7 @@ func TestDraftOrderUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/draft_orders/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"draft_order":{"id": 1}}`)) draftOrder := DraftOrder{ @@ -120,13 +121,13 @@ func TestDraftOrderCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 7}`)) params := map[string]string{"status": "open"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/draft_orders/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -155,7 +156,7 @@ func TestDraftOrderList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("draft_orders.json"))) draftOrders, err := client.DraftOrder.List(nil) @@ -180,7 +181,7 @@ func TestDraftOrderListOptions(t *testing.T) { } httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/draft_orders.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("draft_orders.json"))) @@ -209,7 +210,7 @@ func TestDraftOrderInvoice(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/draft_orders/1/send_invoice.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/send_invoice.json", globalApiPathPrefix), httpmock.NewBytesResponder(201, loadFixture("invoice.json"))) invoice := DraftOrderInvoice{ To: "first@example.com", @@ -236,7 +237,7 @@ func TestDraftOrderDelete(t *testing.T) { httpmock.RegisterResponder( "DELETE", - "https://fooshop.myshopify.com/admin/draft_orders/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, nil)) err := client.DraftOrder.Delete(1) @@ -250,7 +251,7 @@ func TestDraftOrderComplete(t *testing.T) { params := map[string]string{"payment_pending": "false"} httpmock.RegisterResponderWithQuery( "PUT", - "https://fooshop.myshopify.com/admin/draft_orders/1/complete.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/complete.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("draft_order.json"))) @@ -267,7 +268,7 @@ func TestDraftOrderCompletePending(t *testing.T) { params := map[string]string{"payment_pending": "true"} httpmock.RegisterResponderWithQuery( "PUT", - "https://fooshop.myshopify.com/admin/draft_orders/1/complete.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/complete.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("draft_order.json"))) @@ -282,7 +283,7 @@ func TestDraftOrderListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.DraftOrder.ListMetafields(1, nil) @@ -300,13 +301,13 @@ func TestDraftOrderCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/draft_orders/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -336,7 +337,7 @@ func TestDraftOrderGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.DraftOrder.GetMetafield(1, 2, nil) @@ -354,7 +355,7 @@ func TestDraftOrderCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -376,7 +377,7 @@ func TestDraftOrderUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -399,7 +400,7 @@ func TestDraftOrderDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/draft_orders/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/draft_orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.DraftOrder.DeleteMetafield(1, 2) diff --git a/fixtures/applicationcharge.json b/fixtures/applicationcharge.json index 1e58d023..42f3e77b 100644 --- a/fixtures/applicationcharge.json +++ b/fixtures/applicationcharge.json @@ -11,6 +11,6 @@ "updated_at": "2018-07-05T13:11:28-04:00", "charge_type": null, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1017262355", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1017262355/confirm_application_charge?signature=BAhpBBMxojw%3D--1139a82a3433b1a6771786e03f02300440e11883" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1017262355/confirm_application_charge?signature=BAhpBBMxojw%3D--1139a82a3433b1a6771786e03f02300440e11883" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge.json index 91a3c70c..ae19bb3e 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_all_fields_affected.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_all_fields_affected.json index 9e40e8ca..5752abeb 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_all_fields_affected.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_all_fields_affected.json @@ -15,6 +15,6 @@ "cancelled_on": "2018-06-05", "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad.json index d43d477e..9885af44 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad.json @@ -15,6 +15,6 @@ "cancelled_on": false, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_activated_on.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_activated_on.json index a2e3489d..fd76b465 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_activated_on.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_activated_on.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_billing_on.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_billing_on.json index f466ab0b..bd3b594c 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_billing_on.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_billing_on.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_cancelled_on.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_cancelled_on.json index 8010162b..4d9ae9d4 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_cancelled_on.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_cancelled_on.json @@ -15,6 +15,6 @@ "cancelled_on": "ptk 27 lip 14:24:13 2018 CEST", "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_created_at.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_created_at.json index 34684092..396613e6 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_created_at.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_created_at.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_trial_ends_on.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_trial_ends_on.json index 15d7b22e..166c2a82 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_trial_ends_on.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_trial_ends_on.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_updated_at.json b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_updated_at.json index 912328c7..d2e2a471 100755 --- a/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_updated_at.json +++ b/fixtures/reccuringapplicationcharge/reccuringapplicationcharge_bad_updated_at.json @@ -15,6 +15,6 @@ "cancelled_on": null, "trial_days": 0, "decorated_return_url": "http://super-duper.shopifyapps.com/?charge_id=1029266948", - "confirmation_url": "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" + "confirmation_url": "https://apple.myshopify.com/admin/api/9999-99/charges/1029266948/confirm_recurring_application_charge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68" } } diff --git a/fulfillment_test.go b/fulfillment_test.go index 84a11692..afe1c8da 100644 --- a/fulfillment_test.go +++ b/fulfillment_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func FulfillmentTests(t *testing.T, fulfillment Fulfillment) { @@ -20,7 +21,7 @@ func TestFulfillmentList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123/fulfillments.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"fulfillments": [{"id":1},{"id":2}]}`)) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -40,13 +41,13 @@ func TestFulfillmentCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/orders/123/fulfillments/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -78,7 +79,7 @@ func TestFulfillmentGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"fulfillment": {"id":1}}`)) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -98,7 +99,7 @@ func TestFulfillmentCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/123/fulfillments.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -125,7 +126,7 @@ func TestFulfillmentUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/1022782888.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/1022782888.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -147,7 +148,7 @@ func TestFulfillmentComplete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/1/complete.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/1/complete.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -164,7 +165,7 @@ func TestFulfillmentTransition(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/1/open.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/1/open.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} @@ -181,7 +182,7 @@ func TestFulfillmentCancel(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/123/fulfillments/1/cancel.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123/fulfillments/1/cancel.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillmentService := &FulfillmentServiceOp{client: client, resource: ordersResourceName, resourceID: 123} diff --git a/goshopify.go b/goshopify.go index 5d222207..42dbbcdc 100644 --- a/goshopify.go +++ b/goshopify.go @@ -9,6 +9,7 @@ import ( "net/http" "net/url" "reflect" + "regexp" "sort" "strconv" "strings" @@ -21,6 +22,11 @@ const ( UserAgent = "goshopify/1.0.0" ) +var ( + // Shopify API version YYYY-MM + globalApiPathPrefix string +) + // App represents basic app settings such as Api key, secret, scope, and redirect url. // See oauth.go for OAuth related helper functions. type App struct { @@ -173,18 +179,33 @@ func (c *Client) NewRequest(method, urlStr string, body, options interface{}) (* return req, nil } +// Option is used to configure client with options +type Option func(c *Client) + +// WithVersion optionally sets the api-version if the passed string is valid +func WithVersion(apiVersion string) Option { + return func(c *Client) { + var rxPat = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}$`) + if len(apiVersion) > 0 && rxPat.MatchString(apiVersion) { + globalApiPathPrefix = fmt.Sprintf("admin/api/%s", apiVersion) + } else { + globalApiPathPrefix = "admin" + } + } +} + // NewClient returns a new Shopify API client with an already authenticated shopname and // token. The shopName parameter is the shop's myshopify domain, // e.g. "theshop.myshopify.com", or simply "theshop" -// a.NewClient(shopName, token) is equivalent to NewClient(a, shopName, token) -func (a App) NewClient(shopName, token string) *Client { - return NewClient(a, shopName, token) +// a.NewClient(shopName, token, opts) is equivalent to NewClient(a, shopName, token, opts) +func (a App) NewClient(shopName, token string, opts ...Option) *Client { + return NewClient(a, shopName, token, opts...) } // Returns a new Shopify API client with an already authenticated shopname and // token. The shopName parameter is the shop's myshopify domain, // e.g. "theshop.myshopify.com", or simply "theshop" -func NewClient(app App, shopName, token string) *Client { +func NewClient(app App, shopName, token string, opts ...Option) *Client { httpClient := http.DefaultClient baseURL, _ := url.Parse(ShopBaseUrl(shopName)) @@ -218,6 +239,11 @@ func NewClient(app App, shopName, token string) *Client { c.DiscountCode = &DiscountCodeServiceOp{client: c} c.InventoryItem = &InventoryItemServiceOp{client: c} + // apply any options + for _, opt := range opts { + opt(c) + } + return c } diff --git a/goshopify_test.go b/goshopify_test.go index 8f485a29..2ee720fd 100644 --- a/goshopify_test.go +++ b/goshopify_test.go @@ -16,6 +16,10 @@ import ( "gopkg.in/jarcoal/httpmock.v1" ) +const ( + testApiVersion = "9999-99" +) + var ( client *Client app App @@ -40,7 +44,7 @@ func setup() { Scope: "read_products", Password: "privateapppassword", } - client = NewClient(app, "fooshop", "abcd") + client = NewClient(app, "fooshop", "abcd", WithVersion(testApiVersion)) httpmock.ActivateNonDefault(client.Client) } @@ -56,8 +60,32 @@ func loadFixture(filename string) []byte { return f } +func TestWithVersion(t *testing.T) { + _ = NewClient(app, "fooshop", "abcd", WithVersion(testApiVersion)) + expected := fmt.Sprintf("admin/api/%s", testApiVersion) + if globalApiPathPrefix != expected { + t.Errorf("WithVersion globalApiPathPrefix = %s, expected %s", globalApiPathPrefix, expected) + } +} + +func TestWithVersionNoVersion(t *testing.T) { + _ = NewClient(app, "fooshop", "abcd", WithVersion("")) + expected := "admin" + if globalApiPathPrefix != expected { + t.Errorf("WithVersion globalApiPathPrefix = %s, expected %s", globalApiPathPrefix, expected) + } +} + +func TestWithVersionInvalidVersion(t *testing.T) { + _ = NewClient(app, "fooshop", "abcd", WithVersion("9999-99b")) + expected := "admin" + if globalApiPathPrefix != expected { + t.Errorf("WithVersion globalApiPathPrefix = %s, expected %s", globalApiPathPrefix, expected) + } +} + func TestNewClient(t *testing.T) { - testClient := NewClient(app, "fooshop", "abcd") + testClient := NewClient(app, "fooshop", "abcd", WithVersion(testApiVersion)) expected := "https://fooshop.myshopify.com" if testClient.baseURL.String() != expected { t.Errorf("NewClient BaseURL = %v, expected %v", testClient.baseURL.String(), expected) @@ -65,7 +93,7 @@ func TestNewClient(t *testing.T) { } func TestNewClientWithNoToken(t *testing.T) { - testClient := NewClient(app, "fooshop", "") + testClient := NewClient(app, "fooshop", "", WithVersion(testApiVersion)) expected := "https://fooshop.myshopify.com" if testClient.baseURL.String() != expected { t.Errorf("NewClient BaseURL = %v, expected %v", testClient.baseURL.String(), expected) @@ -73,7 +101,7 @@ func TestNewClientWithNoToken(t *testing.T) { } func TestAppNewClient(t *testing.T) { - testClient := app.NewClient("fooshop", "abcd") + testClient := app.NewClient("fooshop", "abcd", WithVersion(testApiVersion)) expected := "https://fooshop.myshopify.com" if testClient.baseURL.String() != expected { t.Errorf("NewClient BaseURL = %v, expected %v", testClient.baseURL.String(), expected) @@ -81,7 +109,7 @@ func TestAppNewClient(t *testing.T) { } func TestAppNewClientWithNoToken(t *testing.T) { - testClient := app.NewClient("fooshop", "") + testClient := app.NewClient("fooshop", "", WithVersion(testApiVersion)) expected := "https://fooshop.myshopify.com" if testClient.baseURL.String() != expected { t.Errorf("NewClient BaseURL = %v, expected %v", testClient.baseURL.String(), expected) @@ -89,7 +117,7 @@ func TestAppNewClientWithNoToken(t *testing.T) { } func TestNewRequest(t *testing.T) { - testClient := NewClient(app, "fooshop", "abcd") + testClient := NewClient(app, "fooshop", "abcd", WithVersion(testApiVersion)) inURL, outURL := "foo?page=1", "https://fooshop.myshopify.com/foo?limit=10&page=1" inBody := struct { @@ -132,7 +160,7 @@ func TestNewRequest(t *testing.T) { } func TestNewRequestForPrivateApp(t *testing.T) { - testClient := NewClient(app, "fooshop", "") + testClient := NewClient(app, "fooshop", "", WithVersion(testApiVersion)) inURL, outURL := "foo?page=1", "https://fooshop.myshopify.com/foo?limit=10&page=1" inBody := struct { @@ -189,7 +217,7 @@ func TestNewRequestForPrivateApp(t *testing.T) { } func TestNewRequestMissingToken(t *testing.T) { - testClient := NewClient(app, "fooshop", "") + testClient := NewClient(app, "fooshop", "", WithVersion(testApiVersion)) req, _ := testClient.NewRequest("GET", "/foo", nil, nil) @@ -201,7 +229,7 @@ func TestNewRequestMissingToken(t *testing.T) { } func TestNewRequestError(t *testing.T) { - testClient := NewClient(app, "fooshop", "abcd") + testClient := NewClient(app, "fooshop", "abcd", WithVersion(testApiVersion)) cases := []struct { method string diff --git a/image.go b/image.go index 6e52e090..951e4211 100644 --- a/image.go +++ b/image.go @@ -50,7 +50,7 @@ type ImagesResource struct { // List images func (s *ImageServiceOp) List(productID int64, options interface{}) ([]Image, error) { - path := fmt.Sprintf("%s/%d/images.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/images.json", globalApiPathPrefix, productsBasePath, productID) resource := new(ImagesResource) err := s.client.Get(path, resource, options) return resource.Images, err @@ -58,13 +58,13 @@ func (s *ImageServiceOp) List(productID int64, options interface{}) ([]Image, er // Count images func (s *ImageServiceOp) Count(productID int64, options interface{}) (int, error) { - path := fmt.Sprintf("%s/%d/images/count.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/images/count.json", globalApiPathPrefix, productsBasePath, productID) return s.client.Count(path, options) } // Get individual image func (s *ImageServiceOp) Get(productID int64, imageID int64, options interface{}) (*Image, error) { - path := fmt.Sprintf("%s/%d/images/%d.json", productsBasePath, productID, imageID) + path := fmt.Sprintf("%s/%s/%d/images/%d.json", globalApiPathPrefix, productsBasePath, productID, imageID) resource := new(ImageResource) err := s.client.Get(path, resource, options) return resource.Image, err @@ -84,7 +84,7 @@ func (s *ImageServiceOp) Get(productID int64, imageID int64, options interface{} // // Shopify will accept Image.Attachment without Image.Filename. func (s *ImageServiceOp) Create(productID int64, image Image) (*Image, error) { - path := fmt.Sprintf("%s/%d/images.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/images.json", globalApiPathPrefix, productsBasePath, productID) wrappedData := ImageResource{Image: &image} resource := new(ImageResource) err := s.client.Post(path, wrappedData, resource) @@ -93,7 +93,7 @@ func (s *ImageServiceOp) Create(productID int64, image Image) (*Image, error) { // Update an existing image func (s *ImageServiceOp) Update(productID int64, image Image) (*Image, error) { - path := fmt.Sprintf("%s/%d/images/%d.json", productsBasePath, productID, image.ID) + path := fmt.Sprintf("%s/%s/%d/images/%d.json", globalApiPathPrefix, productsBasePath, productID, image.ID) wrappedData := ImageResource{Image: &image} resource := new(ImageResource) err := s.client.Put(path, wrappedData, resource) @@ -102,5 +102,5 @@ func (s *ImageServiceOp) Update(productID int64, image Image) (*Image, error) { // Delete an existing image func (s *ImageServiceOp) Delete(productID int64, imageID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d/images/%d.json", productsBasePath, productID, imageID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d/images/%d.json", globalApiPathPrefix, productsBasePath, productID, imageID)) } diff --git a/image_test.go b/image_test.go index 6ecb5ede..eb848a15 100644 --- a/image_test.go +++ b/image_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "testing" "time" @@ -73,7 +74,7 @@ func TestImageList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/images.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("images.json"))) images, err := client.Image.List(1, nil) @@ -93,13 +94,13 @@ func TestImageCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/images/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 2}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/products/1/images/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 1}`)) @@ -129,7 +130,7 @@ func TestImageGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/images/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("image.json"))) image, err := client.Image.Get(1, 1, nil) @@ -144,7 +145,7 @@ func TestImageCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/products/1/images.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("image.json"))) variantIds := make([]int64, 2) @@ -167,7 +168,7 @@ func TestImageUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/products/1/images/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("image.json"))) // Take an existing image @@ -192,7 +193,7 @@ func TestImageDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/products/1/images/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/images/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Image.Delete(1, 1) diff --git a/inventory_item.go b/inventory_item.go index 36457b99..e2812d53 100644 --- a/inventory_item.go +++ b/inventory_item.go @@ -7,7 +7,7 @@ import ( "github.com/shopspring/decimal" ) -const inventoryItemsBasePath = "admin/inventory_items" +const inventoryItemsBasePath = "inventory_items" // InventoryItemService is an interface for interacting with the // inventory items endpoints of the Shopify API @@ -46,7 +46,7 @@ type InventoryItemsResource struct { // List inventory items func (s *InventoryItemServiceOp) List(options interface{}) ([]InventoryItem, error) { - path := fmt.Sprintf("%s.json", inventoryItemsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, inventoryItemsBasePath) resource := new(InventoryItemsResource) err := s.client.Get(path, resource, options) return resource.InventoryItems, err @@ -54,7 +54,7 @@ func (s *InventoryItemServiceOp) List(options interface{}) ([]InventoryItem, err // Get a inventory item func (s *InventoryItemServiceOp) Get(id int64, options interface{}) (*InventoryItem, error) { - path := fmt.Sprintf("%s/%d.json", inventoryItemsBasePath, id) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, inventoryItemsBasePath, id) resource := new(InventoryItemResource) err := s.client.Get(path, resource, options) return resource.InventoryItem, err @@ -62,7 +62,7 @@ func (s *InventoryItemServiceOp) Get(id int64, options interface{}) (*InventoryI // Update a inventory item func (s *InventoryItemServiceOp) Update(item InventoryItem) (*InventoryItem, error) { - path := fmt.Sprintf("%s/%d.json", inventoryItemsBasePath, item.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, inventoryItemsBasePath, item.ID) wrappedData := InventoryItemResource{InventoryItem: &item} resource := new(InventoryItemResource) err := s.client.Put(path, wrappedData, resource) diff --git a/inventory_item_test.go b/inventory_item_test.go index f1f50ffb..89ae984a 100644 --- a/inventory_item_test.go +++ b/inventory_item_test.go @@ -1,9 +1,10 @@ package goshopify import ( + "fmt" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func inventoryItemTests(t *testing.T, item *InventoryItem) { @@ -45,7 +46,7 @@ func TestInventoryItemsList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/inventory_items.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("inventory_items.json"))) items, err := client.InventoryItem.List(nil) @@ -65,7 +66,7 @@ func TestInventoryItemsListWithIDs(t *testing.T) { } httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/inventory_items.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("inventory_items.json")), ) @@ -86,7 +87,7 @@ func TestInventoryItemGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/inventory_items/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("inventory_item.json"))) item, err := client.InventoryItem.Get(1, nil) @@ -100,7 +101,7 @@ func TestInventoryItemUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/inventory_items/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/inventory_items/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("inventory_item.json"))) item := InventoryItem{ diff --git a/location.go b/location.go index faa68201..c014cb73 100644 --- a/location.go +++ b/location.go @@ -5,7 +5,7 @@ import ( "time" ) -const locationsBasePath = "admin/locations" +const locationsBasePath = "locations" // LocationService is an interface for interfacing with the location endpoints // of the Shopify API. @@ -81,21 +81,21 @@ type LocationServiceOp struct { } func (s *LocationServiceOp) List(options interface{}) ([]Location, error) { - path := fmt.Sprintf("%s.json", locationsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, locationsBasePath) resource := new(LocationsResource) err := s.client.Get(path, resource, options) return resource.Locations, err } func (s *LocationServiceOp) Get(ID int64, options interface{}) (*Location, error) { - path := fmt.Sprintf("%s/%d.json", locationsBasePath, ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, locationsBasePath, ID) resource := new(LocationResource) err := s.client.Get(path, resource, options) return resource.Location, err } func (s *LocationServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", locationsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, locationsBasePath) return s.client.Count(path, options) } diff --git a/location_test.go b/location_test.go index eb5fbd66..a9875da2 100644 --- a/location_test.go +++ b/location_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -12,7 +13,7 @@ func TestLocationServiceOp_List(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/locations.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("locations.json"))) products, err := client.Location.List(nil) @@ -50,7 +51,7 @@ func TestLocationServiceOp_Get(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/locations/4688969785.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations/4688969785.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("location.json"))) product, err := client.Location.Get(4688969785, nil) @@ -88,7 +89,7 @@ func TestLocationServiceOp_Count(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/locations/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/locations/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) cnt, err := client.Location.Count(nil) diff --git a/metafield_test.go b/metafield_test.go index dda15000..3a188571 100644 --- a/metafield_test.go +++ b/metafield_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func MetafieldTests(t *testing.T, metafield Metafield) { @@ -20,7 +21,7 @@ func TestMetafieldList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.Metafield.List(nil) @@ -38,13 +39,13 @@ func TestMetafieldCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -74,7 +75,7 @@ func TestMetafieldGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/metafields/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":1}}`)) metafield, err := client.Metafield.Get(1, nil) @@ -92,7 +93,7 @@ func TestMetafieldCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -114,7 +115,7 @@ func TestMetafieldUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/metafields/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -135,7 +136,7 @@ func TestMetafieldDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/metafields/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/metafields/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Metafield.Delete(1) diff --git a/order.go b/order.go index a2207d98..a5e12bdf 100644 --- a/order.go +++ b/order.go @@ -7,7 +7,7 @@ import ( "github.com/shopspring/decimal" ) -const ordersBasePath = "admin/orders" +const ordersBasePath = "orders" const ordersResourceName = "orders" // OrderService is an interface for interfacing with the orders endpoints of @@ -286,7 +286,7 @@ type RefundLineItem struct { // List orders func (s *OrderServiceOp) List(options interface{}) ([]Order, error) { - path := fmt.Sprintf("%s.json", ordersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, ordersBasePath) resource := new(OrdersResource) err := s.client.Get(path, resource, options) return resource.Orders, err @@ -294,13 +294,13 @@ func (s *OrderServiceOp) List(options interface{}) ([]Order, error) { // Count orders func (s *OrderServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", ordersBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, ordersBasePath) return s.client.Count(path, options) } // Get individual order func (s *OrderServiceOp) Get(orderID int64, options interface{}) (*Order, error) { - path := fmt.Sprintf("%s/%d.json", ordersBasePath, orderID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, ordersBasePath, orderID) resource := new(OrderResource) err := s.client.Get(path, resource, options) return resource.Order, err @@ -308,7 +308,7 @@ func (s *OrderServiceOp) Get(orderID int64, options interface{}) (*Order, error) // Create order func (s *OrderServiceOp) Create(order Order) (*Order, error) { - path := fmt.Sprintf("%s.json", ordersBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, ordersBasePath) wrappedData := OrderResource{Order: &order} resource := new(OrderResource) err := s.client.Post(path, wrappedData, resource) @@ -317,7 +317,7 @@ func (s *OrderServiceOp) Create(order Order) (*Order, error) { // Update order func (s *OrderServiceOp) Update(order Order) (*Order, error) { - path := fmt.Sprintf("%s/%d.json", ordersBasePath, order.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, ordersBasePath, order.ID) wrappedData := OrderResource{Order: &order} resource := new(OrderResource) err := s.client.Put(path, wrappedData, resource) diff --git a/order_test.go b/order_test.go index a8bea8ed..2ca3bdc3 100644 --- a/order_test.go +++ b/order_test.go @@ -1,12 +1,13 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" "github.com/shopspring/decimal" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func orderTests(t *testing.T, order Order) { @@ -68,7 +69,7 @@ func TestOrderList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("orders.json"))) orders, err := client.Order.List(nil) @@ -96,7 +97,7 @@ func TestOrderListOptions(t *testing.T) { } httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/orders.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/orders.json", globalApiPathPrefix), params, httpmock.NewBytesResponder(200, loadFixture("orders.json"))) @@ -124,7 +125,7 @@ func TestOrderGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123456.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123456.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("order.json"))) order, err := client.Order.Get(123456, nil) @@ -147,7 +148,7 @@ func TestOrderGetWithTransactions(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/123456.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/123456.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("order_with_transaction.json"))) options := struct { @@ -176,13 +177,13 @@ func TestOrderCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 7}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/orders/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -212,7 +213,7 @@ func TestOrderCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders.json", globalApiPathPrefix), httpmock.NewStringResponder(201, `{"order":{"id": 1}}`)) order := Order{ @@ -239,7 +240,7 @@ func TestOrderUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1.json", globalApiPathPrefix), httpmock.NewStringResponder(201, `{"order":{"id": 1}}`)) order := Order{ @@ -263,7 +264,7 @@ func TestOrderListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.Order.ListMetafields(1, nil) @@ -281,13 +282,13 @@ func TestOrderCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/orders/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -317,7 +318,7 @@ func TestOrderGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.Order.GetMetafield(1, 2, nil) @@ -335,7 +336,7 @@ func TestOrderCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -357,7 +358,7 @@ func TestOrderUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -380,7 +381,7 @@ func TestOrderDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/orders/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Order.DeleteMetafield(1, 2) @@ -393,7 +394,7 @@ func TestOrderListFulfillments(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/fulfillments.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"fulfillments": [{"id":1},{"id":2}]}`)) fulfillments, err := client.Order.ListFulfillments(1, nil) @@ -411,13 +412,13 @@ func TestOrderCountFulfillments(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/orders/1/fulfillments/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -447,7 +448,7 @@ func TestOrderGetFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"fulfillment": {"id":2}}`)) fulfillment, err := client.Order.GetFulfillment(1, 2, nil) @@ -465,7 +466,7 @@ func TestOrderCreateFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/fulfillments.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillment := Fulfillment{ @@ -490,7 +491,7 @@ func TestOrderUpdateFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/1022782888.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/1022782888.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) fulfillment := Fulfillment{ @@ -509,7 +510,7 @@ func TestOrderCompleteFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/2/complete.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/2/complete.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) returnedFulfillment, err := client.Order.CompleteFulfillment(1, 2) @@ -524,7 +525,7 @@ func TestOrderTransitionFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/2/open.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/2/open.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) returnedFulfillment, err := client.Order.TransitionFulfillment(1, 2) @@ -539,7 +540,7 @@ func TestOrderCancelFulfillment(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/fulfillments/2/cancel.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/fulfillments/2/cancel.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("fulfillment.json"))) returnedFulfillment, err := client.Order.CancelFulfillment(1, 2) diff --git a/page.go b/page.go index d4bd7bef..840ccad5 100644 --- a/page.go +++ b/page.go @@ -5,7 +5,7 @@ import ( "time" ) -const pagesBasePath = "admin/pages" +const pagesBasePath = "pages" const pagesResourceName = "pages" // PagesPageService is an interface for interacting with the pages @@ -57,7 +57,7 @@ type PagesResource struct { // List pages func (s *PageServiceOp) List(options interface{}) ([]Page, error) { - path := fmt.Sprintf("%s.json", pagesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, pagesBasePath) resource := new(PagesResource) err := s.client.Get(path, resource, options) return resource.Pages, err @@ -65,13 +65,13 @@ func (s *PageServiceOp) List(options interface{}) ([]Page, error) { // Count pages func (s *PageServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", pagesBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, pagesBasePath) return s.client.Count(path, options) } // Get individual page func (s *PageServiceOp) Get(pageID int64, options interface{}) (*Page, error) { - path := fmt.Sprintf("%s/%d.json", pagesBasePath, pageID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, pagesBasePath, pageID) resource := new(PageResource) err := s.client.Get(path, resource, options) return resource.Page, err @@ -79,7 +79,7 @@ func (s *PageServiceOp) Get(pageID int64, options interface{}) (*Page, error) { // Create a new page func (s *PageServiceOp) Create(page Page) (*Page, error) { - path := fmt.Sprintf("%s.json", pagesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, pagesBasePath) wrappedData := PageResource{Page: &page} resource := new(PageResource) err := s.client.Post(path, wrappedData, resource) @@ -88,7 +88,7 @@ func (s *PageServiceOp) Create(page Page) (*Page, error) { // Update an existing page func (s *PageServiceOp) Update(page Page) (*Page, error) { - path := fmt.Sprintf("%s/%d.json", pagesBasePath, page.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, pagesBasePath, page.ID) wrappedData := PageResource{Page: &page} resource := new(PageResource) err := s.client.Put(path, wrappedData, resource) @@ -97,7 +97,7 @@ func (s *PageServiceOp) Update(page Page) (*Page, error) { // Delete an existing page. func (s *PageServiceOp) Delete(pageID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", pagesBasePath, pageID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, pagesBasePath, pageID)) } // List metafields for a page diff --git a/page_test.go b/page_test.go index 5c17c28e..65481af9 100644 --- a/page_test.go +++ b/page_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func pageTests(t *testing.T, page Page) { @@ -20,7 +21,7 @@ func TestPageList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"pages": [{"id":1},{"id":2}]}`)) pages, err := client.Page.List(nil) @@ -38,13 +39,13 @@ func TestPageCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/pages/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -74,7 +75,7 @@ func TestPageGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"page": {"id":1}}`)) page, err := client.Page.Get(1, nil) @@ -92,7 +93,7 @@ func TestPageCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/pages.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("page.json"))) page := Page{ @@ -112,7 +113,7 @@ func TestPageUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/pages/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("page.json"))) page := Page{ @@ -131,7 +132,7 @@ func TestPageDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/pages/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Page.Delete(1) @@ -144,7 +145,7 @@ func TestPageListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.Page.ListMetafields(1, nil) @@ -162,13 +163,13 @@ func TestPageCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/pages/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -198,7 +199,7 @@ func TestPageGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/pages/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.Page.GetMetafield(1, 2, nil) @@ -216,7 +217,7 @@ func TestPageCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/pages/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -238,7 +239,7 @@ func TestPageUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/pages/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -261,7 +262,7 @@ func TestPageDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/pages/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/pages/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Page.DeleteMetafield(1, 2) diff --git a/product.go b/product.go index 30e0f4b1..9a187182 100644 --- a/product.go +++ b/product.go @@ -5,7 +5,7 @@ import ( "time" ) -const productsBasePath = "admin/products" +const productsBasePath = "products" const productsResourceName = "products" // ProductService is an interface for interfacing with the product endpoints @@ -74,7 +74,7 @@ type ProductsResource struct { // List products func (s *ProductServiceOp) List(options interface{}) ([]Product, error) { - path := fmt.Sprintf("%s.json", productsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, productsBasePath) resource := new(ProductsResource) err := s.client.Get(path, resource, options) return resource.Products, err @@ -82,13 +82,13 @@ func (s *ProductServiceOp) List(options interface{}) ([]Product, error) { // Count products func (s *ProductServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", productsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, productsBasePath) return s.client.Count(path, options) } // Get individual product func (s *ProductServiceOp) Get(productID int64, options interface{}) (*Product, error) { - path := fmt.Sprintf("%s/%d.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, productsBasePath, productID) resource := new(ProductResource) err := s.client.Get(path, resource, options) return resource.Product, err @@ -96,7 +96,7 @@ func (s *ProductServiceOp) Get(productID int64, options interface{}) (*Product, // Create a new product func (s *ProductServiceOp) Create(product Product) (*Product, error) { - path := fmt.Sprintf("%s.json", productsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, productsBasePath) wrappedData := ProductResource{Product: &product} resource := new(ProductResource) err := s.client.Post(path, wrappedData, resource) @@ -105,7 +105,7 @@ func (s *ProductServiceOp) Create(product Product) (*Product, error) { // Update an existing product func (s *ProductServiceOp) Update(product Product) (*Product, error) { - path := fmt.Sprintf("%s/%d.json", productsBasePath, product.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, productsBasePath, product.ID) wrappedData := ProductResource{Product: &product} resource := new(ProductResource) err := s.client.Put(path, wrappedData, resource) @@ -114,7 +114,7 @@ func (s *ProductServiceOp) Update(product Product) (*Product, error) { // Delete an existing product func (s *ProductServiceOp) Delete(productID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", productsBasePath, productID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, productsBasePath, productID)) } // List metafields for a product diff --git a/product_test.go b/product_test.go index b5219a9a..c9f08a4d 100644 --- a/product_test.go +++ b/product_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -20,7 +21,7 @@ func TestProductList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"products": [{"id":1},{"id":2}]}`)) products, err := client.Product.List(nil) @@ -41,7 +42,7 @@ func TestProductListFilterByIds(t *testing.T) { params := map[string]string{"ids": "1,2,3"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/products.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/products.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"products": [{"id":1},{"id":2},{"id":3}]}`)) @@ -62,13 +63,13 @@ func TestProductCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/products/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/products/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -98,7 +99,7 @@ func TestProductGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"product": {"id":1}}`)) product, err := client.Product.Get(1, nil) @@ -116,7 +117,7 @@ func TestProductCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/products.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/products.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("product.json"))) product := Product{ @@ -138,7 +139,7 @@ func TestProductUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/products/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("product.json"))) product := Product{ @@ -158,7 +159,7 @@ func TestProductDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/products/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Product.Delete(1) @@ -171,7 +172,7 @@ func TestProductListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.Product.ListMetafields(1, nil) @@ -189,13 +190,13 @@ func TestProductCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/products/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -225,7 +226,7 @@ func TestProductGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.Product.GetMetafield(1, 2, nil) @@ -243,7 +244,7 @@ func TestProductCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/products/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -265,7 +266,7 @@ func TestProductUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/products/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -288,7 +289,7 @@ func TestProductDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/products/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Product.DeleteMetafield(1, 2) diff --git a/recurringapplicationcharge.go b/recurringapplicationcharge.go index 2f3dce9d..7ba51587 100644 --- a/recurringapplicationcharge.go +++ b/recurringapplicationcharge.go @@ -8,7 +8,7 @@ import ( "github.com/shopspring/decimal" ) -const recurringApplicationChargesBasePath = "admin/recurring_application_charges" +const recurringApplicationChargesBasePath = "recurring_application_charges" // RecurringApplicationChargeService is an interface for interacting with the // RecurringApplicationCharge endpoints of the Shopify API. @@ -30,7 +30,7 @@ type RecurringApplicationChargeServiceOp struct { // RecurringApplicationCharge represents a Shopify RecurringApplicationCharge. type RecurringApplicationCharge struct { - APIClientID int64 `json:"api_client_id"` + APIClientID int64 `json:"api_client_id"` ActivatedOn *time.Time `json:"activated_on"` BalanceRemaining *decimal.Decimal `json:"balance_remaining"` BalanceUsed *decimal.Decimal `json:"balance_used"` @@ -128,7 +128,7 @@ type RecurringApplicationChargesResource struct { func (r *RecurringApplicationChargeServiceOp) Create(charge RecurringApplicationCharge) ( *RecurringApplicationCharge, error) { - path := fmt.Sprintf("%s.json", recurringApplicationChargesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, recurringApplicationChargesBasePath) wrappedData := RecurringApplicationChargeResource{Charge: &charge} resource := &RecurringApplicationChargeResource{} err := r.client.Post(path, wrappedData, resource) @@ -139,7 +139,7 @@ func (r *RecurringApplicationChargeServiceOp) Create(charge RecurringApplication func (r *RecurringApplicationChargeServiceOp) Get(chargeID int64, options interface{}) ( *RecurringApplicationCharge, error) { - path := fmt.Sprintf("%s/%d.json", recurringApplicationChargesBasePath, chargeID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID) resource := &RecurringApplicationChargeResource{} err := r.client.Get(path, resource, options) return resource.Charge, err @@ -149,7 +149,7 @@ func (r *RecurringApplicationChargeServiceOp) Get(chargeID int64, options interf func (r *RecurringApplicationChargeServiceOp) List(options interface{}) ( []RecurringApplicationCharge, error) { - path := fmt.Sprintf("%s.json", recurringApplicationChargesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, recurringApplicationChargesBasePath) resource := &RecurringApplicationChargesResource{} err := r.client.Get(path, resource, options) return resource.Charges, err @@ -159,7 +159,7 @@ func (r *RecurringApplicationChargeServiceOp) List(options interface{}) ( func (r *RecurringApplicationChargeServiceOp) Activate(charge RecurringApplicationCharge) ( *RecurringApplicationCharge, error) { - path := fmt.Sprintf("%s/%d/activate.json", recurringApplicationChargesBasePath, charge.ID) + path := fmt.Sprintf("%s/%s/%d/activate.json", globalApiPathPrefix, recurringApplicationChargesBasePath, charge.ID) wrappedData := RecurringApplicationChargeResource{Charge: &charge} resource := &RecurringApplicationChargeResource{} err := r.client.Post(path, wrappedData, resource) @@ -168,14 +168,14 @@ func (r *RecurringApplicationChargeServiceOp) Activate(charge RecurringApplicati // Delete deletes recurring application charge. func (r *RecurringApplicationChargeServiceOp) Delete(chargeID int64) error { - return r.client.Delete(fmt.Sprintf("%s/%d.json", recurringApplicationChargesBasePath, chargeID)) + return r.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID)) } // Update updates recurring application charge. func (r *RecurringApplicationChargeServiceOp) Update(chargeID, newCappedAmount int64) ( *RecurringApplicationCharge, error) { - path := fmt.Sprintf("%s/%d/customize.json?recurring_application_charge[capped_amount]=%d", + path := fmt.Sprintf("%s/%s/%d/customize.json?recurring_application_charge[capped_amount]=%d", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID, newCappedAmount) resource := &RecurringApplicationChargeResource{} err := r.client.Put(path, nil, resource) diff --git a/recurringapplicationcharge_test.go b/recurringapplicationcharge_test.go index b02cb5b4..f88b3c7c 100644 --- a/recurringapplicationcharge_test.go +++ b/recurringapplicationcharge_test.go @@ -42,8 +42,8 @@ func recurringApplicationChargeTests(t *testing.T, charge RecurringApplicationCh }, { "ConfirmationURL", - "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_c" + - "harge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68", + fmt.Sprintf("https://apple.myshopify.com/%s/charges/1029266948/confirm_recurring_application_c"+ + "harge?signature=BAhpBAReWT0%%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68", globalApiPathPrefix), charge.ConfirmationURL, }, } @@ -90,8 +90,8 @@ func recurringApplicationChargeTestsAllFieldsAffected(t *testing.T, }, { "ConfirmationURL", - "https://apple.myshopify.com/admin/charges/1029266948/confirm_recurring_application_c" + - "harge?signature=BAhpBAReWT0%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68", + fmt.Sprintf("https://apple.myshopify.com/%s/charges/1029266948/confirm_recurring_application_c"+ + "harge?signature=BAhpBAReWT0%%3D--b51a6db06a3792c4439783fcf0f2e89bf1c9df68", globalApiPathPrefix), charge.ConfirmationURL, }, } @@ -110,7 +110,7 @@ func TestRecurringApplicationChargeServiceOp_Create(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/recurring_application_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("reccuringapplicationcharge/reccuringapplicationcharge.json"), ), @@ -137,7 +137,7 @@ func TestRecurringApplicationChargeServiceOp_Get(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"recurring_application_charge": {"id":1}}`), ) @@ -158,7 +158,7 @@ func TestRecurringApplicationChargeServiceOp_GetAllFieldsAffected(t *testing.T) httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/1029266948.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/1029266948.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture( "reccuringapplicationcharge/reccuringapplicationcharge_all_fields_affected.json", @@ -189,7 +189,7 @@ func TestRecurringApplicationChargeServiceOp_GetAllFieldsBad(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/1029266948.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/1029266948.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture( @@ -212,7 +212,7 @@ func TestRecurringApplicationChargeServiceOp_List(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"recurring_application_charges": [{"id":1},{"id":2}]}`), ) @@ -233,7 +233,7 @@ func TestRecurringApplicationChargeServiceOp_Activate(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/activate.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/activate.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"recurring_application_charge":{"id":455696195,"status":"active"}}`, ), @@ -261,7 +261,7 @@ func TestRecurringApplicationChargeServiceOp_Delete(t *testing.T) { httpmock.RegisterResponder( "DELETE", - "https://fooshop.myshopify.com/admin/recurring_application_charges/1.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}"), ) @@ -276,7 +276,7 @@ func TestRecurringApplicationChargeServiceOp_Update(t *testing.T) { params := map[string]string{"recurring_application_charge[capped_amount]": "100"} httpmock.RegisterResponderWithQuery( "PUT", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/customize.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/customize.json", globalApiPathPrefix), params, httpmock.NewStringResponder( 200, `{"recurring_application_charge":{"id":455696195,"capped_amount":"100.00"}}`, diff --git a/redirect.go b/redirect.go index de051851..36698330 100644 --- a/redirect.go +++ b/redirect.go @@ -4,7 +4,7 @@ import ( "fmt" ) -const redirectsBasePath = "admin/redirects" +const redirectsBasePath = "redirects" // RedirectService is an interface for interacting with the redirects // endpoints of the Shopify API. @@ -43,7 +43,7 @@ type RedirectsResource struct { // List redirects func (s *RedirectServiceOp) List(options interface{}) ([]Redirect, error) { - path := fmt.Sprintf("%s.json", redirectsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, redirectsBasePath) resource := new(RedirectsResource) err := s.client.Get(path, resource, options) return resource.Redirects, err @@ -51,13 +51,13 @@ func (s *RedirectServiceOp) List(options interface{}) ([]Redirect, error) { // Count redirects func (s *RedirectServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", redirectsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, redirectsBasePath) return s.client.Count(path, options) } // Get individual redirect func (s *RedirectServiceOp) Get(redirectID int64, options interface{}) (*Redirect, error) { - path := fmt.Sprintf("%s/%d.json", redirectsBasePath, redirectID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, redirectsBasePath, redirectID) resource := new(RedirectResource) err := s.client.Get(path, resource, options) return resource.Redirect, err @@ -65,7 +65,7 @@ func (s *RedirectServiceOp) Get(redirectID int64, options interface{}) (*Redirec // Create a new redirect func (s *RedirectServiceOp) Create(redirect Redirect) (*Redirect, error) { - path := fmt.Sprintf("%s.json", redirectsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, redirectsBasePath) wrappedData := RedirectResource{Redirect: &redirect} resource := new(RedirectResource) err := s.client.Post(path, wrappedData, resource) @@ -74,7 +74,7 @@ func (s *RedirectServiceOp) Create(redirect Redirect) (*Redirect, error) { // Update an existing redirect func (s *RedirectServiceOp) Update(redirect Redirect) (*Redirect, error) { - path := fmt.Sprintf("%s/%d.json", redirectsBasePath, redirect.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, redirectsBasePath, redirect.ID) wrappedData := RedirectResource{Redirect: &redirect} resource := new(RedirectResource) err := s.client.Put(path, wrappedData, resource) @@ -83,5 +83,5 @@ func (s *RedirectServiceOp) Update(redirect Redirect) (*Redirect, error) { // Delete an existing redirect. func (s *RedirectServiceOp) Delete(redirectID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", redirectsBasePath, redirectID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, redirectsBasePath, redirectID)) } diff --git a/redirect_test.go b/redirect_test.go index 4fca3c5f..c1221c0e 100644 --- a/redirect_test.go +++ b/redirect_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func redirectTests(t *testing.T, redirect Redirect) { @@ -20,7 +21,7 @@ func TestRedirectList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/redirects.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"redirects": [{"id":1},{"id":2}]}`)) redirects, err := client.Redirect.List(nil) @@ -38,13 +39,13 @@ func TestRedirectCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/redirects/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/redirects/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -74,7 +75,7 @@ func TestRedirectGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/redirects/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"redirect": {"id":1}}`)) redirect, err := client.Redirect.Get(1, nil) @@ -92,7 +93,7 @@ func TestRedirectCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/redirects.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("redirect.json"))) redirect := Redirect{ @@ -112,7 +113,7 @@ func TestRedirectUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/redirects/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("redirect.json"))) redirect := Redirect{ @@ -131,7 +132,7 @@ func TestRedirectDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/redirects/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/redirects/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Redirect.Delete(1) diff --git a/scripttag.go b/scripttag.go index 71bd8a9b..81abb95b 100644 --- a/scripttag.go +++ b/scripttag.go @@ -5,7 +5,7 @@ import ( "time" ) -const scriptTagsBasePath = "admin/script_tags" +const scriptTagsBasePath = "script_tags" // ScriptTagService is an interface for interfacing with the ScriptTag endpoints // of the Shopify API. @@ -62,7 +62,7 @@ type ScriptTagResource struct { // List script tags func (s *ScriptTagServiceOp) List(options interface{}) ([]ScriptTag, error) { - path := fmt.Sprintf("%s.json", scriptTagsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, scriptTagsBasePath) resource := &ScriptTagsResource{} err := s.client.Get(path, resource, options) return resource.ScriptTags, err @@ -70,13 +70,13 @@ func (s *ScriptTagServiceOp) List(options interface{}) ([]ScriptTag, error) { // Count script tags func (s *ScriptTagServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", scriptTagsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, scriptTagsBasePath) return s.client.Count(path, options) } // Get individual script tag func (s *ScriptTagServiceOp) Get(tagID int64, options interface{}) (*ScriptTag, error) { - path := fmt.Sprintf("%s/%d.json", scriptTagsBasePath, tagID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, scriptTagsBasePath, tagID) resource := &ScriptTagResource{} err := s.client.Get(path, resource, options) return resource.ScriptTag, err @@ -84,7 +84,7 @@ func (s *ScriptTagServiceOp) Get(tagID int64, options interface{}) (*ScriptTag, // Create a new script tag func (s *ScriptTagServiceOp) Create(tag ScriptTag) (*ScriptTag, error) { - path := fmt.Sprintf("%s.json", scriptTagsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, scriptTagsBasePath) wrappedData := ScriptTagResource{ScriptTag: &tag} resource := &ScriptTagResource{} err := s.client.Post(path, wrappedData, resource) @@ -93,7 +93,7 @@ func (s *ScriptTagServiceOp) Create(tag ScriptTag) (*ScriptTag, error) { // Update an existing script tag func (s *ScriptTagServiceOp) Update(tag ScriptTag) (*ScriptTag, error) { - path := fmt.Sprintf("%s/%d.json", scriptTagsBasePath, tag.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, scriptTagsBasePath, tag.ID) wrappedData := ScriptTagResource{ScriptTag: &tag} resource := &ScriptTagResource{} err := s.client.Put(path, wrappedData, resource) @@ -102,5 +102,5 @@ func (s *ScriptTagServiceOp) Update(tag ScriptTag) (*ScriptTag, error) { // Delete an existing script tag func (s *ScriptTagServiceOp) Delete(tagID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", scriptTagsBasePath, tagID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, scriptTagsBasePath, tagID)) } diff --git a/scripttag_test.go b/scripttag_test.go index 16d9d324..2e84c592 100644 --- a/scripttag_test.go +++ b/scripttag_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" @@ -11,7 +12,7 @@ func TestScriptTagList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/script_tags.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"script_tags": [{"id": 1},{"id": 2}]}`)) scriptTags, err := client.ScriptTag.List(nil) @@ -29,7 +30,7 @@ func TestScriptTagCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/script_tags/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) cnt, err := client.ScriptTag.Count(nil) @@ -47,7 +48,7 @@ func TestScriptTagGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/script_tags/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"script_tag": {"id": 1}}`)) scriptTag, err := client.ScriptTag.Get(1, nil) @@ -72,7 +73,7 @@ func TestScriptTagCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/script_tags.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("script_tags.json"))) tag0 := ScriptTag{ @@ -92,7 +93,7 @@ func TestScriptTagUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/script_tags/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("script_tags.json"))) tag := ScriptTag{ @@ -111,7 +112,7 @@ func TestScriptTagDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/script_tags/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/script_tags/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) if err := client.ScriptTag.Delete(1); err != nil { diff --git a/shop.go b/shop.go index 36e40adc..d6a51f6f 100644 --- a/shop.go +++ b/shop.go @@ -1,6 +1,9 @@ package goshopify -import "time" +import ( + "fmt" + "time" +) // ShopService is an interface for interfacing with the shop endpoint of the // Shopify API. @@ -75,6 +78,6 @@ type ShopResource struct { // Get shop func (s *ShopServiceOp) Get(options interface{}) (*Shop, error) { resource := new(ShopResource) - err := s.client.Get("admin/shop.json", resource, options) + err := s.client.Get(fmt.Sprintf("%s/shop.json", globalApiPathPrefix), resource, options) return resource.Shop, err } diff --git a/shop_test.go b/shop_test.go index e963d791..e29e33dc 100644 --- a/shop_test.go +++ b/shop_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "testing" "time" @@ -11,7 +12,7 @@ func TestShopGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/shop.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/shop.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("shop.json"))) shop, err := client.Shop.Get(nil) diff --git a/smartcollection.go b/smartcollection.go index 99b88f81..bdb7a960 100644 --- a/smartcollection.go +++ b/smartcollection.go @@ -5,7 +5,7 @@ import ( "time" ) -const smartCollectionsBasePath = "admin/smart_collections" +const smartCollectionsBasePath = "smart_collections" const smartCollectionsResourceName = "collections" // SmartCollectionService is an interface for interacting with the smart @@ -65,7 +65,7 @@ type SmartCollectionsResource struct { // List smart collections func (s *SmartCollectionServiceOp) List(options interface{}) ([]SmartCollection, error) { - path := fmt.Sprintf("%s.json", smartCollectionsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, smartCollectionsBasePath) resource := new(SmartCollectionsResource) err := s.client.Get(path, resource, options) return resource.Collections, err @@ -73,13 +73,13 @@ func (s *SmartCollectionServiceOp) List(options interface{}) ([]SmartCollection, // Count smart collections func (s *SmartCollectionServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", smartCollectionsBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, smartCollectionsBasePath) return s.client.Count(path, options) } // Get individual smart collection func (s *SmartCollectionServiceOp) Get(collectionID int64, options interface{}) (*SmartCollection, error) { - path := fmt.Sprintf("%s/%d.json", smartCollectionsBasePath, collectionID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, smartCollectionsBasePath, collectionID) resource := new(SmartCollectionResource) err := s.client.Get(path, resource, options) return resource.Collection, err @@ -88,7 +88,7 @@ func (s *SmartCollectionServiceOp) Get(collectionID int64, options interface{}) // Create a new smart collection // See Image for the details of the Image creation for a collection. func (s *SmartCollectionServiceOp) Create(collection SmartCollection) (*SmartCollection, error) { - path := fmt.Sprintf("%s.json", smartCollectionsBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, smartCollectionsBasePath) wrappedData := SmartCollectionResource{Collection: &collection} resource := new(SmartCollectionResource) err := s.client.Post(path, wrappedData, resource) @@ -97,7 +97,7 @@ func (s *SmartCollectionServiceOp) Create(collection SmartCollection) (*SmartCol // Update an existing smart collection func (s *SmartCollectionServiceOp) Update(collection SmartCollection) (*SmartCollection, error) { - path := fmt.Sprintf("%s/%d.json", smartCollectionsBasePath, collection.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, smartCollectionsBasePath, collection.ID) wrappedData := SmartCollectionResource{Collection: &collection} resource := new(SmartCollectionResource) err := s.client.Put(path, wrappedData, resource) @@ -106,7 +106,7 @@ func (s *SmartCollectionServiceOp) Update(collection SmartCollection) (*SmartCol // Delete an existing smart collection. func (s *SmartCollectionServiceOp) Delete(collectionID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", smartCollectionsBasePath, collectionID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, smartCollectionsBasePath, collectionID)) } // List metafields for a smart collection diff --git a/smartcollection_test.go b/smartcollection_test.go index 524d23bc..a51f3c68 100644 --- a/smartcollection_test.go +++ b/smartcollection_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func smartCollectionTests(t *testing.T, collection SmartCollection) { @@ -37,7 +38,7 @@ func TestSmartCollectionList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/smart_collections.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"smart_collections": [{"id":1},{"id":2}]}`)) collections, err := client.SmartCollection.List(nil) @@ -55,13 +56,13 @@ func TestSmartCollectionCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/smart_collections/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 5}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/smart_collections/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -91,7 +92,7 @@ func TestSmartCollectionGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/smart_collections/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"smart_collection": {"id":1}}`)) collection, err := client.SmartCollection.Get(1, nil) @@ -109,7 +110,7 @@ func TestSmartCollectionCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/smart_collections.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("smartcollection.json"))) collection := SmartCollection{ @@ -128,7 +129,7 @@ func TestSmartCollectionUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/smart_collections/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("smartcollection.json"))) collection := SmartCollection{ @@ -148,7 +149,7 @@ func TestSmartCollectionDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/smart_collections/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/smart_collections/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.SmartCollection.Delete(1) @@ -161,7 +162,7 @@ func TestSmartCollectionListMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafields": [{"id":1},{"id":2}]}`)) metafields, err := client.SmartCollection.ListMetafields(1, nil) @@ -179,13 +180,13 @@ func TestSmartCollectionCountMetafields(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/collections/1/metafields/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -215,7 +216,7 @@ func TestSmartCollectionGetMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"metafield": {"id":2}}`)) metafield, err := client.SmartCollection.GetMetafield(1, 2, nil) @@ -233,7 +234,7 @@ func TestSmartCollectionCreateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/collections/1/metafields.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -255,7 +256,7 @@ func TestSmartCollectionUpdateMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("metafield.json"))) metafield := Metafield{ @@ -278,7 +279,7 @@ func TestSmartCollectionDeleteMetafield(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/collections/1/metafields/2.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/collections/1/metafields/2.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.SmartCollection.DeleteMetafield(1, 2) diff --git a/storefrontaccesstoken.go b/storefrontaccesstoken.go index dc21e4fb..9fb12d6f 100644 --- a/storefrontaccesstoken.go +++ b/storefrontaccesstoken.go @@ -5,7 +5,7 @@ import ( "time" ) -const storefrontAccessTokensBasePath = "admin/storefront_access_tokens" +const storefrontAccessTokensBasePath = "storefront_access_tokens" // StorefrontAccessTokenService is an interface for interfacing with the storefront access // token endpoints of the Shopify API. @@ -44,7 +44,7 @@ type StorefrontAccessTokensResource struct { // List storefront access tokens func (s *StorefrontAccessTokenServiceOp) List(options interface{}) ([]StorefrontAccessToken, error) { - path := fmt.Sprintf("%s.json", storefrontAccessTokensBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, storefrontAccessTokensBasePath) resource := new(StorefrontAccessTokensResource) err := s.client.Get(path, resource, options) return resource.StorefrontAccessTokens, err @@ -52,7 +52,7 @@ func (s *StorefrontAccessTokenServiceOp) List(options interface{}) ([]Storefront // Create a new storefront access token func (s *StorefrontAccessTokenServiceOp) Create(storefrontAccessToken StorefrontAccessToken) (*StorefrontAccessToken, error) { - path := fmt.Sprintf("%s.json", storefrontAccessTokensBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, storefrontAccessTokensBasePath) wrappedData := StorefrontAccessTokenResource{StorefrontAccessToken: &storefrontAccessToken} resource := new(StorefrontAccessTokenResource) err := s.client.Post(path, wrappedData, resource) @@ -61,5 +61,5 @@ func (s *StorefrontAccessTokenServiceOp) Create(storefrontAccessToken Storefront // Delete an existing storefront access token func (s *StorefrontAccessTokenServiceOp) Delete(ID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", storefrontAccessTokensBasePath, ID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, storefrontAccessTokensBasePath, ID)) } diff --git a/storefrontaccesstoken_test.go b/storefrontaccesstoken_test.go index b55180ac..d597dedc 100644 --- a/storefrontaccesstoken_test.go +++ b/storefrontaccesstoken_test.go @@ -1,10 +1,11 @@ package goshopify import ( + "fmt" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func storefrontAccessTokenTests(t *testing.T, StorefrontAccessToken StorefrontAccessToken) { @@ -38,7 +39,7 @@ func TestStorefrontAccessTokenList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/storefront_access_tokens.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("storefront_access_tokens.json"))) storefrontAccessTokens, err := client.StorefrontAccessToken.List(nil) @@ -57,7 +58,7 @@ func TestStorefrontAccessTokenCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/storefront_access_tokens.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("storefront_access_token.json"))) storefrontAccessToken := StorefrontAccessToken{ @@ -76,7 +77,7 @@ func TestStorefrontAccessTokenDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/storefront_access_tokens/755357713.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/storefront_access_tokens/755357713.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.StorefrontAccessToken.Delete(755357713) diff --git a/theme.go b/theme.go index 267aa6f5..4136be14 100644 --- a/theme.go +++ b/theme.go @@ -5,7 +5,7 @@ import ( "time" ) -const themesBasePath = "admin/themes" +const themesBasePath = "themes" // Options for theme list type ThemeListOptions struct { @@ -45,7 +45,7 @@ type ThemesResource struct { // List all themes func (s *ThemeServiceOp) List(options interface{}) ([]Theme, error) { - path := fmt.Sprintf("%s.json", themesBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, themesBasePath) resource := new(ThemesResource) err := s.client.Get(path, resource, options) return resource.Themes, err diff --git a/theme_test.go b/theme_test.go index afc761eb..003e5b93 100644 --- a/theme_test.go +++ b/theme_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" @@ -13,7 +14,7 @@ func TestThemeList(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/themes.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"themes": [{"id":1},{"id":2}]}`, @@ -23,7 +24,7 @@ func TestThemeList(t *testing.T) { params := map[string]string{"role": "main"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/themes.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/themes.json", globalApiPathPrefix), params, httpmock.NewStringResponder( 200, diff --git a/transaction.go b/transaction.go index 17eceda2..49cae765 100644 --- a/transaction.go +++ b/transaction.go @@ -30,7 +30,7 @@ type TransactionsResource struct { // List transactions func (s *TransactionServiceOp) List(orderID int64, options interface{}) ([]Transaction, error) { - path := fmt.Sprintf("%s/%d/transactions.json", ordersBasePath, orderID) + path := fmt.Sprintf("%s/%s/%d/transactions.json", globalApiPathPrefix, ordersBasePath, orderID) resource := new(TransactionsResource) err := s.client.Get(path, resource, options) return resource.Transactions, err @@ -38,13 +38,13 @@ func (s *TransactionServiceOp) List(orderID int64, options interface{}) ([]Trans // Count transactions func (s *TransactionServiceOp) Count(orderID int64, options interface{}) (int, error) { - path := fmt.Sprintf("%s/%d/transactions/count.json", ordersBasePath, orderID) + path := fmt.Sprintf("%s/%s/%d/transactions/count.json", globalApiPathPrefix, ordersBasePath, orderID) return s.client.Count(path, options) } // Get individual transaction func (s *TransactionServiceOp) Get(orderID int64, transactionID int64, options interface{}) (*Transaction, error) { - path := fmt.Sprintf("%s/%d/transactions/%d.json", ordersBasePath, orderID, transactionID) + path := fmt.Sprintf("%s/%s/%d/transactions/%d.json", globalApiPathPrefix, ordersBasePath, orderID, transactionID) resource := new(TransactionResource) err := s.client.Get(path, resource, options) return resource.Transaction, err @@ -52,7 +52,7 @@ func (s *TransactionServiceOp) Get(orderID int64, transactionID int64, options i // Create a new transaction func (s *TransactionServiceOp) Create(orderID int64, transaction Transaction) (*Transaction, error) { - path := fmt.Sprintf("%s/%d/transactions.json", ordersBasePath, orderID) + path := fmt.Sprintf("%s/%s/%d/transactions.json", globalApiPathPrefix, ordersBasePath, orderID) wrappedData := TransactionResource{Transaction: &transaction} resource := new(TransactionResource) err := s.client.Post(path, wrappedData, resource) diff --git a/transaction_test.go b/transaction_test.go index ebda45e2..5ab2e6e3 100644 --- a/transaction_test.go +++ b/transaction_test.go @@ -1,11 +1,12 @@ package goshopify import ( + "fmt" "testing" "time" "github.com/shopspring/decimal" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func TransactionTests(t *testing.T, transaction Transaction) { @@ -130,7 +131,7 @@ func TestTransactionList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/transactions.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/transactions.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("transactions.json"))) transactions, err := client.Transaction.List(1, nil) @@ -147,7 +148,7 @@ func TestTransactionCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/transactions/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/transactions/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 2}`)) cnt, err := client.Transaction.Count(1, nil) @@ -165,7 +166,7 @@ func TestTransactionGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/orders/1/transactions/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/transactions/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("transaction.json"))) transaction, err := client.Transaction.Get(1, 1, nil) @@ -180,7 +181,7 @@ func TestTransactionCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/orders/1/transactions.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/orders/1/transactions.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("transaction.json"))) amount := decimal.NewFromFloat(409.94) diff --git a/usagecharge.go b/usagecharge.go index 25142207..95489e24 100644 --- a/usagecharge.go +++ b/usagecharge.go @@ -73,7 +73,7 @@ type UsageChargesResource struct { func (r *UsageChargeServiceOp) Create(chargeID int64, usageCharge UsageCharge) ( *UsageCharge, error) { - path := fmt.Sprintf("%s/%d/%s.json", recurringApplicationChargesBasePath, chargeID, usageChargesPath) + path := fmt.Sprintf("%s/%s/%d/%s.json", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID, usageChargesPath) wrappedData := UsageChargeResource{Charge: &usageCharge} resource := &UsageChargeResource{} err := r.client.Post(path, wrappedData, resource) @@ -84,7 +84,7 @@ func (r *UsageChargeServiceOp) Create(chargeID int64, usageCharge UsageCharge) ( func (r *UsageChargeServiceOp) Get(chargeID int64, usageChargeID int64, options interface{}) ( *UsageCharge, error) { - path := fmt.Sprintf("%s/%d/%s/%d.json", recurringApplicationChargesBasePath, chargeID, usageChargesPath, usageChargeID) + path := fmt.Sprintf("%s/%s/%d/%s/%d.json", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID, usageChargesPath, usageChargeID) resource := &UsageChargeResource{} err := r.client.Get(path, resource, options) return resource.Charge, err @@ -94,7 +94,7 @@ func (r *UsageChargeServiceOp) Get(chargeID int64, usageChargeID int64, options func (r *UsageChargeServiceOp) List(chargeID int64, options interface{}) ( []UsageCharge, error) { - path := fmt.Sprintf("%s/%d/%s.json", recurringApplicationChargesBasePath, chargeID, usageChargesPath) + path := fmt.Sprintf("%s/%s/%d/%s.json", globalApiPathPrefix, recurringApplicationChargesBasePath, chargeID, usageChargesPath) resource := &UsageChargesResource{} err := r.client.Get(path, resource, options) return resource.Charges, err diff --git a/usagecharge_test.go b/usagecharge_test.go index 2b53b19f..e1268f2d 100644 --- a/usagecharge_test.go +++ b/usagecharge_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -39,7 +40,7 @@ func TestUsageChargeServiceOp_Create(t *testing.T) { httpmock.RegisterResponder( "POST", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/usage_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/usage_charges.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("usagecharge.json"), ), @@ -65,7 +66,7 @@ func TestUsageChargeServiceOp_Get(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/usage_charges/1034618210.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/usage_charges/1034618210.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("usagecharge.json"), ), @@ -85,7 +86,7 @@ func TestUsageChargeServiceOp_List(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/usage_charges.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/usage_charges.json", globalApiPathPrefix), httpmock.NewBytesResponder( 200, loadFixture("usagecharges.json"), ), @@ -111,7 +112,7 @@ func TestUsageChargeServiceOp_GetBadFields(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/usage_charges/1034618210.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/usage_charges/1034618210.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"usage_charge":{"id":"wrong_id_type"}}`, ), @@ -123,7 +124,7 @@ func TestUsageChargeServiceOp_GetBadFields(t *testing.T) { httpmock.RegisterResponder( "GET", - "https://fooshop.myshopify.com/admin/recurring_application_charges/455696195/usage_charges/1034618210.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/recurring_application_charges/455696195/usage_charges/1034618210.json", globalApiPathPrefix), httpmock.NewStringResponder( 200, `{"usage_charge":{"billing_on":"2018-14-01"}}`, ), diff --git a/util.go b/util.go index 6a624e9e..25463702 100644 --- a/util.go +++ b/util.go @@ -33,9 +33,9 @@ func ShopBaseUrl(name string) string { func MetafieldPathPrefix(resource string, resourceID int64) string { var prefix string if resource == "" { - prefix = fmt.Sprintf("admin/metafields") + prefix = fmt.Sprintf("%s/metafields", globalApiPathPrefix) } else { - prefix = fmt.Sprintf("admin/%s/%d/metafields", resource, resourceID) + prefix = fmt.Sprintf("%s/%s/%d/metafields", globalApiPathPrefix, resource, resourceID) } return prefix } @@ -44,9 +44,9 @@ func MetafieldPathPrefix(resource string, resourceID int64) string { func FulfillmentPathPrefix(resource string, resourceID int64) string { var prefix string if resource == "" { - prefix = fmt.Sprintf("admin/fulfillments") + prefix = fmt.Sprintf("%s/fulfillments", globalApiPathPrefix) } else { - prefix = fmt.Sprintf("admin/%s/%d/fulfillments", resource, resourceID) + prefix = fmt.Sprintf("%s/%s/%d/fulfillments", globalApiPathPrefix, resource, resourceID) } return prefix } diff --git a/util_test.go b/util_test.go index cc13d353..47a8251d 100644 --- a/util_test.go +++ b/util_test.go @@ -1,6 +1,9 @@ package goshopify -import "testing" +import ( + "fmt" + "testing" +) func TestShopFullName(t *testing.T) { cases := []struct { @@ -69,8 +72,8 @@ func TestMetafieldPathPrefix(t *testing.T) { resourceID int64 expected string }{ - {"", 0, "admin/metafields"}, - {"products", 123, "admin/products/123/metafields"}, + {"", 0, fmt.Sprintf("%s/metafields", globalApiPathPrefix)}, + {"products", 123, fmt.Sprintf("%s/products/123/metafields", globalApiPathPrefix)}, } for _, c := range cases { @@ -87,8 +90,8 @@ func TestFulfillmentPathPrefix(t *testing.T) { resourceID int64 expected string }{ - {"", 0, "admin/fulfillments"}, - {"orders", 123, "admin/orders/123/fulfillments"}, + {"", 0, fmt.Sprintf("%s/fulfillments", globalApiPathPrefix)}, + {"orders", 123, fmt.Sprintf("%s/orders/123/fulfillments", globalApiPathPrefix)}, } for _, c := range cases { diff --git a/variant.go b/variant.go index 2462cff2..cad40623 100644 --- a/variant.go +++ b/variant.go @@ -7,7 +7,7 @@ import ( "github.com/shopspring/decimal" ) -const variantsBasePath = "admin/variants" +const variantsBasePath = "variants" // VariantService is an interface for interacting with the variant endpoints // of the Shopify API. @@ -69,7 +69,7 @@ type VariantsResource struct { // List variants func (s *VariantServiceOp) List(productID int64, options interface{}) ([]Variant, error) { - path := fmt.Sprintf("%s/%d/variants.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/variants.json", globalApiPathPrefix, productsBasePath, productID) resource := new(VariantsResource) err := s.client.Get(path, resource, options) return resource.Variants, err @@ -77,13 +77,13 @@ func (s *VariantServiceOp) List(productID int64, options interface{}) ([]Variant // Count variants func (s *VariantServiceOp) Count(productID int64, options interface{}) (int, error) { - path := fmt.Sprintf("%s/%d/variants/count.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/variants/count.json", globalApiPathPrefix, productsBasePath, productID) return s.client.Count(path, options) } // Get individual variant func (s *VariantServiceOp) Get(variantID int64, options interface{}) (*Variant, error) { - path := fmt.Sprintf("%s/%d.json", variantsBasePath, variantID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, variantsBasePath, variantID) resource := new(VariantResource) err := s.client.Get(path, resource, options) return resource.Variant, err @@ -91,7 +91,7 @@ func (s *VariantServiceOp) Get(variantID int64, options interface{}) (*Variant, // Create a new variant func (s *VariantServiceOp) Create(productID int64, variant Variant) (*Variant, error) { - path := fmt.Sprintf("%s/%d/variants.json", productsBasePath, productID) + path := fmt.Sprintf("%s/%s/%d/variants.json", globalApiPathPrefix, productsBasePath, productID) wrappedData := VariantResource{Variant: &variant} resource := new(VariantResource) err := s.client.Post(path, wrappedData, resource) @@ -100,7 +100,7 @@ func (s *VariantServiceOp) Create(productID int64, variant Variant) (*Variant, e // Update existing variant func (s *VariantServiceOp) Update(variant Variant) (*Variant, error) { - path := fmt.Sprintf("%s/%d.json", variantsBasePath, variant.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, variantsBasePath, variant.ID) wrappedData := VariantResource{Variant: &variant} resource := new(VariantResource) err := s.client.Put(path, wrappedData, resource) @@ -109,5 +109,5 @@ func (s *VariantServiceOp) Update(variant Variant) (*Variant, error) { // Delete an existing product func (s *VariantServiceOp) Delete(productID int64, variantID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d/variants/%d.json", productsBasePath, productID, variantID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d/variants/%d.json", globalApiPathPrefix, productsBasePath, productID, variantID)) } diff --git a/variant_test.go b/variant_test.go index 61ac11d8..8609b78b 100644 --- a/variant_test.go +++ b/variant_test.go @@ -1,12 +1,13 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" "github.com/shopspring/decimal" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "gopkg.in/jarcoal/httpmock.v1" ) func variantTests(t *testing.T, variant Variant) { @@ -32,7 +33,7 @@ func TestVariantList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/variants.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/variants.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"variants": [{"id":1},{"id":2}]}`)) variants, err := client.Variant.List(1, nil) @@ -50,13 +51,13 @@ func TestVariantCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/products/1/variants/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/variants/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 3}`)) params := map[string]string{"created_at_min": "2016-01-01T00:00:00Z"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/products/1/variants/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/variants/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -86,7 +87,7 @@ func TestVariantGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/variants/1.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/variants/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"variant": {"id":1}}`)) variant, err := client.Variant.Get(1, nil) @@ -104,7 +105,7 @@ func TestVariantCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/products/1/variants.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/variants.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("variant.json"))) price := decimal.NewFromFloat(1) @@ -124,7 +125,7 @@ func TestVariantUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/variants/1.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/variants/1.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("variant.json"))) variant := Variant{ @@ -145,7 +146,7 @@ func TestVariantDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/products/1/variants/1.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/products/1/variants/1.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Variant.Delete(1, 1) diff --git a/webhook.go b/webhook.go index 40ab258e..7e04924f 100644 --- a/webhook.go +++ b/webhook.go @@ -5,7 +5,7 @@ import ( "time" ) -const webhooksBasePath = "admin/webhooks" +const webhooksBasePath = "webhooks" // WebhookService is an interface for interfacing with the webhook endpoints of // the Shopify API. @@ -55,7 +55,7 @@ type WebhooksResource struct { // List webhooks func (s *WebhookServiceOp) List(options interface{}) ([]Webhook, error) { - path := fmt.Sprintf("%s.json", webhooksBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, webhooksBasePath) resource := new(WebhooksResource) err := s.client.Get(path, resource, options) return resource.Webhooks, err @@ -63,13 +63,13 @@ func (s *WebhookServiceOp) List(options interface{}) ([]Webhook, error) { // Count webhooks func (s *WebhookServiceOp) Count(options interface{}) (int, error) { - path := fmt.Sprintf("%s/count.json", webhooksBasePath) + path := fmt.Sprintf("%s/%s/count.json", globalApiPathPrefix, webhooksBasePath) return s.client.Count(path, options) } // Get individual webhook func (s *WebhookServiceOp) Get(webhookdID int64, options interface{}) (*Webhook, error) { - path := fmt.Sprintf("%s/%d.json", webhooksBasePath, webhookdID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, webhooksBasePath, webhookdID) resource := new(WebhookResource) err := s.client.Get(path, resource, options) return resource.Webhook, err @@ -77,7 +77,7 @@ func (s *WebhookServiceOp) Get(webhookdID int64, options interface{}) (*Webhook, // Create a new webhook func (s *WebhookServiceOp) Create(webhook Webhook) (*Webhook, error) { - path := fmt.Sprintf("%s.json", webhooksBasePath) + path := fmt.Sprintf("%s/%s.json", globalApiPathPrefix, webhooksBasePath) wrappedData := WebhookResource{Webhook: &webhook} resource := new(WebhookResource) err := s.client.Post(path, wrappedData, resource) @@ -86,7 +86,7 @@ func (s *WebhookServiceOp) Create(webhook Webhook) (*Webhook, error) { // Update an existing webhook. func (s *WebhookServiceOp) Update(webhook Webhook) (*Webhook, error) { - path := fmt.Sprintf("%s/%d.json", webhooksBasePath, webhook.ID) + path := fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, webhooksBasePath, webhook.ID) wrappedData := WebhookResource{Webhook: &webhook} resource := new(WebhookResource) err := s.client.Put(path, wrappedData, resource) @@ -95,5 +95,5 @@ func (s *WebhookServiceOp) Update(webhook Webhook) (*Webhook, error) { // Delete an existing webhooks func (s *WebhookServiceOp) Delete(ID int64) error { - return s.client.Delete(fmt.Sprintf("%s/%d.json", webhooksBasePath, ID)) + return s.client.Delete(fmt.Sprintf("%s/%s/%d.json", globalApiPathPrefix, webhooksBasePath, ID)) } diff --git a/webhook_test.go b/webhook_test.go index f983446d..e4744480 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -1,6 +1,7 @@ package goshopify import ( + "fmt" "reflect" "testing" "time" @@ -40,7 +41,7 @@ func TestWebhookList(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("webhooks.json"))) webhooks, err := client.Webhook.List(nil) @@ -60,7 +61,7 @@ func TestWebhookGet(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/4759306.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks/4759306.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("webhook.json"))) webhook, err := client.Webhook.Get(4759306, nil) @@ -75,13 +76,13 @@ func TestWebhookCount(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("GET", "https://fooshop.myshopify.com/admin/webhooks/count.json", + httpmock.RegisterResponder("GET", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks/count.json", globalApiPathPrefix), httpmock.NewStringResponder(200, `{"count": 7}`)) params := map[string]string{"topic": "orders/paid"} httpmock.RegisterResponderWithQuery( "GET", - "https://fooshop.myshopify.com/admin/webhooks/count.json", + fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks/count.json", globalApiPathPrefix), params, httpmock.NewStringResponder(200, `{"count": 2}`)) @@ -111,7 +112,7 @@ func TestWebhookCreate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("POST", "https://fooshop.myshopify.com/admin/webhooks.json", + httpmock.RegisterResponder("POST", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("webhook.json"))) webhook := Webhook{ @@ -131,7 +132,7 @@ func TestWebhookUpdate(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("PUT", "https://fooshop.myshopify.com/admin/webhooks/4759306.json", + httpmock.RegisterResponder("PUT", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks/4759306.json", globalApiPathPrefix), httpmock.NewBytesResponder(200, loadFixture("webhook.json"))) webhook := Webhook{ @@ -152,7 +153,7 @@ func TestWebhookDelete(t *testing.T) { setup() defer teardown() - httpmock.RegisterResponder("DELETE", "https://fooshop.myshopify.com/admin/webhooks/4759306.json", + httpmock.RegisterResponder("DELETE", fmt.Sprintf("https://fooshop.myshopify.com/%s/webhooks/4759306.json", globalApiPathPrefix), httpmock.NewStringResponder(200, "{}")) err := client.Webhook.Delete(4759306)