/
location.go
66 lines (51 loc) · 1.32 KB
/
location.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
package flow
import (
"context"
"fmt"
"net/http"
)
type LocationService interface {
List(ctx context.Context, options PaginationOptions) ([]*Location, *Response, error)
Get(ctx context.Context, id Id) (*Location, *Response, error)
}
type Location struct {
Id Id `json:"id"`
Name string `json:"name"`
Key string `json:"key"`
City string `json:"city"`
}
func (l *Location) String() string {
return l.Name
}
type locationService struct {
client *Client
}
func (s *locationService) List(ctx context.Context, options PaginationOptions) ([]*Location, *Response, error) {
path, err := addOptions("/v3/entities/locations", options)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil, FlagNoAuthentication)
if err != nil {
return nil, nil, err
}
var val []*Location
res, err := s.client.Do(req, &val)
if err != nil {
return nil, nil, err
}
return val, res, nil
}
func (s *locationService) Get(ctx context.Context, id Id) (*Location, *Response, error) {
path := fmt.Sprintf("/v3/entities/locations/%d", id)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil, FlagNoAuthentication)
if err != nil {
return nil, nil, err
}
val := &Location{}
res, err := s.client.Do(req, val)
if err != nil {
return nil, nil, err
}
return val, res, nil
}