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

mollie.*PermissionsService.Get   A

Complexity

Conditions 4

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.432

Importance

Changes 0
Metric Value
cc 4
eloc 11
dl 0
loc 14
ccs 7
cts 10
cp 0.7
crap 4.432
rs 9.85
c 0
b 0
f 0
nop 1
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
)
8
9
// PermissionGrant defines supported permissions.
10
type PermissionGrant string
11
12
// Available permission grants.
13
const (
14
	PaymentsRead       PermissionGrant = "payments.read"
15
	PaymentsWrite      PermissionGrant = "payments.write"
16
	RefundsRead        PermissionGrant = "refunds.read"
17
	RefundsWrite       PermissionGrant = "refunds.write"
18
	CustomersRead      PermissionGrant = "customers.read"
19
	CustomersWrite     PermissionGrant = "customers.write"
20
	MandatesRead       PermissionGrant = "mandates.read"
21
	MandatesWrite      PermissionGrant = "mandates.write"
22
	SubscriptionsRead  PermissionGrant = "subscriptions.read"
23
	SubscriptionsWrite PermissionGrant = "subscriptions.write"
24
	ProfilesRead       PermissionGrant = "profiles.read"
25
	ProfilesWrite      PermissionGrant = "profiles.write"
26
	InvoicesRead       PermissionGrant = "invoices.read"
27
	OrdersRead         PermissionGrant = "orders.read"
28
	OrdersWrite        PermissionGrant = "orders.write"
29
	ShipmentsRead      PermissionGrant = "shipments.read"
30
	ShipmentsWrite     PermissionGrant = "shipments.write"
31
	OrganizationsRead  PermissionGrant = "organizations.read"
32
	OrganizationsWrite PermissionGrant = "organizations.write"
33
	OnboardingRead     PermissionGrant = "onbording.read"
34
	OnboardingWrite    PermissionGrant = "onbording.write"
35
)
36
37
// Permission represents an action that
38
// can be performed by any API actor.
39
type Permission struct {
40
	Resource    string          `json:"resource,omitempty"`
41
	ID          PermissionGrant `json:"id,omitempty"`
42
	Description string          `json:"description,omitempty"`
43
	Granted     bool            `json:"granted,omitempty"`
44
	Links       PermissionLinks `json:"_links,omitempty"`
45
}
46
47
// PermissionLinks contains URL objects that make
48
// reference to an http addres related to permissions.
49
type PermissionLinks struct {
50
	Self          *URL `json:"self,omitempty"`
51
	Documentation *URL `json:"documentation,omitempty"`
52
}
53
54
// PermissionsList lists all the permissions given to an
55
// API actor.
56
type PermissionsList struct {
57
	Count    int `json:"count,omitempty"`
58
	Embedded struct {
59
		Permissions []*Permission `json:"permissions,omitempty"`
60
	} `json:"_embedded,omitempty"`
61
	Links PermissionLinks `json:"_links,omitempty"`
62
}
63
64
// PermissionsService operates over permission resources.
65
type PermissionsService service
66
67
// Get returns a permission by its id.
68
//
69
// See: https://docs.mollie.com/reference/v2/permissions-api/get-permission
70
func (ps *PermissionsService) Get(id string) (p *Permission, err error) {
71 1
	u := fmt.Sprintf("v2/permissions/%s", id)
72 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil)
73 1
	if err != nil {
74
		return
75
	}
76 1
	res, err := ps.client.Do(req)
77 1
	if err != nil {
78
		return
79
	}
80 1
	if err = json.Unmarshal(res.content, &p); err != nil {
81
		return
82
	}
83 1
	return
84
}
85
86
// List retrieves all permissions available with the current app access token.
87
// The list is not paginated.
88
//
89
// See: https://docs.mollie.com/reference/v2/permissions-api/list-permissions
90
func (ps *PermissionsService) List() (pl *PermissionsList, err error) {
91 1
	req, err := ps.client.NewAPIRequest(http.MethodGet, "v2/permissions", nil)
92 1
	if err != nil {
93
		return
94
	}
95 1
	res, err := ps.client.Do(req)
96 1
	if err != nil {
97
		return
98
	}
99 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
100
		return
101
	}
102 1
	return
103
}
104