forked from Invoiced/invoiced-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook_attempt.go
59 lines (41 loc) · 1.25 KB
/
webhook_attempt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package invdapi
import (
"github.com/gabrielsoaressantos/invoiced-go/invdendpoint"
"strconv"
)
type WebhookAttempt struct {
*Connection
*invdendpoint.WebhookAttempt
}
type WebhookAttempts []*WebhookAttempt
func (c *Connection) NewWebhookAttempt() *WebhookAttempt {
webhookAttempt := new(invdendpoint.WebhookAttempt)
return &WebhookAttempt{c, webhookAttempt}
}
func (c *WebhookAttempt) ListAll(filter *invdendpoint.Filter, sort *invdendpoint.Sort) (WebhookAttempts, error) {
endpoint := invdendpoint.WebhookEndpoint
endpoint = addFilterAndSort(endpoint, filter, sort)
webhookAttempts := make(WebhookAttempts, 0)
NEXT:
tmpWebhookAttempts := make(WebhookAttempts, 0)
endpoint, apiErr := c.retrieveDataFromAPI(endpoint, &tmpWebhookAttempts)
if apiErr != nil {
return nil, apiErr
}
webhookAttempts = append(webhookAttempts, tmpWebhookAttempts...)
if endpoint != "" {
goto NEXT
}
for _, webhookAttempt := range webhookAttempts {
webhookAttempt.Connection = c.Connection
}
return webhookAttempts, nil
}
func (c *WebhookAttempt) ReAttempt(webhookId int64) error {
endpoint := invdendpoint.WebhookEndpoint + "/" + strconv.FormatInt(webhookId, 10) + "/retries"
err := c.create(endpoint, nil, nil)
if err != nil {
return err
}
return nil
}