-
Notifications
You must be signed in to change notification settings - Fork 10
/
agreements.go
62 lines (52 loc) · 1.46 KB
/
agreements.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
61
62
package nordigen
import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
type EndUserAgreement struct {
Id string `json:"id,omitempty"`
Created time.Time `json:"created,omitempty"`
Accepted interface{} `json:"accepted,omitempty"`
MaxHistoricalDays int `json:"max_historical_days,omitempty"`
AccessValidForDays int `json:"access_valid_for_days,omitempty"`
InstitutionId string `json:"institution_id,omitempty"`
AgreementVersion string `json:"agreement_version,omitempty"`
AccessScope []string `json:"access_scope"`
}
const agreementsPath = "agreements"
const endUserPath = "enduser"
func (c Client) CreateEndUserAgreement(eua EndUserAgreement) (EndUserAgreement, error) {
req := http.Request{
Method: http.MethodPost,
URL: &url.URL{
Path: strings.Join([]string{agreementsPath, endUserPath, ""}, "/"),
},
}
data, err := json.Marshal(eua)
if err != nil {
return EndUserAgreement{}, nil
}
req.Body = io.NopCloser(bytes.NewBuffer(data))
resp, err := c.c.Do(&req)
if err != nil {
return EndUserAgreement{}, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return EndUserAgreement{}, err
}
if resp.StatusCode != http.StatusCreated {
return EndUserAgreement{}, &APIError{resp.StatusCode, string(body), err}
}
err = json.Unmarshal(body, &eua)
if err != nil {
return EndUserAgreement{}, err
}
return eua, nil
}