Skip to content

Commit

Permalink
feat: add app uninstall functionality (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghodss authored Feb 26, 2024
1 parent 98d1349 commit 99f6b0a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
27 changes: 27 additions & 0 deletions api_permissions.go
Original file line number Diff line number Diff line change
@@ -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)
}
23 changes: 23 additions & 0 deletions api_permissions_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 2 additions & 0 deletions goshopify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 99f6b0a

Please sign in to comment.