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 (#33)
by Victor Hugo
01:21
created

mollie.*ProfilesService.Current   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
type profileListLinks struct {
70
	Self          *URL `json:"self,omitempty"`
71
	Previous      *URL `json:"previous,omitempty"`
72
	Next          *URL `json:"next,omitempty"`
73
	Documentation *URL `json:"documentation,omitempty"`
74
}
75
76
// ProfilesService operates over profile resource
77
type ProfilesService service
78
79
// List returns all the profiles for the authenticated account
80
func (ps *ProfilesService) List(options *ProfileListOptions) (pl *ProfileList, err error) {
81 1
	u := "v2/profiles"
82 1
	if options != nil {
83 1
		v, _ := query.Values(options)
84 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
85
	}
86 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
87 1
	if err != nil {
88 1
		return
89
	}
90 1
	res, err := ps.client.Do(req)
91 1
	if err != nil {
92 1
		return
93
	}
94 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
95 1
		return
96
	}
97 1
	return
98
}
99
100
// Get retrieves the a profile by ID.
101
func (ps *ProfilesService) Get(id string) (p *Profile, err error) {
102 1
	return ps.get(id)
103
}
104
105
// Current returns the profile belonging to the API key.
106
// This method only works when using API keys.
107
func (ps *ProfilesService) Current() (p *Profile, err error) {
108 1
	return ps.get("me")
109
}
110
111
func (ps *ProfilesService) get(id string) (p *Profile, err error) {
112 1
	u := fmt.Sprintf("v2/profiles/%s", id)
113 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
114 1
	if err != nil {
115 1
		return
116
	}
117 1
	res, err := ps.client.Do(req)
118 1
	if err != nil {
119 1
		return
120
	}
121 1
	if err = json.Unmarshal(res.content, &p); err != nil {
122 1
		return
123
	}
124 1
	return
125
}
126
127
// Create stores a new profile in your Mollie account.
128
func (ps *ProfilesService) Create(np *Profile) (p *Profile, err error) {
129 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, "v2/profiles", np)
130 1
	if err != nil {
131 1
		return
132
	}
133 1
	res, err := ps.client.Do(req)
134 1
	if err != nil {
135 1
		return
136
	}
137 1
	if err = json.Unmarshal(res.content, &p); err != nil {
138 1
		return
139
	}
140 1
	return
141
}
142
143
// Update allows you to perform mutations on a profile
144
func (ps *ProfilesService) Update(id string, up *Profile) (p *Profile, err error) {
145 1
	u := fmt.Sprintf("v2/profiles/%s", id)
146 1
	req, err := ps.client.NewAPIRequest(http.MethodPatch, u, up)
147 1
	if err != nil {
148 1
		return
149
	}
150 1
	res, err := ps.client.Do(req)
151 1
	if err != nil {
152 1
		return
153
	}
154 1
	if err = json.Unmarshal(res.content, &p); err != nil {
155 1
		return
156
	}
157 1
	return
158
}
159
160
// Delete  enables profile deletions, rendering the profile unavailable
161
// for further API calls and transactions.
162
func (ps *ProfilesService) Delete(id string) (err error) {
163 1
	u := fmt.Sprintf("v2/profiles/%s", id)
164 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
165 1
	if err != nil {
166 1
		return
167
	}
168 1
	_, err = ps.client.Do(req)
169 1
	if err != nil {
170 1
		return
171
	}
172 1
	return
173
}
174
175
// EnablePaymentMethod enables a payment method on a specific or authenticated profile.
176
// If you're using API tokens for authentication, pass "me" as id.
177
func (ps *ProfilesService) EnablePaymentMethod(id string, pm PaymentMethod) (pmi *PaymentMethodInfo, err error) {
178 1
	u := fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm)
179 1
	req, err := ps.client.NewAPIRequest(http.MethodPost, u, nil)
180 1
	if err != nil {
181 1
		return
182
	}
183 1
	res, err := ps.client.Do(req)
184 1
	if err != nil {
185 1
		return
186
	}
187 1
	if err = json.Unmarshal(res.content, &pmi); err != nil {
188 1
		return
189
	}
190 1
	return
191
}
192
193
// DisablePaymentMethod disables a payment method on a specific or authenticated profile.
194
// If you're using API tokens for authentication, pass "me" as id.
195
func (ps *ProfilesService) DisablePaymentMethod(id string, pm PaymentMethod) (err error) {
196 1
	u := fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm)
197 1
	req, err := ps.client.NewAPIRequest(http.MethodDelete, u, nil)
198 1
	if err != nil {
199 1
		return
200
	}
201 1
	_, err = ps.client.Do(req)
202 1
	if err != nil {
203 1
		return
204
	}
205 1
	return
206
}
207