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