-
Notifications
You must be signed in to change notification settings - Fork 5
/
credits.go
42 lines (31 loc) · 889 Bytes
/
credits.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
// credits.go
//
// This file implements the credits API calls
package atlas
import (
"encoding/json"
"github.com/pkg/errors"
)
// GetCredits returns high-level data for credits
func (c *Client) GetCredits() (credits *Credits, err error) {
opts := make(map[string]string)
opts = c.addAPIKey(opts)
opts = mergeOptions(opts, c.opts)
req := c.prepareRequest("GET", "credits", opts)
resp, err := c.call(req)
c.debug("resp: %#v - err: %#v", resp, err)
if err != nil {
return &Credits{}, errors.Wrap(err, "GetCredits/call")
}
// We may have all http errors here but the request did succeed
c.debug("http.code=%d", resp.StatusCode)
body, err := c.handleAPIResponse(resp)
if err != nil {
return &Credits{}, errors.Wrapf(err, "GetCredits")
}
credits = &Credits{}
credits = &Credits{}
err = json.Unmarshal(body, credits)
c.debug("credits=%#v\n", credits)
return
}