-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_api.go
112 lines (103 loc) · 3.12 KB
/
data_api.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
package metax
import (
"encoding/json"
"fmt"
"math/big"
"net/http"
"net/url"
"strings"
)
type UniqueUserDataRequest struct {
StartDate string `json:"startDate"` /// Format (“MM-DD-YYYY”) example: 21st Jan 2022 would be 01-21-2022
EndDate string `json:"endDate"` /// Format (“MM-DD-YYYY”)
}
type UniqueUserDataResponse struct {
GeneralResponse
UniqueUserData []struct {
Date string `json:"date"`
Count int `json:"count"`
Addresses []string `json:"addresses"`
}
}
type UserLimitRequest struct {
SignerAddress string `json:"signerAddress"`
ApiId string `json:"apiId"`
}
type UserLimitResponse struct {
GeneralResponse
UserLimitData struct {
LimitLeft struct {
SignerAddress string `json:"signerAddress"`
TransactionLimitLeft float32 `json:"transactionLimitLeft"`
TransactionCount int `json:"transactionCount"`
AreLimitsConsumed bool `json:"areLimitsConsumed"`
UserTransactionLimit int `json:"userTransactionLimit"`
} `json:"limitLeft"`
LimitType string `json:"limitType"`
LimitStartTime *big.Int `json:"limitStartTime"`
LimitEndTime *big.Int `json:"limitEndTime"`
TimePeriodInDays int `json:"timePeriodInDays"`
} `json:"userLimitData"`
}
func (b *Bcnmy) GetUniqueUserData(data *UniqueUserDataRequest) (*UniqueUserDataResponse, error) {
bodyCh := make(chan []byte)
errorCh := make(chan error)
defer close(errorCh)
defer close(bodyCh)
body := url.Values{
"startDate": {data.StartDate},
"endDate": {data.EndDate},
}
req, err := http.NewRequest(http.MethodGet, UniqueUserDataURL, strings.NewReader(body.Encode()))
if err != nil {
b.logger.WithError(err).Error("GetUniqueUserData NewRequest failed")
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("authToken", b.authToken)
req.Header.Set("apiKey", b.apiKey)
var resp UniqueUserDataResponse
b.asyncHttpx(req, errorCh, bodyCh)
select {
case ret := <-bodyCh:
err = json.Unmarshal(ret, &resp)
if err != nil {
return nil, fmt.Errorf("GetUniqueUserData unmarshal failed, %v", err)
}
return &resp, nil
case err := <-errorCh:
b.logger.Error(err.Error())
return nil, err
}
}
func (b *Bcnmy) GetUserLimit(data *UserLimitRequest) (*UserLimitResponse, error) {
bodyCh := make(chan []byte)
errorCh := make(chan error)
defer close(errorCh)
defer close(bodyCh)
body := url.Values{
"signerAddress": {data.SignerAddress},
"apiId": {data.ApiId},
}
req, err := http.NewRequest(http.MethodGet, UserLimitURL, strings.NewReader(body.Encode()))
if err != nil {
b.logger.WithError(err).Error("GetUserLimit NewRequest failed")
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("authToken", b.authToken)
req.Header.Set("apiKey", b.apiKey)
var resp UserLimitResponse
b.asyncHttpx(req, errorCh, bodyCh)
select {
case ret := <-bodyCh:
err = json.Unmarshal(ret, &resp)
if err != nil {
return nil, fmt.Errorf("GetUserLimit unmarshal failed, %v", err)
}
return &resp, nil
case err := <-errorCh:
b.logger.Error(err.Error())
return nil, err
}
}