From fdd415c4599ff45e5b83c2230118fd9d9504bb4b Mon Sep 17 00:00:00 2001 From: tripitakit Date: Tue, 12 Nov 2013 04:40:29 +0100 Subject: [PATCH] basic search --- lib/xeno-canto.js | 60 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/lib/xeno-canto.js b/lib/xeno-canto.js index ff33a4c..3c62281 100644 --- a/lib/xeno-canto.js +++ b/lib/xeno-canto.js @@ -3,11 +3,65 @@ * * * Copyright (c) 2013 Patrick De Marta - * Licensed under the MIT license. + * Licensed under the GNU GPL license. */ 'use strict'; -exports.awesome = function() { - return 'awesome'; +/** @dependencies */ +var rest = require('rest'); + +/** @constructor */ +function XenoCanto(){ + this.entity = {}; }; + + +/** Search for name of advanced options*/ +XenoCanto.prototype.search = function(query, success){ + + var url = 'http://www.xeno-canto.org/api/recordings.php?query='; + + // Duck-typing args + if (typeof(query) === 'string') { + + // Normal query search name in English, Latin, Family latin + url = url + query; + + } else { + // Genus gen:zonotrichia + // Recordist rec:John + // Country cnt:brazil. + // Location loc:tambopata. + // Recordist Remarks rmk:playback + // Geographic Coordinates + // lat, lon + // box:LAT_MIN,LON_MIN,LAT_MAX,LON_MAX + // Background Species also:formicariidae + // Sound type type:song + // Catalog number nr:76967 or range: nr:88888-88890 + // Recording Quality + // q:A will return recordings with a quality rating of A. + // q<:C will return recordings with a quality rating of D or E. + // World area area:africa (, america, asia, australia, europe) + } + + console.log("GET", url); + + get(this, url, success); + + +}; + +function get(that, url, success){ + rest(url).then(function(response) { + // store response in instance var + that.entity = JSON.parse(response.entity); + success(that); + } + ); +} + + +module.exports = XenoCanto; +