Skip to content

Commit

Permalink
Add unstable as valid api version (bold-commerce#119)
Browse files Browse the repository at this point in the history
Co-authored-by: Craig Dykstra <[email protected]>
  • Loading branch information
Wryte and Craig Dykstra authored Sep 29, 2020
1 parent cd587cf commit a817a50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion goshopify.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (

const (
UserAgent = "goshopify/1.0.0"
// UnstableApiVersion Shopify API version for accessing unstable API features
UnstableApiVersion = "unstable"

// Shopify API version YYYY-MM - defaults to admin which uses the oldest stable version of the api
defaultApiPathPrefix = "admin"
Expand Down Expand Up @@ -87,7 +89,7 @@ type Client struct {
Customer CustomerService
CustomerAddress CustomerAddressService
Order OrderService
Fulfillment FulfillmentService
Fulfillment FulfillmentService
DraftOrder DraftOrderService
Shop ShopService
Webhook WebhookService
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Option func(c *Client)
func WithVersion(apiVersion string) Option {
return func(c *Client) {
pathPrefix := defaultApiPathPrefix
if len(apiVersion) > 0 && apiVersionRegex.MatchString(apiVersion) {
if len(apiVersion) > 0 && (apiVersionRegex.MatchString(apiVersion) || apiVersion == UnstableApiVersion) {
pathPrefix = fmt.Sprintf("admin/api/%s", apiVersion)
}
c.apiVersion = apiVersion
Expand Down
8 changes: 8 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ func TestWithLogger(t *testing.T) {
t.Errorf("WithLogger expected logs to match %v != %v", c.log, logger)
}
}

func TestWithUnstableVersion(t *testing.T) {
c := NewClient(app, "fooshop", "abcd", WithVersion(UnstableApiVersion))
expected := fmt.Sprintf("admin/api/%s", UnstableApiVersion)
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}

0 comments on commit a817a50

Please sign in to comment.