Skip to content

Commit

Permalink
Backwards incompatible changes for 4.0 (#258)
Browse files Browse the repository at this point in the history
* make AuthorizeUrl() return an error

* NewClient now returns an error, MustNewClient can be used if a panic is acceptable

* Address #89 - SinceID as Zero and omitempty

* fix variable names

* int64 --> uint64

* README.md
  • Loading branch information
oliver006 authored Jan 31, 2024
1 parent 62dcbad commit d631571
Show file tree
Hide file tree
Showing 94 changed files with 1,264 additions and 1,234 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
THE SOFTWARE IS PROVIdED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ app := goshopify.App{
}

// Create a new API client
client := goshopify.NewClient(app, "shopname", "token")
client, err := goshopify.NewClient(app, "shopname", "token")

// Fetch the number of products.
numProducts, err := client.Product.Count(nil)
Expand All @@ -111,7 +111,7 @@ app := goshopify.App{
}

// Create a new API client (notice the token parameter is the empty string)
client := goshopify.NewClient(app, "shopname", "")
client, err := goshopify.NewClient(app, "shopname", "")

// Fetch the number of products.
numProducts, err := client.Product.Count(nil)
Expand All @@ -130,7 +130,7 @@ to understand the format and release schedules. You can use `WithVersion` to spe
of the API. If you do not use this option you will be defaulted to the oldest stable API.

```go
client := goshopify.NewClient(app, "shopname", "", goshopify.WithVersion("2019-04"))
client, err := goshopify.NewClient(app, "shopname", "", goshopify.WithVersion("2019-04"))
```

#### WithRetry
Expand All @@ -141,7 +141,7 @@ the client a `WithRetry` option exists where you can pass an `int` of how many t
before returning an error. `WithRetry` additionally supports retrying HTTP503 errors.

```go
client := goshopify.NewClient(app, "shopname", "", goshopify.WithRetry(3))
client, err := goshopify.NewClient(app, "shopname", "", goshopify.WithRetry(3))
```

#### Query options
Expand Down Expand Up @@ -187,7 +187,7 @@ For example, let's say you want to fetch webhooks. There's a helper function
```go
// Declare a model for the webhook
type Webhook struct {
ID int `json:"id"`
Id int `json:"id"`
Address string `json:"address"`
}

Expand All @@ -199,7 +199,7 @@ type WebhooksResource struct {
func FetchWebhooks() ([]Webhook, error) {
path := "admin/webhooks.json"
resource := new(WebhooksResource)
client := goshopify.NewClient(app, "shopname", "token")
client, _ := goshopify.NewClient(app, "shopname", "token")

// resource gets modified when calling Get
err := client.Get(path, resource, nil)
Expand Down
8 changes: 4 additions & 4 deletions abandoned_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type AbandonedCheckoutsResource struct {

// AbandonedCheckout represents a Shopify abandoned checkout
type AbandonedCheckout struct {
ID int64 `json:"id,omitempty"`
Id uint64 `json:"id,omitempty"`
Token string `json:"token,omitempty"`
CartToken string `json:"cart_token,omitempty"`
Email string `json:"email,omitempty"`
Expand All @@ -48,10 +48,10 @@ type AbandonedCheckout struct {
Currency string `json:"currency,omitempty"`
CompletedAt *time.Time `json:"completed_at,omitempty"`
ClosedAt *time.Time `json:"closed_at,omitempty"`
UserID int64 `json:"user_id,omitempty"`
UserId uint64 `json:"user_id,omitempty"`
SourceIdentifier string `json:"source_identifier,omitempty"`
SourceUrl string `json:"source_url,omitempty"`
DeviceID int64 `json:"device_id,omitempty"`
DeviceId uint64 `json:"device_id,omitempty"`
Phone string `json:"phone,omitempty"`
CustomerLocale string `json:"customer_locale,omitempty"`
Name string `json:"name,omitempty"`
Expand All @@ -72,7 +72,7 @@ type AbandonedCheckout struct {
ShippingAddress *Address `json:"shipping_address,omitempty"`
Customer *Customer `json:"customer,omitempty"`
SmsMarketingConsent *SmsMarketingConsent `json:"sms_marketing_consent,omitempty"`
AdminGraphqlApiID string `json:"admin_graphql_api_id,omitempty"`
AdminGraphqlApiId string `json:"admin_graphql_api_id,omitempty"`
DefaultAddress *CustomerAddress `json:"default_address,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion abandoned_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAbandonedCheckoutList(t *testing.T) {
t.Errorf("AbandonedCheckout.List returned error: %v", err)
}

expected := []AbandonedCheckout{{ID: 1}, {ID: 2}}
expected := []AbandonedCheckout{{Id: 1}, {Id: 2}}
if !reflect.DeepEqual(abandonedCheckouts, expected) {
t.Errorf("AbandonedCheckout.List returned %+v, expected %+v", abandonedCheckouts, expected)
}
Expand Down
12 changes: 6 additions & 6 deletions applicationcharge.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const applicationChargesBasePath = "application_charges"
// See https://help.shopify.com/api/reference/billing/applicationcharge
type ApplicationChargeService interface {
Create(context.Context, ApplicationCharge) (*ApplicationCharge, error)
Get(context.Context, int64, interface{}) (*ApplicationCharge, error)
Get(context.Context, uint64, interface{}) (*ApplicationCharge, error)
List(context.Context, interface{}) ([]ApplicationCharge, error)
Activate(context.Context, ApplicationCharge) (*ApplicationCharge, error)
}
Expand All @@ -25,9 +25,9 @@ type ApplicationChargeServiceOp struct {
}

type ApplicationCharge struct {
ID int64 `json:"id"`
Id uint64 `json:"id"`
Name string `json:"name"`
APIClientID int64 `json:"api_client_id"`
APIClientId uint64 `json:"api_client_id"`
Price *decimal.Decimal `json:"price"`
Status string `json:"status"`
ReturnURL string `json:"return_url"`
Expand Down Expand Up @@ -59,8 +59,8 @@ func (a ApplicationChargeServiceOp) Create(ctx context.Context, charge Applicati
}

// Get gets individual application charge.
func (a ApplicationChargeServiceOp) Get(ctx context.Context, chargeID int64, options interface{}) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s/%d.json", applicationChargesBasePath, chargeID)
func (a ApplicationChargeServiceOp) Get(ctx context.Context, chargeId uint64, options interface{}) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s/%d.json", applicationChargesBasePath, chargeId)
resource := &ApplicationChargeResource{}
return resource.Charge, a.client.Get(ctx, path, resource, options)
}
Expand All @@ -74,7 +74,7 @@ func (a ApplicationChargeServiceOp) List(ctx context.Context, options interface{

// Activate activates application charge.
func (a ApplicationChargeServiceOp) Activate(ctx context.Context, charge ApplicationCharge) (*ApplicationCharge, error) {
path := fmt.Sprintf("%s/%d/activate.json", applicationChargesBasePath, charge.ID)
path := fmt.Sprintf("%s/%d/activate.json", applicationChargesBasePath, charge.Id)
resource := &ApplicationChargeResource{}
return resource.Charge, a.client.Post(ctx, path, ApplicationChargeResource{Charge: &charge}, resource)
}
12 changes: 6 additions & 6 deletions applicationcharge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func applicationChargeTests(t *testing.T, charge ApplicationCharge) {
expected interface{}
actual interface{}
}{
{"ID", int64(1017262355), charge.ID},
{"Id", uint64(1017262355), charge.Id},
{"Name", "Super Duper Expensive action", charge.Name},
{"APIClientID", int64(755357713), charge.APIClientID},
{"APIClientId", uint64(755357713), charge.APIClientId},
{"Price", decimal.NewFromFloat(100.00).String(), charge.Price.String()},
{"Status", "pending", charge.Status},
{"ReturnURL", "http://super-duper.shopifyapps.com/", charge.ReturnURL},
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestApplicationChargeServiceOp_Get(t *testing.T) {
t.Errorf("ApplicationCharge.Get returned an error: %v", err)
}

expected := &ApplicationCharge{ID: 1}
expected := &ApplicationCharge{Id: 1}
if !reflect.DeepEqual(charge, expected) {
t.Errorf("ApplicationCharge.Get returned %+v, expected %+v", charge, expected)
}
Expand All @@ -108,7 +108,7 @@ func TestApplicationChargeServiceOp_List(t *testing.T) {
t.Errorf("ApplicationCharge.List returned an error: %v", err)
}

expected := []ApplicationCharge{{ID: 1}, {ID: 2}}
expected := []ApplicationCharge{{Id: 1}, {Id: 2}}
if !reflect.DeepEqual(charges, expected) {
t.Errorf("ApplicationCharge.List returned %+v, expected %+v", charges, expected)
}
Expand All @@ -128,7 +128,7 @@ func TestApplicationChargeServiceOp_Activate(t *testing.T) {
)

charge := ApplicationCharge{
ID: 455696195,
Id: 455696195,
Status: "accepted",
}

Expand All @@ -137,7 +137,7 @@ func TestApplicationChargeServiceOp_Activate(t *testing.T) {
t.Errorf("ApplicationCharge.Activate returned an error: %v", err)
}

expected := &ApplicationCharge{ID: 455696195, Status: "active"}
expected := &ApplicationCharge{Id: 455696195, Status: "active"}
if !reflect.DeepEqual(returnedCharge, expected) {
t.Errorf("ApplicationCharge.Activate returned %+v, expected %+v", charge, expected)
}
Expand Down
30 changes: 15 additions & 15 deletions asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const assetsBasePath = "themes"
// of the Shopify API.
// See: https://help.shopify.com/api/reference/asset
type AssetService interface {
List(context.Context, int64, interface{}) ([]Asset, error)
Get(context.Context, int64, string) (*Asset, error)
Update(context.Context, int64, Asset) (*Asset, error)
Delete(context.Context, int64, string) error
List(context.Context, uint64, interface{}) ([]Asset, error)
Get(context.Context, uint64, string) (*Asset, error)
Update(context.Context, uint64, Asset) (*Asset, error)
Delete(context.Context, uint64, string) error
}

// AssetServiceOp handles communication with the asset related methods of
Expand All @@ -33,7 +33,7 @@ type Asset struct {
Size int `json:"size,omitempty"`
SourceKey string `json:"source_key,omitempty"`
Src string `json:"src,omitempty"`
ThemeID int64 `json:"theme_id,omitempty"`
ThemeId uint64 `json:"theme_id,omitempty"`
Value string `json:"value,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Expand All @@ -51,40 +51,40 @@ type AssetsResource struct {

type assetGetOptions struct {
Key string `url:"asset[key]"`
ThemeID int64 `url:"theme_id"`
ThemeId uint64 `url:"theme_id"`
}

// List the metadata for all assets in the given theme
func (s *AssetServiceOp) List(ctx context.Context, themeID int64, options interface{}) ([]Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID)
func (s *AssetServiceOp) List(ctx context.Context, themeId uint64, options interface{}) ([]Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeId)
resource := new(AssetsResource)
err := s.client.Get(ctx, path, resource, options)
return resource.Assets, err
}

// Get an asset by key from the given theme
func (s *AssetServiceOp) Get(ctx context.Context, themeID int64, key string) (*Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID)
func (s *AssetServiceOp) Get(ctx context.Context, themeId uint64, key string) (*Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeId)
options := assetGetOptions{
Key: key,
ThemeID: themeID,
ThemeId: themeId,
}
resource := new(AssetResource)
err := s.client.Get(ctx, path, resource, options)
return resource.Asset, err
}

// Update an asset
func (s *AssetServiceOp) Update(ctx context.Context, themeID int64, asset Asset) (*Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeID)
func (s *AssetServiceOp) Update(ctx context.Context, themeId uint64, asset Asset) (*Asset, error) {
path := fmt.Sprintf("%s/%d/assets.json", assetsBasePath, themeId)
wrappedData := AssetResource{Asset: &asset}
resource := new(AssetResource)
err := s.client.Put(ctx, path, wrappedData, resource)
return resource.Asset, err
}

// Delete an asset
func (s *AssetServiceOp) Delete(ctx context.Context, themeID int64, key string) error {
path := fmt.Sprintf("%s/%d/assets.json?asset[key]=%s", assetsBasePath, themeID, key)
func (s *AssetServiceOp) Delete(ctx context.Context, themeId uint64, key string) error {
path := fmt.Sprintf("%s/%d/assets.json?asset[key]=%s", assetsBasePath, themeId, key)
return s.client.Delete(ctx, path)
}
24 changes: 12 additions & 12 deletions assigned_fulfillment_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ type AssignedFulfillmentOrderService interface {
}

type AssignedFulfillmentOrder struct {
Id int64 `json:"id,omitempty"`
AssignedLocationId int64 `json:"assigned_location_id,omitempty"`
Id uint64 `json:"id,omitempty"`
AssignedLocationId uint64 `json:"assigned_location_id,omitempty"`
Destination AssignedFulfillmentOrderDestination `json:"destination,omitempty"`
LineItems []AssignedFulfillmentOrderLineItem `json:"line_items,omitempty"`
OrderId int64 `json:"order_id,omitempty"`
OrderId uint64 `json:"order_id,omitempty"`
RequestStatus string `json:"request_status,omitempty"`
ShopId int64 `json:"shop_id,omitempty"`
ShopId uint64 `json:"shop_id,omitempty"`
Status string `json:"status,omitempty"`
}

// AssignedFulfillmentOrderDestination represents a destination for a AssignedFulfillmentOrder
type AssignedFulfillmentOrderDestination struct {
Id int64 `json:"id,omitempty"`
Id uint64 `json:"id,omitempty"`
Address1 string `json:"address1,omitempty"`
Address2 string `json:"address2,omitempty"`
City string `json:"city,omitempty"`
Expand All @@ -45,13 +45,13 @@ type AssignedFulfillmentOrderDestination struct {

// AssignedFulfillmentOrderLineItem represents a line item for a AssignedFulfillmentOrder
type AssignedFulfillmentOrderLineItem struct {
Id int64 `json:"id,omitempty"`
ShopId int64 `json:"shop_id,omitempty"`
FulfillmentOrderId int64 `json:"fulfillment_order_id,omitempty"`
LineItemId int64 `json:"line_item_id,omitempty"`
InventoryItemId int64 `json:"inventory_item_id,omitempty"`
Quantity int64 `json:"quantity,omitempty"`
FulfillableQuantity int64 `json:"fulfillable_quantity,omitempty"`
Id uint64 `json:"id,omitempty"`
ShopId uint64 `json:"shop_id,omitempty"`
FulfillmentOrderId uint64 `json:"fulfillment_order_id,omitempty"`
LineItemId uint64 `json:"line_item_id,omitempty"`
InventoryItemId uint64 `json:"inventory_item_id,omitempty"`
Quantity uint64 `json:"quantity,omitempty"`
FulfillableQuantity uint64 `json:"fulfillable_quantity,omitempty"`
}

// AssignedFulfillmentOrderResource represents the result from the assigned_fulfillment_order.json endpoint
Expand Down
6 changes: 3 additions & 3 deletions assigned_fulfillment_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
)

func AssignedFulfillmentOrderTests(t *testing.T, assignedFulfillmentOrder AssignedFulfillmentOrder) {
// Check that ID is assigned to the returned fulfillment
expectedInt := int64(255858046) // in assigned_fulfillment_orders.json fixture
// Check that Id is assigned to the returned fulfillment
expectedInt := uint64(255858046) // in assigned_fulfillment_orders.json fixture
if assignedFulfillmentOrder.Id != expectedInt {
t.Errorf("AssignedFulfillmentOrder.ID returned %+v, expected %+v", assignedFulfillmentOrder.Id, expectedInt)
t.Errorf("AssignedFulfillmentOrder.Id returned %+v, expected %+v", assignedFulfillmentOrder.Id, expectedInt)
}
}

Expand Down
14 changes: 7 additions & 7 deletions blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ const blogsBasePath = "blogs"
type BlogService interface {
List(context.Context, interface{}) ([]Blog, error)
Count(context.Context, interface{}) (int, error)
Get(context.Context, int64, interface{}) (*Blog, error)
Get(context.Context, uint64, interface{}) (*Blog, error)
Create(context.Context, Blog) (*Blog, error)
Update(context.Context, Blog) (*Blog, error)
Delete(context.Context, int64) error
Delete(context.Context, uint64) error
}

// BlogServiceOp handles communication with the blog related methods of
Expand All @@ -28,7 +28,7 @@ type BlogServiceOp struct {

// Blog represents a Shopify blog
type Blog struct {
ID int64 `json:"id"`
Id uint64 `json:"id"`
Title string `json:"title"`
Commentable string `json:"commentable"`
Feedburner string `json:"feedburner"`
Expand All @@ -39,7 +39,7 @@ type Blog struct {
TemplateSuffix string `json:"template_suffix"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
AdminGraphqlAPIID string `json:"admin_graphql_api_id,omitempty"`
AdminGraphqlApiId string `json:"admin_graphql_api_id,omitempty"`
}

// BlogsResource is the result from the blogs.json endpoint
Expand Down Expand Up @@ -67,7 +67,7 @@ func (s *BlogServiceOp) Count(ctx context.Context, options interface{}) (int, er
}

// Get single blog
func (s *BlogServiceOp) Get(ctx context.Context, blogId int64, options interface{}) (*Blog, error) {
func (s *BlogServiceOp) Get(ctx context.Context, blogId uint64, options interface{}) (*Blog, error) {
path := fmt.Sprintf("%s/%d.json", blogsBasePath, blogId)
resource := new(BlogResource)
err := s.client.Get(ctx, path, resource, options)
Expand All @@ -85,14 +85,14 @@ func (s *BlogServiceOp) Create(ctx context.Context, blog Blog) (*Blog, error) {

// Update an existing blog
func (s *BlogServiceOp) Update(ctx context.Context, blog Blog) (*Blog, error) {
path := fmt.Sprintf("%s/%d.json", blogsBasePath, blog.ID)
path := fmt.Sprintf("%s/%d.json", blogsBasePath, blog.Id)
wrappedData := BlogResource{Blog: &blog}
resource := new(BlogResource)
err := s.client.Put(ctx, path, wrappedData, resource)
return resource.Blog, err
}

// Delete an blog
func (s *BlogServiceOp) Delete(ctx context.Context, blogId int64) error {
func (s *BlogServiceOp) Delete(ctx context.Context, blogId uint64) error {
return s.client.Delete(ctx, fmt.Sprintf("%s/%d.json", blogsBasePath, blogId))
}
Loading

0 comments on commit d631571

Please sign in to comment.