Skip to content

Instantly share code, notes, and snippets.

@iaincollins
Created May 12, 2015 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaincollins/2f98f201cf0ea4c44169 to your computer and use it in GitHub Desktop.
Save iaincollins/2f98f201cf0ea4c44169 to your computer and use it in GitHub Desktop.
Juicer 2.0 API Example
<html>
<body>
<h2>Lookup by Query</h2>
<textarea cols="100" rows="10" id="query-result"></textarea>
<hr/>
<h2>Lookup by URI</h2>
<textarea cols="100" rows="10" id="uri-result"></textarea>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var juicer = {
apikey: '9OHbOpZpVh9tQZBDjwTlTmsCF2Ce0yGQ',
host: "http://data.test.bbc.co.uk/bbcrd-juicer"
};
/**
* Get mentions for one or more URIs and/or a query in the Juicer
*/
function getMentionsByURI(uris, sources, start, end) {
// hist_interval=week
var url = juicer.host+"/articles?size=10&published_before="+end+"&published_after="+start+"&apikey="+juicer.apikey;
$(sources).each(function(index, source) {
url += "&sources[]="+source;
});
$(uris).each(function(index, uri) {
url += "&facets[]="+encodeURIComponent(uri)
});
return $.ajax({
url: url,
type: "GET",
dataType: 'json',
cache: false, // Append timestamp
success: function(response) {
$("#uri-result").text(JSON.stringify(response));
}
});
}
/**
* Get mentions for one or more URIs and/or a query in the Juicer
*/
function getMentionsByQuery(query, sources, start, end) {
// hist_interval=week
var url = juicer.host+"/articles?size=10&q="+encodeURIComponent(query)+"&published_before="+end+"&published_after="+start+"&apikey="+juicer.apikey;
console.log(url);
$(sources).each(function(index, source) {
url += "&sources[]="+source;
});
return $.ajax({
url: url,
type: "GET",
dataType: 'json',
cache: false, // Append timestamp
success: function(response) {
$("#query-result").text(JSON.stringify(response));
}
});
}
getMentionsByQuery("London");
getMentionsByURI([ "http://dbpedia.org/resource/David_Cameron" ]);
</script>
</body>
</html>
@iaincollins
Copy link
Author

  var graphData = []
  $(response.timeseries).each(function(index, object) {
    graphData.push([object.key, object.doc_count]);
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment