GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#159)
by Victor Hugo
01:33
created

mollie/partners.go   A

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 10
eloc 63
dl 0
loc 110
c 0
b 0
f 0
ccs 26
cts 26
cp 1
crap 10
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*PartnerService.List 0 21 5
A mollie.*PartnerService.Get 0 21 5
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
	"time"
8
9
	"github.com/google/go-querystring/query"
10
)
11
12
// PartnerClient describes a partner client.
13
type PartnerClient struct {
14
	Resource              string             `json:"resource,omitempty"`
15
	ID                    string             `json:"id,omitempty"`
16
	OrganizationCreatedAt *time.Time         `json:"organizationCreatedAt,omitempty"`
17
	Commission            Commission         `json:"commission,omitempty"`
18
	Links                 PartnerClientLinks `json:"_links,omitempty"`
19
}
20
21
// PartnerClientList describes a list of partner clients.
22
type PartnerClientList struct {
23
	Count          int `json:"count,omitempty"`
24
	PartnerClients struct {
25
		Clients []*PartnerClient `json:"clients,omitempty"`
26
	} `json:"_embedded,omitempty"`
27
	Links PaginationLinks `json:"_links,omitempty"`
28
}
29
30
// PartnerClientLinks contains URL objects relevant to the client.
31
type PartnerClientLinks struct {
32
	Self          *URL `json:"self,omitempty"`
33
	Organization  *URL `json:"organization,omitempty"`
34
	Onboarding    *URL `json:"onboarding,omitempty"`
35
	Documentation *URL `json:"documentation,omitempty"`
36
}
37
38
// Commission describes a partner take from any
39
// operation on Mollie's API.
40
type Commission struct {
41
	Count       int     `json:"count,omitempty"`
42
	TotalAmount *Amount `json:"totalAmount,omitempty"`
43
}
44
45
// GetPartnerClientOptions contains valid query parameters for the get clients endpoint.
46
type GetPartnerClientOptions struct {
47
	Embed string `url:"embed,omitempty"`
48
}
49
50
// ListPartnerClientsOptions contains valid query parameters for the list clients endpoint.
51
type ListPartnerClientsOptions struct {
52
	From  int `url:"from,omitempty"`
53
	Limit int `url:"limit,omitempty"`
54
	Year  int `url:"year,omitempty"`
55
	Month int `url:"month,omitempty"`
56
}
57
58
// PartnerService operates over the partners API.
59
type PartnerService service
60
61
// Get retrieves all clients.
62
//
63
// See: https://docs.mollie.com/reference/v2/partners-api/list-clients
64
func (ps *PartnerService) List(opts *ListPartnerClientsOptions) (pc *PartnerClientList, err error) {
65 1
	u := "v2/clients"
66 1
	if opts != nil {
67 1
		v, _ := query.Values(opts)
68 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
69
	}
70
71 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
72 1
	if err != nil {
73 1
		return
74
	}
75
76 1
	res, err := ps.client.Do(req)
77 1
	if err != nil {
78 1
		return
79
	}
80
81 1
	if err = json.Unmarshal(res.content, &pc); err != nil {
82 1
		return
83
	}
84 1
	return
85
}
86
87
// Get retrieves a single client by its ID.
88
//
89
// See: https://docs.mollie.com/reference/v2/partners-api/get-client
90
func (ps *PartnerService) Get(id string, opts *GetPartnerClientOptions) (pc *PartnerClient, err error) {
91 1
	u := fmt.Sprintf("v2/clients/%s", id)
92 1
	if opts != nil {
93 1
		v, _ := query.Values(opts)
94 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
95
	}
96
97 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
98 1
	if err != nil {
99 1
		return
100
	}
101
102 1
	res, err := ps.client.Do(req)
103 1
	if err != nil {
104 1
		return
105
	}
106
107 1
	if err = json.Unmarshal(res.content, &pc); err != nil {
108 1
		return
109
	}
110 1
	return
111
}
112