-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbalance_service.go
70 lines (61 loc) · 2.06 KB
/
balance_service.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
package sendpulse_sdk_go
import (
"context"
"net/http"
"strings"
)
// Automation360Service is a service to interact with user balance
type BalanceService struct {
client *Client
}
// newBalanceService creates Automation360Service
func newBalanceService(cl *Client) *BalanceService {
return &BalanceService{client: cl}
}
// Balance represents main information about user's balance
type Balance struct {
Currency string `json:"currency"`
BalanceCurrency float32 `json:"balance_currency"`
}
// Balance represents detailed information about user's balance
type BalanceDetailed struct {
Balance struct {
Main float32 `json:"main,string"`
Bonus float32 `json:"bonus,string"`
Currency string `json:"currency"`
} `json:"balance"`
Email struct {
TariffName string `json:"tariff_name"`
FinishedTime DateTime `json:"finished_time"`
EmailsLeft int `json:"emails_left"`
MaximumSubscribers int `json:"maximum_subscribers"`
CurrentSubscribers int `json:"current_subscribers"`
} `json:"email"`
Smtp struct {
TariffName string `json:"tariff_name"`
EndDate DateTime `json:"end_date"`
AutoRenew int `json:"auto_renew"`
} `json:"smtp"`
Push struct {
TariffName string `json:"tariff_name"`
EndDate DateTime `json:"end_date"`
AutoRenew int `json:"auto_renew"`
} `json:"push"`
}
// GetBalance returns main information about users's balance
func (service *BalanceService) GetBalance(ctx context.Context, currency string) (*Balance, error) {
path := "/balance"
if currency != "" {
path += "/" + strings.ToLower(currency)
}
var respData Balance
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return &respData, err
}
// GetDetailedBalance returns detailed information about users's balance
func (service *BalanceService) GetDetailedBalance(ctx context.Context) (*BalanceDetailed, error) {
path := "/user/balance/detail"
var respData BalanceDetailed
_, err := service.client.newRequest(ctx, http.MethodGet, path, nil, &respData, true)
return &respData, err
}