Created
May 12, 2015 15:23
-
-
Save iaincollins/2f98f201cf0ea4c44169 to your computer and use it in GitHub Desktop.
Juicer 2.0 API Example
This file contains 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
<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> |
Author
iaincollins
commented
May 12, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment