From 99f6b0a2cbc1d388e293dec2c6062cf04c26c24f Mon Sep 17 00:00:00 2001 From: Sam Ghods Date: Sun, 25 Feb 2024 23:53:04 -0800 Subject: [PATCH] feat: add app uninstall functionality (#267) --- api_permissions.go | 27 +++++++++++++++++++++++++++ api_permissions_test.go | 23 +++++++++++++++++++++++ goshopify.go | 2 ++ 3 files changed, 52 insertions(+) create mode 100644 api_permissions.go create mode 100644 api_permissions_test.go diff --git a/api_permissions.go b/api_permissions.go new file mode 100644 index 00000000..a4aee934 --- /dev/null +++ b/api_permissions.go @@ -0,0 +1,27 @@ +package goshopify + +import ( + "context" + "fmt" +) + +const apiPermissionsBasePath = "api_permissions" + +// ApiPermissionsService is an interface for interfacing with the API +// permissions endpoints of the Shopify API. +// See: https://help.shopify.com/api/reference/theme +type ApiPermissionsService interface { + Delete(context.Context) error +} + +// ApiPermissionsServiceOp handles communication with the theme related methods of +// the Shopify API. +type ApiPermissionsServiceOp struct { + client *Client +} + +// Uninstall an app. +func (s *ApiPermissionsServiceOp) Delete(ctx context.Context) error { + path := fmt.Sprintf("%s/current.json", apiPermissionsBasePath) + return s.client.Delete(ctx, path) +} diff --git a/api_permissions_test.go b/api_permissions_test.go new file mode 100644 index 00000000..130072bb --- /dev/null +++ b/api_permissions_test.go @@ -0,0 +1,23 @@ +package goshopify + +import ( + "context" + "fmt" + "testing" + + "github.com/jarcoal/httpmock" +) + +func TestApiPermissionsDelete(t *testing.T) { + setup() + defer teardown() + + httpmock.RegisterResponder("DELETE", + fmt.Sprintf("https://fooshop.myshopify.com/%s/%s/current.json", client.pathPrefix, apiPermissionsBasePath), + httpmock.NewStringResponder(200, "")) + + err := client.ApiPermissions.Delete(context.Background()) + if err != nil { + t.Errorf("Theme.Delete returned error: %v", err) + } +} diff --git a/goshopify.go b/goshopify.go index 00cf9b90..43453487 100644 --- a/goshopify.go +++ b/goshopify.go @@ -130,6 +130,7 @@ type Client struct { FulfillmentRequest FulfillmentRequestService PaymentsTransactions PaymentsTransactionsService OrderRisk OrderRiskService + ApiPermissions ApiPermissionsService } // A general response error that follows a similar layout to Shopify's response @@ -334,6 +335,7 @@ func NewClient(app App, shopName, token string, opts ...Option) (*Client, error) c.FulfillmentRequest = &FulfillmentRequestServiceOp{client: c} c.PaymentsTransactions = &PaymentsTransactionsServiceOp{client: c} c.OrderRisk = &OrderRiskServiceOp{client: c} + c.ApiPermissions = &ApiPermissionsServiceOp{client: c} // apply any options for _, opt := range opts {