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
Push — master ( 76d75a...85f6e4 )
by Victor Hugo
01:21
created

mollie.*InvoicesService.Get   A

Complexity

Conditions 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 11
dl 0
loc 15
ccs 10
cts 10
cp 1
crap 4
rs 9.85
c 0
b 0
f 0
nop 1
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"github.com/google/go-querystring/query"
7
	"net/http"
8
)
9
10
// InvoiceStatus status of the invoice
11
type InvoiceStatus string
12
13
// Valid status of the invoice
14
const (
15
	InvoiceStatusOpen    InvoiceStatus = "open"
16
	InvoiceStatusPaid    InvoiceStatus = "paid"
17
	InvoiceStatusOverdue InvoiceStatus = "overdue"
18
)
19
20
// Invoice describes a invoice detail
21
type Invoice struct {
22
	Resource    string        `json:"resource,omitempty"`
23
	ID          string        `json:"id,omitempty"`
24
	Reference   string        `json:"reference,omitempty"`
25
	VatNumber   string        `json:"vatNumber,omitempty"`
26
	Status      InvoiceStatus `json:"status,omitempty"`
27
	IssuedAt    string        `json:"issuedAt,omitempty"`
28
	PaidAt      string        `json:"paidAt,omitempty"`
29
	DueAt       string        `json:"dueAt,omitempty"`
30
	NetAmount   Amount        `json:"netAmount,omitempty"`
31
	VatAmount   Amount        `json:"vatAmount,omitempty"`
32
	GrossAmount Amount        `json:"grossAmount,omitempty"`
33
	Lines       []*LineItem   `json:"lines,omitempty"`
34
	Links       *InvoiceLinks `json:"_links,omitempty"`
35
}
36
37
// LineItem product detail
38
type LineItem struct {
39
	Period        string  `json:"period,omitempty"`
40
	Description   string  `json:"description,omitempty"`
41
	Count         int64   `json:"count,omitempty"`
42
	VatPercentage float64 `json:"vatPercentage,omitempty"`
43
	Amount        Amount  `json:"amount,omitempty"`
44
}
45
46
// InvoiceLinks describes all the possible links to be returned with
47
// a invoice object.
48
type InvoiceLinks struct {
49
	Self          URL `json:"self,omitempty"`
50
	PDF           URL `json:"pdf,omitempty"`
51
	Documentation URL `json:"documentation,omitempty"`
52
}
53
54
// ListInvoiceOptions describes list invoices endpoint valid query string parameters.
55
type ListInvoiceOptions struct {
56
	Reference string `json:"reference,omitempty"`
57
	Year      string `json:"year,omitempty"`
58
	From      int64  `json:"from,omitempty"`
59
	Limit     int64  `json:"limit,omitempty"`
60
}
61
62
// InvoiceList describes how a list of invoices will be retrieved by Mollie.
63
type InvoiceList struct {
64
	Count    int `json:"count,omitempty"`
65
	Embedded struct {
66
		Invoices []Invoice `json:"invoices"`
67
	} `json:"_embedded,omitempty"`
68
	Links PaginationLinks `json:"_links,omitempty"`
69
}
70
71
// InvoicesService instance operates over invoice resources
72
type InvoicesService service
73
74
// Get retrieve details of an invoice, using the invoice’s identifier.
75
func (is *InvoicesService) Get(id string) (i Invoice, err error) {
76 1
	getURL := fmt.Sprintf("v2/invoices/%s", id)
77
78 1
	req, err := is.client.NewAPIRequest(http.MethodGet, getURL, nil)
79 1
	if err != nil {
80 1
		return
81
	}
82 1
	res, err := is.client.Do(req)
83 1
	if err != nil {
84 1
		return
85
	}
86 1
	if err = json.Unmarshal(res.content, &i); err != nil {
87 1
		return
88
	}
89 1
	return
90
}
91
92
// List retrieves a list of invoices associated with your account/organization.
93
func (is *InvoicesService) List(options *ListInvoiceOptions) (il InvoiceList, err error) {
94 1
	u := fmt.Sprint("v2/invoices")
95 1
	if options != nil {
96 1
		v, _ := query.Values(options)
97 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
98
	}
99 1
	req, err := is.client.NewAPIRequest(http.MethodGet, u, nil)
100 1
	if err != nil {
101 1
		return
102
	}
103 1
	res, err := is.client.Do(req)
104 1
	if err != nil {
105 1
		return
106
	}
107 1
	if err = json.Unmarshal(res.content, &il); err != nil {
108 1
		return
109
	}
110 1
	return
111
}
112