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