-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c04c290
commit 6036856
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package apiclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"sort" | ||
|
||
"github.com/otto8-ai/otto8/apiclient/types" | ||
) | ||
|
||
func (c *Client) ListWebhooks(ctx context.Context) (result types.WebhookList, _ error) { | ||
defer func() { | ||
sort.Slice(result.Items, func(i, j int) bool { | ||
return result.Items[i].Metadata.Created.Time.Before(result.Items[j].Metadata.Created.Time) | ||
}) | ||
}() | ||
|
||
_, resp, err := c.doRequest(ctx, http.MethodGet, "/webhooks", nil) | ||
if err != nil { | ||
return | ||
} | ||
defer resp.Body.Close() | ||
|
||
_, err = toObject(resp, &result) | ||
if err != nil { | ||
return result, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (c *Client) DeleteWebhook(ctx context.Context, id string) error { | ||
_, resp, err := c.doRequest(ctx, http.MethodDelete, fmt.Sprintf("/webhooks/"+id), nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
return nil | ||
} |