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.
Completed
Pull Request — master (#33)
by Victor Hugo
01:59
created

mollie/profiles.go   A

Size/Duplication

Total Lines 198
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 29
eloc 122
dl 0
loc 198
ccs 70
cts 70
cp 1
crap 29
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*ProfilesService.Get 0 2 1
A mollie.*ProfilesService.DisablePaymentMethod 0 11 3
A mollie.*ProfilesService.List 0 18 5
A mollie.*ProfilesService.Update 0 14 4
A mollie.*ProfilesService.Delete 0 11 3
A mollie.*ProfilesService.Current 0 2 1
A mollie.*ProfilesService.Create 0 13 4
A mollie.*ProfilesService.EnablePaymentMethod 0 14 4
A mollie.*ProfilesService.get 0 14 4
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
// ProfileStatus determines whether the profile is able to receive live payments
13
type ProfileStatus string
14
15
// Possible profile statuses
16
const (
17
	StatusUnverified ProfileStatus = "unverified"
18
	StatusVerified   ProfileStatus = "verified"
19
	StatusBlocked    ProfileStatus = "blocked"
20
)
21
22
// Profile will usually reflect the trademark or brand name
23
// of the profile’s website or application.
24
type Profile struct {
25
	ID           string       `json:"id,omitempty"`
26
	CategoryCode CategoryCode `json:"categoryCode,omitempty"`
27
	CreatedAt    *time.Time   `json:"createdAt,omitempty"`
28
	Email        string       `json:"email,omitempty"`
29
	Mode         Mode         `json:"mode,omitempty"`
30
	Name         string       `json:"name,omitempty"`
31
	Phone        PhoneNumber  `json:"phone,omitempty"`
32
	Resource     string       `json:"resource,omitempty"`
33
	Review       struct {
34
		Status string `json:"status,omitempty"`
35
	} `json:"review,omitempty"`
36
	Status  ProfileStatus `json:"status,omitempty"`
37
	Website string        `json:"website,omitempty"`
38
	Links   ProfileLinks  `json:"_links,omitempty"`
39
}
40
41
// ProfileLinks contains URL's to relevant information related to
42
// a profile.
43
type ProfileLinks struct {
44
	Self               URL `json:"self,omitempty"`
45
	Chargebacks        URL `json:"chargebacks,omitempty"`
46
	Methods            URL `json:"methods,omitempty"`
47
	Refunds            URL `json:"refunds,omitempty"`
48
	CheckoutPreviewURL URL `json:"checkoutPreviewUrl,omitempty"`
49
	Documentation      URL `json:"documentation,omitempty"`
50
}
51
52
// ProfileListOptions are optional query string parameters for the list profiles request
53
type ProfileListOptions struct {
54
	From  string `url:"from,omitempty"`
55
	Limit uint   `url:"limit,omitempty"`
56
}
57
58
// ProfileList contains a list of profiles for your account.
59
type ProfileList struct {
60
	Count    int             `json:"count,omitempty"`
61
	Embedded profiles        `json:"_embedded,omitempty"`
62
	Links    PaginationLinks `json:"_links,omitempty"`
63
}
64
65
type profiles struct {
66
	Profiles []Profile `json:"profiles,omitempty"`
67
}
68
69
// ProfilesService operates over profile resource
70
type ProfilesService service
71
72
// List returns all the profiles for the authenticated account
73
func (ps *ProfilesService) List(options *ProfileListOptions) (pl *ProfileList, err error) {
74 1
	u := "v2/profiles"
75 1
	if options != nil {
76 1
		v, _ := query.Values(options)
77 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
78
	}
79 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
80 1
	if err != nil {
81 1
		return
82
	}
83 1
	res, err := ps.client.Do(req)
84 1
	if err != nil {
85 1
		return
86
	}
87 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
88 1
		return
89
	}
90 1
	return
91
}
92
93
// Get retrieves the a profile by ID.
94
func (ps *ProfilesService) Get(id string) (p *Profile, err error) {
95 1
	return ps.get(id)
96
}
97
98
// Current returns the profile belonging to the API key.
99
// This method only works when using API keys.
100
func (ps *ProfilesService) Current() (p *Profile, err error) {
101 1
	return ps.get("me")
102
}
103
104
func (ps *ProfilesService) get(id string) (p *Profile, err error) {
105 1
	u := fmt.Sprintf("v2/profiles/%s", id)
106 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
107 1
	if err != nil {
108 1
		return
109
	}
110 1
	res, err := ps.client.Do(req)
111 1
	if err != nil {
112 1
		return
113
	}
114 1
	if err = json.Unmarshal(res.content, &p); err != nil {
115 1
		return
116
	}
117 1
	return
118
}
119
120
// Create stores a new profile in your Mollie account.
121
func (ps *ProfilesService) Create(np *Profile) (p *Profile, err error) {
122 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, "v2/profiles", np)
123 1
	if err != nil {
124 1
		return
125
	}
126 1
	res, err := ps.client.Do(req)
127 1
	if err != nil {
128 1
		return
129
	}
130 1
	if err = json.Unmarshal(res.content, &p); err != nil {
131 1
		return
132
	}
133 1
	return
134
}
135
136
// Update allows you to perform mutations on a profile
137
func (ps *ProfilesService) Update(id string, up *Profile) (p *Profile, err error) {
138 1
	u := fmt.Sprintf("v2/profiles/%s", id)
139 1
	req, err := ps.client.NewAPIRequest(http.MethodPatch, u, up)
140 1
	if err != nil {
141 1
		return
142
	}
143 1
	res, err := ps.client.Do(req)
144 1
	if err != nil {
145 1
		return
146
	}
147 1
	if err = json.Unmarshal(res.content, &p); err != nil {
148 1
		return
149
	}
150 1
	return
151
}
152
153
// Delete  enables profile deletions, rendering the profile unavailable
154
// for further API calls and transactions.
155
func (ps *ProfilesService) Delete(id string) (err error) {
156 1
	u := fmt.Sprintf("v2/profiles/%s", id)
157 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
158 1
	if err != nil {
159 1
		return
160
	}
161 1
	_, err = ps.client.Do(req)
162 1
	if err != nil {
163 1
		return
164
	}
165 1
	return
166
}
167
168
// EnablePaymentMethod enables a payment method on a specific or authenticated profile.
169
// If you're using API tokens for authentication, pass "me" as id.
170
func (ps *ProfilesService) EnablePaymentMethod(id string, pm PaymentMethod) (pmi *PaymentMethodInfo, err error) {
171 1
	u := fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm)
172 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, u, nil)
173 1
	if err != nil {
174 1
		return
175
	}
176 1
	res, err := ps.client.Do(req)
177 1
	if err != nil {
178 1
		return
179
	}
180 1
	if err = json.Unmarshal(res.content, &pmi); err != nil {
181 1
		return
182
	}
183 1
	return
184
}
185
186
// DisablePaymentMethod disables a payment method on a specific or authenticated profile.
187
// If you're using API tokens for authentication, pass "me" as id.
188
func (ps *ProfilesService) DisablePaymentMethod(id string, pm PaymentMethod) (err error) {
189 1
	u := fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm)
190 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
191 1
	if err != nil {
192 1
		return
193
	}
194 1
	_, err = ps.client.Do(req)
195 1
	if err != nil {
196 1
		return
197
	}
198 1
	return
199
}
200