mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
197 lines
4.5 KiB
Go
197 lines
4.5 KiB
Go
// Code generated by "requestgen -method GET -type DistributionRequest -url /v1/metrics/distribution/:metric -responseType Response"; DO NOT EDIT.
|
|
|
|
package glassnodeapi
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"regexp"
|
|
)
|
|
|
|
func (d *DistributionRequest) SetAsset(Asset string) *DistributionRequest {
|
|
d.Asset = Asset
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetSince(Since int64) *DistributionRequest {
|
|
d.Since = Since
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetUntil(Until int64) *DistributionRequest {
|
|
d.Until = Until
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetInterval(Interval Interval) *DistributionRequest {
|
|
d.Interval = Interval
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetFormat(Format Format) *DistributionRequest {
|
|
d.Format = Format
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetTimestampFormat(TimestampFormat string) *DistributionRequest {
|
|
d.TimestampFormat = TimestampFormat
|
|
return d
|
|
}
|
|
|
|
func (d *DistributionRequest) SetMetric(Metric string) *DistributionRequest {
|
|
d.Metric = Metric
|
|
return d
|
|
}
|
|
|
|
// GetQueryParameters builds and checks the query parameters and returns url.Values
|
|
func (d *DistributionRequest) GetQueryParameters() (url.Values, error) {
|
|
var params = map[string]interface{}{}
|
|
// check Asset field -> json key a
|
|
Asset := d.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 := d.Since
|
|
|
|
// assign parameter of Since
|
|
params["s"] = Since
|
|
// check Until field -> json key u
|
|
Until := d.Until
|
|
|
|
// assign parameter of Until
|
|
params["u"] = Until
|
|
// check Interval field -> json key i
|
|
Interval := d.Interval
|
|
|
|
// assign parameter of Interval
|
|
params["i"] = Interval
|
|
// check Format field -> json key f
|
|
Format := d.Format
|
|
|
|
// assign parameter of Format
|
|
params["f"] = Format
|
|
// check TimestampFormat field -> json key timestamp_format
|
|
TimestampFormat := d.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 (d *DistributionRequest) 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 (d *DistributionRequest) GetParametersQuery() (url.Values, error) {
|
|
query := url.Values{}
|
|
|
|
params, err := d.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 (d *DistributionRequest) GetParametersJSON() ([]byte, error) {
|
|
params, err := d.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 (d *DistributionRequest) GetSlugParameters() (map[string]interface{}, error) {
|
|
var params = map[string]interface{}{}
|
|
// check Metric field -> json key metric
|
|
Metric := d.Metric
|
|
|
|
// assign parameter of Metric
|
|
params["metric"] = Metric
|
|
|
|
return params, nil
|
|
}
|
|
|
|
func (d *DistributionRequest) 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 (d *DistributionRequest) GetSlugsMap() (map[string]string, error) {
|
|
slugs := map[string]string{}
|
|
params, err := d.GetSlugParameters()
|
|
if err != nil {
|
|
return slugs, nil
|
|
}
|
|
|
|
for k, v := range params {
|
|
slugs[k] = fmt.Sprintf("%v", v)
|
|
}
|
|
|
|
return slugs, nil
|
|
}
|
|
|
|
func (d *DistributionRequest) Do(ctx context.Context) (Response, error) {
|
|
|
|
// no body params
|
|
var params interface{}
|
|
query, err := d.GetQueryParameters()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
apiURL := "/v1/metrics/distribution/:metric"
|
|
slugs, err := d.GetSlugsMap()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
apiURL = d.applySlugsToUrl(apiURL, slugs)
|
|
|
|
req, err := d.Client.NewAuthenticatedRequest(ctx, "GET", apiURL, query, params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response, err := d.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
|
|
}
|