dodge
Version:
An API client for Foursquare's Venues Service
53 lines (43 loc) • 1.35 kB
JavaScript
// Generated by CoffeeScript 1.7.1
(function() {
var Dodge, extend, request;
extend = require('underscore').extend;
request = require('request');
Dodge = (function() {
function Dodge(options) {
this.baseUrl = 'https://api.foursquare.com/v2';
this.clientId = options.clientId;
this.clientSecret = options.clientSecret;
this.registerEndpoints('venues');
}
Dodge.prototype.registerEndpoints = function(namespace) {
var endpoint;
endpoint = require("./endpoints/" + namespace)(this);
return extend(this, endpoint);
};
Dodge.prototype.fetch = function(endpoint, queryParams, callback) {
var apiOptions, defaultQueryParams;
defaultQueryParams = {
client_id: this.clientId,
client_secret: this.clientSecret,
v: '20140429'
};
apiOptions = {
json: true,
qs: extend({}, queryParams, defaultQueryParams),
uri: "" + this.baseUrl + "/" + endpoint
};
return request(apiOptions, function(err, res, body) {
if (err != null) {
return callback(err);
}
if (body.meta.code !== 200) {
return callback(new Error(body.meta.errorDetail));
}
return callback(err, body);
});
};
return Dodge;
})();
module.exports = Dodge;
}).call(this);