Skip to content

Commit

Permalink
Move implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
philcluff committed May 1, 2019
1 parent bdf79f1 commit d47cffc
Showing 1 changed file with 0 additions and 46 deletions.
46 changes: 0 additions & 46 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d47cffc

Please sign in to comment.