예제 #1
0
func (c *CrittercismAPIClient) FetchSumOfGraphIntoFlow(path, name string, interval int, f *gotelemetry.Flow) error {
	if data, found := f.ValueData(); found == true {
		value, err := c.FetchSumOfGraph(path, name, interval)

		if err != nil {
			return err
		}

		data.Value = value

		return nil
	}

	return gotelemetry.NewError(400, "Cannot extract value data from flow"+f.Tag)
}
func (p *CrittercismPlugin) AppStoreRatings(job *job.Job, f *gotelemetry.Flow) {
	jq, err := p.api.Request("GET", "apps?attributes=appType,rating", nil)

	if err != nil {
		job.ReportError(err)
		return
	}

	source, err := jq.Object()

	if err != nil {
		job.ReportError(err)
		return
	}

	data, found := f.ValueData()

	if !found {
		job.ReportError(gotelemetry.NewError(400, "Cannot extract value data from flow"+f.Tag))
		return
	}

	if appObj, ok := source[p.appId]; ok {
		app := appObj.(map[string]interface{})

		data.Value = app["rating"].(float64)

		switch p.ratingKey {
		case "ios":
			data.Icon = "fa-apple"

		case "android":
			data.Icon = "fa-android"

		case "wp":
			data.Icon = "fa-windows"

		case "html5":
			data.Icon = "fa-html5"
		}
	}

	job.PostFlowUpdate(f)
	job.Logf("Updated flow %s", f.Tag)
}