-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaccount.go
115 lines (97 loc) · 2.58 KB
/
account.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package goiex
import (
"net/http"
"net/url"
)
// Account struct to interface with /account endpoints
type Account struct {
iex
}
// Metadata struct
type Metadata struct {
PayAsYouGoEnabled bool `json:"payAsYouGoEnabled"`
EffectiveDate int64 `json:"effectiveDate"`
EndDateEffective int64 `json:"endDateEffective"`
SubscriptionTermType string `json:"subscriptionTermType"`
TierName string `json:"tierName"`
MessageLimit int `json:"messageLimit"`
MessagesUsed int `json:"messagesUsed"`
}
// Usage struct
type Usage struct {
Messages struct {
MonthlyUsage int `json:"monthlyUsage"`
MonthlyPayAsYouGo int `json:"monthlyPayAsYouGo"`
DailyUsage interface{} `json:"dailyUsage"`
TokenUsage interface{} `json:"tokenUsage"`
KeyUsage interface{} `json:"keyUsage"`
} `json:"messages"`
}
// NewAccount return new Account
func NewAccount(token, version string, base *url.URL, httpClient *http.Client, options ...IEXOption) *Account {
apiurl, err := url.Parse("account/")
if err != nil {
panic(err)
}
account := &Account{
iex: iex{
token: token,
version: version,
url: base,
apiurl: apiurl,
client: httpClient,
},
}
for _, option := range options {
err := option(&account.iex)
if err != nil {
return nil
}
}
return account
}
// Token return token string
func (a *Account) Token() string {
return a.token
}
// Version return version string
func (a *Account) Version() string {
return a.version
}
// URL return URL base
func (a *Account) URL() *url.URL {
return a.url
}
// APIURL return APIURL
func (a *Account) APIURL() *url.URL {
return a.apiurl
}
// Client return HTTP client
func (a *Account) Client() *http.Client {
return a.client
}
// Retry return Retry struct that implements Retryer
func (a *Account) Retry() *Retry {
return a.iex.Retry
}
// Metadata GET /account/metadata
func (a *Account) Metadata() (metadata *Metadata, err error) {
err = get(a, &metadata, "metadata", nil)
return
}
// Usage GET /account/usage
// No support for GET /account/usage/{type}
func (a *Account) Usage() (usage *Usage, err error) {
err = get(a, &usage, "usage", nil)
return
}
// Payasyougo POST /account/payasyougo
func (a *Account) Payasyougo(params interface{}) (ifc interface{}, err error) {
err = post(a, &ifc, "payasyougo", params.(map[string]interface{}))
return
}
// MessageBudget POST /account/messagebudget
func (a *Account) MessageBudget(params interface{}) (ifc interface{}, err error) {
err = post(a, &ifc, "messagebudget", params.(map[string]interface{}))
return
}