-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemberships.go
58 lines (46 loc) · 1.38 KB
/
memberships.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
package goqonto
import (
"context"
"net/http"
)
// membershipsBasePath Qonto API Memberships Endpoint
const membershipsBasePath = "v2/memberships"
// MembershipsService provides access to to the memberships in Qonto API
type MembershipsService service
// MembershipsOptions Qonto API Memberships query strings
// https://api-doc.qonto.eu/2.0/memberships/list-memberships
type MembershipsOptions struct {
CurrentPage int64 `json:"current_page,omitempty"`
PerPage int64 `json:"per_page,omitempty"`
}
// Membership struct
// https://api-doc.qonto.eu/2.0/memberships/list-memberships
type Membership struct {
ID string `json:"id"`
FistName string `json:"first_name"`
LastName string `json:"last_name"`
}
// membershipsRoot root key in the JSON response for memberships
type membershipsRoot struct {
Memberships []Membership `json:"memberships"`
}
// List all the memberships
func (s *MembershipsService) List(ctx context.Context, opt *MembershipsOptions) ([]Membership, *Response, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, membershipsBasePath, opt)
if err != nil {
return nil, nil, err
}
type respWithMeta struct {
membershipsRoot
metaRoot
}
root := new(respWithMeta)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
if m := &root.metaRoot; m != nil {
resp.Meta = &m.Meta
}
return root.Memberships, resp, nil
}