From d47cffcc38787fe5e79a643a5e09615c6852c496 Mon Sep 17 00:00:00 2001 From: Phil Cluff Date: Wed, 1 May 2019 13:28:56 +0100 Subject: [PATCH] Move implementation --- client.go | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) diff --git a/client.go b/client.go index 0b8b650..fd6d992 100644 --- a/client.go +++ b/client.go @@ -307,52 +307,6 @@ func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err err return errors.New("undefined response type") } -// !!! 🐉 Here be dragons 🐉 !!! -// This function exists just to work around one awkward API call where we can't model the response -// in a way that allows us to JSON unmarshal. The work around is to pre-process the JSON response from -// these calls, and manually build a struct to return. This function definately still needs cleanup. -func (c *APIClient) decodeForGetMetricTimeseriesData(v *GetMetricTimeseriesDataResponse, b []byte, contentType string) (err error) { - - if strings.Contains(contentType, "application/xml") { - return errors.New("decodeForGetMetricTimeseriesData does not support XML responses") - } else if strings.Contains(contentType, "application/json") { - - // Unmarshal JSON into a string => interface{} map - var result map[string]interface{} - json.Unmarshal([]byte(b), &result) - - // Build up a new list of each of the datapoints from data as [][]string, nil checking as we go - datapoints := [][]string{} - for _, node := range result["data"].([]interface{}) { - nodeAsArray := node.([]interface{}) - d := []string{"", "", ""} - d[0] = nodeAsArray[0].(string) - if nodeAsArray[1] != nil { - d[1] = fmt.Sprintf("%f", nodeAsArray[1].(float64)) - } - if nodeAsArray[2] != nil { - d[2] = fmt.Sprintf("%f", nodeAsArray[2].(float64)) - } - datapoints = append(datapoints, d) - } - - // Build the array of timeframe - timeframes := []int64{} - for _, time := range result["timeframe"].([]interface{}) { - timefloat := time.(float64) - timeframes = append(timeframes, int64(timefloat)) - } - - // Set the fields on the response object to what we've pieced together - v.Data = datapoints - v.Timeframe = timeframes - v.TotalRowCount = int64(result["total_row_count"].(float64)) - - return nil - } - return errors.New("undefined response type") -} - // Add a file to the multipart request func addFile(w *multipart.Writer, fieldName, path string) error { file, err := os.Open(path)