mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-24 07:45:15 +00:00
197 lines
4.5 KiB
Go
197 lines
4.5 KiB
Go
// Code generated by "requestgen -method GET -type TransactionsRequest -url /v1/metrics/transactions/:metric -responseType Response"; DO NOT EDIT.
|
|
|
|
package glassnodeapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"regexp"
|
|
)
|
|
|
|
func (t *TransactionsRequest) SetAsset(Asset string) *TransactionsRequest {
|
|
t.Asset = Asset
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetSince(Since int64) *TransactionsRequest {
|
|
t.Since = Since
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetUntil(Until int64) *TransactionsRequest {
|
|
t.Until = Until
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetInterval(Interval Interval) *TransactionsRequest {
|
|
t.Interval = Interval
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetFormat(Format Format) *TransactionsRequest {
|
|
t.Format = Format
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetTimestampFormat(TimestampFormat string) *TransactionsRequest {
|
|
t.TimestampFormat = TimestampFormat
|
|
return t
|
|
}
|
|
|
|
func (t *TransactionsRequest) SetMetric(Metric string) *TransactionsRequest {
|
|
t.Metric = Metric
|
|
return t
|
|
}
|
|
|
|
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
|
func (t *TransactionsRequest) GetQueryParameters() (url.Values, error) {
|
|
var params = map[string]interface{}{}
|
|
// check Asset field -> json key a
|
|
Asset := t.Asset
|
|
|
|
// TEMPLATE check-required
|
|
if len(Asset) == 0 {
|
|
return nil, fmt.Errorf("a is required, empty string given")
|
|
}
|
|
// END TEMPLATE check-required
|
|
|
|
// assign parameter of Asset
|
|
params["a"] = Asset
|
|
// check Since field -> json key s
|
|
Since := t.Since
|
|
|
|
// assign parameter of Since
|
|
params["s"] = Since
|
|
// check Until field -> json key u
|
|
Until := t.Until
|
|
|
|
// assign parameter of Until
|
|
params["u"] = Until
|
|
// check Interval field -> json key i
|
|
Interval := t.Interval
|
|
|
|
// assign parameter of Interval
|
|
params["i"] = Interval
|
|
// check Format field -> json key f
|
|
Format := t.Format
|
|
|
|
// assign parameter of Format
|
|
params["f"] = Format
|
|
// check TimestampFormat field -> json key timestamp_format
|
|
TimestampFormat := t.TimestampFormat
|
|
|
|
// assign parameter of TimestampFormat
|
|
params["timestamp_format"] = TimestampFormat
|
|
|
|
query := url.Values{}
|
|
for k, v := range params {
|
|
query.Add(k, fmt.Sprintf("%v", v))
|
|
}
|
|
|
|
return query, nil
|
|
}
|
|
|
|
// GetParameters builds and checks the parameters and return the result in a map object
|
|
func (t *TransactionsRequest) GetParameters() (map[string]interface{}, error) {
|
|
var params = map[string]interface{}{}
|
|
|
|
return params, nil
|
|
}
|
|
|
|
// GetParametersQuery converts the parameters from GetParameters into the url.Values format
|
|
func (t *TransactionsRequest) GetParametersQuery() (url.Values, error) {
|
|
query := url.Values{}
|
|
|
|
params, err := t.GetParameters()
|
|
if err != nil {
|
|
return query, err
|
|
}
|
|
|
|
for k, v := range params {
|
|
query.Add(k, fmt.Sprintf("%v", v))
|
|
}
|
|
|
|
return query, nil
|
|
}
|
|
|
|
// GetParametersJSON converts the parameters from GetParameters into the JSON format
|
|
func (t *TransactionsRequest) GetParametersJSON() ([]byte, error) {
|
|
params, err := t.GetParameters()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return json.Marshal(params)
|
|
}
|
|
|
|
// GetSlugParameters builds and checks the slug parameters and return the result in a map object
|
|
func (t *TransactionsRequest) GetSlugParameters() (map[string]interface{}, error) {
|
|
var params = map[string]interface{}{}
|
|
// check Metric field -> json key metric
|
|
Metric := t.Metric
|
|
|
|
// assign parameter of Metric
|
|
params["metric"] = Metric
|
|
|
|
return params, nil
|
|
}
|
|
|
|
func (t *TransactionsRequest) applySlugsToUrl(url string, slugs map[string]string) string {
|
|
for k, v := range slugs {
|
|
needleRE := regexp.MustCompile(":" + k + "\\b")
|
|
url = needleRE.ReplaceAllString(url, v)
|
|
}
|
|
|
|
return url
|
|
}
|
|
|
|
func (t *TransactionsRequest) GetSlugsMap() (map[string]string, error) {
|
|
slugs := map[string]string{}
|
|
params, err := t.GetSlugParameters()
|
|
if err != nil {
|
|
return slugs, nil
|
|
}
|
|
|
|
for k, v := range params {
|
|
slugs[k] = fmt.Sprintf("%v", v)
|
|
}
|
|
|
|
return slugs, nil
|
|
}
|
|
|
|
func (t *TransactionsRequest) Do(ctx context.Context) (Response, error) {
|
|
|
|
// no body params
|
|
var params interface{}
|
|
query, err := t.GetQueryParameters()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
apiURL := "/v1/metrics/transactions/:metric"
|
|
slugs, err := t.GetSlugsMap()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
apiURL = t.applySlugsToUrl(apiURL, slugs)
|
|
|
|
req, err := t.Client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response, err := t.Client.SendRequest(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var apiResponse Response
|
|
if err := response.DecodeJSON(&apiResponse); err != nil {
|
|
return nil, err
|
|
}
|
|
return apiResponse, nil
|
|
}
|