PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/share/spice/expatistan/spice.js

http://github.com/duckduckgo/zeroclickinfo-spice
JavaScript | 47 lines | 13 code | 3 blank | 31 comment | 2 complexity | 7e848dae913e5a25ffb16e0fbb3ecabe MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. This is the function you define.
  3. To see a live example of what this function produces, check out:
  4. http://duckduckgo.com/?q=is+it+raining+in+philadelphia
  5. Here is the flow (as laid out in the ../example.html file
  6. 1) The external API is called through our servers, e.g.
  7. http://duckduckgo.com/ir/Phialadelphia
  8. 2) The API call returns JSON wrapped in a callback function, i.e. JSONP.
  9. 3) That callback function is defined below. It's name corresponds
  10. to the internal API endpoint, i.e. /ir/ becomes /nrir/.
  11. Your project will get its own unique endpoint, and thus
  12. function name.
  13. 4) The callback function receives the JSON object as its argument.
  14. There is no need to parse the string returned by the API; it is
  15. already a JavaScript object -- that's the beauty of JSONP.
  16. You can check out what it looks like by using Firebug or
  17. a browser extention like JSONView
  18. 5) The function should do some validity checks to make sure
  19. what it got back is appropriate for display.
  20. 6) If so, then you create the return object and send it to nra(),
  21. which displays it on the page.
  22. */
  23. function ddg_spice_expatistan(ir) {
  24. var snippet = '';
  25. if (ir['status'] == 'OK') {
  26. snippet = ir['abstract'];
  27. items = new Array();
  28. items[0] = new Array();
  29. items[0]['a'] = snippet;
  30. items[0]['h'] = '';
  31. items[0]['s'] = 'Expatistan';
  32. items[0]['u'] = ir['source_url'];
  33. nra(items);
  34. }
  35. }