-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.go
45 lines (40 loc) · 1.06 KB
/
client.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
package harvest
import (
"fmt"
"time"
)
type ClientsResponse struct {
PagedResponse
Clients []*Client `json:"clients"`
}
type ClientStub struct {
ID int64 `json:"id"`
Name string `json:"name"`
}
type Client struct {
ID int64 `json:"id"`
Name string `json:"name"`
IsActive bool `json:"is_active"`
Address string `json:"address"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Currency string `json:"currency"`
}
func (a *API) GetClient(clientID int64, args Arguments) (client *Client, err error) {
c := Client{}
path := fmt.Sprintf("/clients/%v", clientID)
err = a.Get(path, args, &c)
return &c, err
}
func (a *API) GetClients(args Arguments) (clients []*Client, err error) {
clients = make([]*Client, 0)
clientsResponse := ClientsResponse{}
path := fmt.Sprintf("/clients")
err = a.GetPaginated(path, args, &clientsResponse, func() {
for _, c := range clientsResponse.Clients {
clients = append(clients, c)
}
clientsResponse.Clients = make([]*Client, 0)
})
return clients, err
}