Created
July 17, 2014 23:41
-
-
Save ankurcha/5c4a28d8b6afb28e932f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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