Skip to content

Instantly share code, notes, and snippets.

@ankurcha
Created July 17, 2014 23:41
Show Gist options
  • Select an option

  • Save ankurcha/5c4a28d8b6afb28e932f to your computer and use it in GitHub Desktop.

Select an option

Save ankurcha/5c4a28d8b6afb28e932f to your computer and use it in GitHub Desktop.
/*
var context = cubism.context(),
cube = context.cube("https://data.brightcove.com/v1/accounts/8523")
cube.metric("video_view")
*/
cubism_contextPrototype.analytics_api = function(url) {
if (!arguments.length) url = "";
var source = {},
context = this;
source.metric = function(field) {
var baseUrl = url + "?fields=" + field
return context.metric(function(start, stop, step, callback) {
d3.json(baseUrl + "/v1/accounts/" + account
+ "?fields=" + field
+ "&from=" + start.getTime()
+ "&to=" + stop.getTime()
//+ "&step=" + step <---- step is ignored for now ----->
,function(error, data) {
if(error) return console.warn(error);
if (!data) return callback(new Error("unable to load data"));
if(!data["metrics"][field]) {
callback(null, [])
} else {
callback(null, data["metrics"][field]["series"]["values"]);
}
});
}, field += "");
};
// Returns the Cube host.
source.toString = function() {
return host;
};
return source;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment