-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequisitions_endpoints.go
60 lines (49 loc) · 1.7 KB
/
requisitions_endpoints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package gocardless
import (
"context"
"strconv"
)
// CreateRequisition creates a new requisition
func (c Client) CreateRequisition(ctx context.Context, requisitionRequestBody *RequisitionRequestBody) (*Requisition, error) {
var requisition Requisition
err := c.HTTP.Post(ctx, RequisitionsPath, RequestHeadersWithAuth(c.Token.Access), requisitionRequestBody, &requisition)
if err != nil {
return nil, err
}
return &requisition, nil
}
// ListRequisitions lists all requisitions
func (c Client) ListRequisitions(ctx context.Context, requestParams *ListRequisitionsParams) (*Requisitions, error) {
var requisitions Requisitions
endpointURL := RequisitionsPath
if requestParams != nil {
if requestParams.Limit != 0 {
endpointURL = endpointURL + "?" + strconv.Itoa(requestParams.Limit)
}
if requestParams.Offset != 0 {
endpointURL = endpointURL + "&" + strconv.Itoa(requestParams.Offset)
}
}
err := c.HTTP.Get(ctx, endpointURL, RequestHeadersWithAuth(c.Token.Access), &requisitions)
if err != nil {
return nil, err
}
return &requisitions, nil
}
// FetchRequisition retrieves a requisition by requisitionID
func (c Client) FetchRequisition(ctx context.Context, requisitionID string) (*Requisition, error) {
var requisition Requisition
err := c.HTTP.Get(ctx, RequisitionsPath+requisitionID, RequestHeadersWithAuth(c.Token.Access), &requisition)
if err != nil {
return nil, err
}
return &requisition, nil
}
// DeleteRequisition deletes a requisition by requisitionID
func (c Client) DeleteRequisition(ctx context.Context, requisitionID string) error {
err := c.HTTP.Delete(ctx, RequisitionsPath+requisitionID, RequestHeadersWithAuth(c.Token.Access), nil)
if err != nil {
return err
}
return nil
}