Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from pardocz/master
Browse files Browse the repository at this point in the history
Initial spice implementation for Expatistan
  • Loading branch information
yegg committed Oct 28, 2011
2 parents 8be4e66 + 1ad635a commit d3f57f1
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
33 changes: 33 additions & 0 deletions expatistan/spice.html
@@ -0,0 +1,33 @@
<html>
<head>

<!--
This is the function you define -- see its details in the repository.
//-->
<script type="text/javascript" src="/spice/expatistan/spice.js"></script>

<!--
This is a stub function that takes what you pass it
and creates the Zero-click Info that gets shoved
into the body of the page in the div marked "a".
//-->
<script type="text/javascript">
function nra(items) {
document.getElementById('a').innerHTML = items[0]['a'];
}
</script>

</head>

<body>

<!--
This is a placeholder div for the Zero-click Info that nra() populates
//-->
<div id="a"></div>

<script type="text/javascript" src="http://www.expatistan.com/api/spice?q=cost+of+living+in+london&api_key=wideopen"></script>
<script type="text/javascript" src="http://www.expatistan.com/api/spice?q=cost+of+living+london+vs+melbourne&api_key=wideopen"></script>

</body>
</html>
59 changes: 59 additions & 0 deletions expatistan/spice.js
@@ -0,0 +1,59 @@


/*
This is the function you define.
To see a live example of what this function produces, check out:
http://duckduckgo.com/?q=is+it+raining+in+philadelphia
Here is the flow (as laid out in the ../example.html file
1) The external API is called through our servers, e.g.
http://duckduckgo.com/ir/Phialadelphia
2) The API call returns JSON wrapped in a callback function, i.e. JSONP.
3) That callback function is defined below. It's name corresponds
to the internal API endpoint, i.e. /ir/ becomes /nrir/.
Your project will get its own unique endpoint, and thus
function name.
4) The callback function receives the JSON object as its argument.
There is no need to parse the string returned by the API; it is
already a JavaScript object -- that's the beauty of JSONP.
You can check out what it looks like by using Firebug or
a browser extention like JSONView
5) The function should do some validity checks to make sure
what it got back is appropriate for display.
6) If so, then you create the return object and send it to nra(),
which displays it on the page.
*/

function nrexp(ir) {
var snippet = '';

// For debugging.
// console.log(ir);

// Validity check.
if (ir['status'] == 'OK') {

// Snippet that gets shown in the 0-click box.
snippet = ir['abstract'];

items = new Array();
items[0] = new Array();
items[0]['a'] = snippet;

items[0]['h'] = '';

// Source name and url for the More at X link.
items[0]['s'] = 'Expatistan';
items[0]['u'] = ir['source_url'];

nra(items);
}
}
1 change: 1 addition & 0 deletions expatistan/spice.pl
@@ -0,0 +1 @@
$q_check =~ /cost of living/i

0 comments on commit d3f57f1

Please sign in to comment.