-
Notifications
You must be signed in to change notification settings - Fork 9
/
event.go
73 lines (58 loc) · 1.59 KB
/
event.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package dwolla
import (
"context"
"fmt"
"net/url"
)
// EventService is the event service interface
//
// see: https://docsv2.dwolla.com/#events
type EventService interface {
List(context.Context, *url.Values) (*Events, error)
Retrieve(context.Context, string) (*Event, error)
}
// EventServiceOp is an implementation of the event service interface
type EventServiceOp struct {
client *Client
}
// EventTopic is an event topic
type EventTopic string
// Event is a dwolla event
type Event struct {
Resource
ID string `json:"id"`
Created string `json:"created"`
Topic EventTopic `json:"topic"`
ResourceID string `json:"resourceId"`
}
// Events is a collection of dwolla events
type Events struct {
Collection
client *Client
Embedded map[string][]Event `json:"_embedded"`
}
// List returns a collection of events
//
// see: https://docsv2.dwolla.com/#list-events
func (e *EventServiceOp) List(ctx context.Context, params *url.Values) (*Events, error) {
var events Events
if err := e.client.Get(ctx, "events", params, nil, &events); err != nil {
return nil, err
}
events.client = e.client
for i := range events.Embedded["events"] {
events.Embedded["events"][i].client = e.client
}
return &events, nil
}
// Retrieve retrieves the event matching the id
//
// see: https://docsv2.dwolla.com/#retrieve-an-event
func (e *EventServiceOp) Retrieve(ctx context.Context, id string) (*Event, error) {
var event Event
if err := e.client.Get(ctx, fmt.Sprintf("events/%s", id), nil, nil, &event); err != nil {
return nil, err
}
event.client = e.client
return &event, nil
}