From e83fd911e08b9387f3fab2a4048b90e1e6166923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Fr=C3=B6ssman?= Date: Sun, 3 Jan 2021 21:20:12 +0100 Subject: [PATCH] add GetWebhookEventTypes --- integration_test.go | 14 ++++++++++++++ types.go | 5 +++++ webhooks.go | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/integration_test.go b/integration_test.go index 442c241..f977851 100644 --- a/integration_test.go +++ b/integration_test.go @@ -401,3 +401,17 @@ func TestSubscription(t *testing.T) { assert.NotEqual(t, "", subDetails.ID) } + +func TestGetWebhookEventTypes(t *testing.T) { + c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) + c.GetAccessToken(context.Background()) + + r, err := c.GetWebhookEventTypes(context.Background()) + assert.Equal(t, nil, err) + assert.GreaterOrEqual(t, len(r.EventTypes), 1) + for _, v := range r.EventTypes { + assert.GreaterOrEqual(t, len(v.Name), 1) + assert.GreaterOrEqual(t, len(v.Description), 1) + assert.GreaterOrEqual(t, len(v.Status), 1) + } +} diff --git a/types.go b/types.go index c42a3af..1279f2b 100644 --- a/types.go +++ b/types.go @@ -1027,6 +1027,10 @@ type ( VerificationStatus string `json:"verification_status,omitempty"` } + WebhookEventTypesResponse struct { + EventTypes []WebhookEventType `json:"event_types"` + } + // Webhook strunct Webhook struct { ID string `json:"id"` @@ -1052,6 +1056,7 @@ type ( WebhookEventType struct { Name string `json:"name"` Description string `json:"description"` + Status string `json:"status,omitempty"` } // CreateWebhookRequest struct diff --git a/webhooks.go b/webhooks.go index ff2a3bf..39d0dba 100644 --- a/webhooks.go +++ b/webhooks.go @@ -123,3 +123,19 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque return response, nil } + +// GetWebhooksEventTypes - Lists all webhook event types. +// Endpoint: GET /v1/notifications/webhooks-event-types +func (c *Client) GetWebhookEventTypes(ctx context.Context) (*WebhookEventTypesResponse, error) { + req, err := c.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s%s", c.APIBase, "/v1/notifications/webhooks-event-types"), nil) + q := req.URL.Query() + + req.URL.RawQuery = q.Encode() + resp := &WebhookEventTypesResponse{} + if err != nil { + return nil, err + } + + err = c.SendWithAuth(req, resp) + return resp, err +}