Browse files

Initial commit of v0.2.0 overhaul; more coming.

  • Loading branch information...
1 parent d5c6e7b commit 15add151e9112ac60288d832e6787b4037447642 @clintandrewhall committed Jan 1, 2013
View
50 lib/checkins.js
@@ -4,12 +4,9 @@
* @module node-foursquare/Checkins
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Tips");
+ var core = require('./core')(config),
+ path = require('path'),
+ logger = core.getLogger('checkins');
/**
* Retrieve a Foursquare Check-in.
@@ -19,18 +16,38 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/checkins/checkins.html
+ * @see https://developer.foursquare.com/docs/checkins/checkins
*/
function getCheckin(checkinId, params, accessToken, callback) {
- logger.debug("ENTERING: Checkins.getCheckin");
+ logger.enter('ENTERING: Checkins.getCheckin');
+
+ if(!checkinId) {
+ logger.error('getCheckin: checkinId is required.');
+ callback(new Error('Checkins.getCheckin: checkinId is required.'));
+ return;
+ }
+
+ core.callApi(path.join('/checkins', checkinId), accessToken, params || {}, callback);
+ }
+
+ /**
+ * Retrieve the 'likes' for a Foursquare Check-in.
+ * @memberof module:node-foursquare/Checkins
+ * @param {String} checkinId The id of the check-in.
+ * @param {String} accessToken The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/checkins/checkins/likes
+ */
+ function getLikes(checkinId, accessToken, callback) {
+ logger.enter('ENTERING: Checkins.getLikes');
if(!checkinId) {
- logger.error("getCheckin: checkinId is required.");
- callback(new Error("Checkins.getCheckin: checkinId is required."));
+ logger.error('getCheckin: checkinId is required.');
+ callback(new Error('Checkins.getCheckin: checkinId is required.'));
return;
}
- core.callApi(path.join("/checkins", checkinId), accessToken, params || {}, callback);
+ core.callApi(path.join('/checkins', checkinId, 'likes'), accessToken, {}, callback);
}
/**
@@ -42,15 +59,16 @@ module.exports = function(config) {
* @param {String|Number} [params.lng] The longitude of the location around which to search.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/checkins/recent.html
+ * @see https://developer.foursquare.com/docs/checkins/recent
*/
function getRecentCheckins(params, accessToken, callback) {
- logger.debug("ENTERING: Checkins.getRecentCheckins");
- core.callApi("/checkins/recent", accessToken, params || {}, callback);
+ logger.enter('ENTERING: Checkins.getRecentCheckins');
+ core.callApi('/checkins/recent', accessToken, params || {}, callback);
}
return {
- "getCheckin" : getCheckin,
- "getRecentCheckins" : getRecentCheckins
+ 'getCheckin' : getCheckin,
+ 'getLikes' : getLikes,
+ 'getRecentCheckins' : getRecentCheckins
}
};
View
72 lib/config-default.js
@@ -1,36 +1,58 @@
+
+var winston = require('winston');
+
module.exports = {
- "foursquare" : {
- "accessTokenUrl" : "https://foursquare.com/oauth2/access_token",
- "authenticateUrl" : "https://foursquare.com/oauth2/authenticate",
- "apiUrl" : "https://api.foursquare.com/v2"
+ 'foursquare' : {
+ 'accessTokenUrl' : 'https://foursquare.com/oauth2/access_token',
+ 'authenticateUrl' : 'https://foursquare.com/oauth2/authenticate',
+ 'apiUrl' : 'https://api.foursquare.com/v2'
/*
- This field will indicate which version of the Foursquare API you wish to call. If not specified or set to "LATEST",
+ This field will indicate which version of the Foursquare API you wish to call. If not specified or set to 'LATEST',
it will use the latest version by setting the version number to today's date.
*/
- //"version" : "LATEST",
+ //'version' : 'LATEST',
/*
This field determines how this library handles endpoints that return results along with an error, (e.g. deprecations).
- - If set to "WARN" (default), log4js will write a warning to the log, (NOTE: You must raise the
- "node-foursquare.core" log4js level to WARN or lower in order to see these warnings.
- - If set to "ERROR", the library will behave as though it encountered an ERROR and not return results.
+ - If set to 'WARN' (default), log4js will write a warning to the log, (NOTE: You must raise the
+ 'node-foursquare.core' log4js level to WARN or lower in order to see these warnings.
+ - If set to 'ERROR', the library will behave as though it encountered an ERROR and not return results.
*/
- //"warnings" : "WARN"
+ //'warnings' : 'WARN'
},
- "log4js" : {
- "levels" : {
- "node-foursquare" : "INFO",
- "node-foursquare.core" : "OFF",
- "node-foursquare.Users" : "OFF",
- "node-foursquare.Venues" : "OFF",
- "node-foursquare.Checkins" : "OFF",
- "node-foursquare.Tips" : "OFF",
- "node-foursquare.Lists" : "OFF",
- "node-foursquare.Photos" : "OFF",
- "node-foursquare.Settings" : "OFF",
- "node-foursquare.Specials" : "OFF",
- "node-foursquare.Updates" : "OFF",
- "node-foursquare.Events" : "OFF"
+ 'winston' : {
+ 'transports' : [
+ new (winston.transports.Console)(
+ {
+ 'level' : 'enter',
+ 'colorize' : true
+ }
+ )
+ ],
+ 'levels': {
+ 'detail': 0,
+ 'trace': 1,
+ 'debug': 2,
+ 'enter': 3,
+ 'info': 4,
+ 'warn': 5,
+ 'error': 6
+ },
+ 'colors': {
+ 'detail': 'grey',
+ 'trace': 'white',
+ 'debug': 'blue',
+ 'enter': 'inverse',
+ 'info': 'green',
+ 'warn': 'yellow',
+ 'error': 'red'
+ },
+ 'loggers': {
+ 'default': {
+ 'console': {
+ 'level': 'none'
+ }
+ }
}
},
- "secrets" : { }
+ 'secrets' : { }
};
View
109 lib/core.js
@@ -1,8 +1,9 @@
var exports = module.exports,
qs = require('querystring'),
- sys = require("util"),
+ util = require('util'),
https = require('https'),
urlParser = require('url'),
+ winston = require('winston'),
emptyCallback = function() { };
/**
@@ -11,43 +12,60 @@ var exports = module.exports,
*/
module.exports = function(config) {
- var log4js = require("log4js");
+ var logger = getLogger('core');
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.core");
+ function getLoggerSettings(name) {
+ var settings = config.winston.loggers[name] || config.winston.loggers.default;
+
+ if(!settings) {
+ logger.error('No settings exist for \'' + name + '\', nor is there a default. Update your configuration.');
+ settings = config.winston.loggers['default'] = {
+ 'console': {
+ 'level': 'warn'
+ }
+ }
+ }
+
+ for(var setting in settings) {
+ settings[setting]['label'] = 'node-foursquare:' + name;
+ settings[setting]['colorize'] = true;
+ }
+
+ return settings;
+ }
function retrieve(url, callback) {
callback = callback || emptyCallback;
- var parsedUrl = urlParser.parse(url, true), request, result = "";
+ var parsedUrl = urlParser.parse(url, true), request, result = '';
- if(parsedUrl.protocol == "https:" && !parsedUrl.port) {
+ if(parsedUrl.protocol == 'https:' && !parsedUrl.port) {
parsedUrl.port = 443;
}
if(parsedUrl.query === undefined) {
parsedUrl.query = {};
}
- var path = parsedUrl.pathname + "?" + qs.stringify(parsedUrl.query);
- logger.debug("Requesting: " + path);
+ var path = parsedUrl.pathname + '?' + qs.stringify(parsedUrl.query);
+ logger.debug('retrieve: Request path: ' + path);
request = https.request({
- "host" : parsedUrl.hostname,
- "port" : parsedUrl.port,
- "path" : path,
- "method" : "GET",
- "headers" : {
- "Content-Length": 0
+ 'host' : parsedUrl.hostname,
+ 'port' : parsedUrl.port,
+ 'path' : path,
+ 'method' : 'GET',
+ 'headers' : {
+ 'Content-Length': 0
}
}, function(res) {
- res.on("data", function(chunk) {
+ res.on('data', function(chunk) {
result += chunk;
});
- res.on("end", function() {
+ res.on('end', function() {
callback(null, res.statusCode, result);
});
});
- request.on("error", function(error) {
- logger.error("Error calling remote host: " + error.message);
+ request.on('error', function(error) {
+ logger.error('retrieve: Error calling remote host: ' + error.message);
callback(error);
});
@@ -72,7 +90,7 @@ module.exports = function(config) {
parsedUrl.query.v = config.foursquare.version;
}
- parsedUrl.search = "?" + qs.stringify(parsedUrl.query);
+ parsedUrl.search = '?' + qs.stringify(parsedUrl.query);
url = urlParser.format(parsedUrl);
retrieve(url,
@@ -81,7 +99,7 @@ module.exports = function(config) {
callback(error);
}
else {
- logger.trace(sys.inspect(result));
+ logger.trace('invokeApi: Result: ' + util.inspect(result));
callback(null, status, result);
}
});
@@ -103,9 +121,10 @@ module.exports = function(config) {
if(json.meta && json.meta.code === 200) {
if(json.meta.errorType) {
var parsedUrl = urlParser.parse(url),
- message = parsedUrl.pathname + " (" + json.meta.errorType + "): " + json.meta.errorDetail || "No detail provided.";
- logger.debug("Warning level set to: " + config.foursquare.warnings);
- if(config.foursquare.warnings === "ERROR") {
+ message =
+ parsedUrl.pathname + ' (' + json.meta.errorType + '): ' + json.meta.errorDetail || 'No detail provided.';
+ logger.debug('extractData: Warning level set to ' + config.foursquare.warnings);
+ if(config.foursquare.warnings === 'ERROR') {
logger.error(message);
callback(new Error(message));
return;
@@ -122,48 +141,64 @@ module.exports = function(config) {
}
}
else if(json.meta) {
- logger.error("JSON Response had unexpected code: \"" + json.meta.code + ": " + json.meta.errorDetail + "\"");
- callback(new Error(json.meta.code + ": " + json.meta.errorDetail));
+ logger.error('JSON Response had unexpected code: \'' + json.meta.code + ': ' + json.meta.errorDetail + '\'');
+ callback(new Error(json.meta.code + ': ' + json.meta.errorDetail));
}
else {
- logger.error("Response had no code: " + sys.inspect(json));
- callback(new Error("Response had no code: " + sys.inspect(json)));
+ logger.error('Response had no code: ' + util.inspect(json));
+ callback(new Error('Response had no code: ' + util.inspect(json)));
}
}
else {
- logger.error("There was an unexpected, fatal error calling Foursquare: the response was undefined or had no status code.");
- callback(new Error("Foursquare had no response or status code."));
+ logger.error(
+ 'There was an unexpected, fatal error calling Foursquare: the response was undefined or had no status code.'
+ );
+ callback(new Error('Foursquare had no response or status code.'));
}
}
function callApi(path, accessToken, params, callback) {
+ if(!callback || typeof(callback) !== 'function') {
+ logger.error('callApi: callback not provided.');
+ throw new Error('callApi: callback not provided');
+ }
+
var url = config.foursquare.apiUrl + path;
if(params) {
if((params.lat && !params.lng) || (!params.lat && params.lng)) {
- callback(new Error("parameters: if you specify a longitude or latitude, you must include BOTH."));
+ callback(new Error('callApi:parameters: if you specify a longitude or latitude, you must include BOTH.'));
return;
}
if(params.lat && params.lng) {
- params.ll = params.lat + "," + params.lng;
+ params.ll = params.lat + ',' + params.lng;
delete params.lat;
delete params.lng;
}
- url += "?" + qs.stringify(params);
+ url += '?' + qs.stringify(params);
}
- logger.trace("URL: " + url);
+ logger.trace('callApi: Request URL: ' + url);
invokeApi(url, accessToken, function(error, status, result) {
extractData(url, status, result, callback);
});
}
+ function getLogger(name) {
+ if(!winston.loggers.has(name)) {
+ var logger = winston.loggers.add(name, getLoggerSettings(name));
+ logger.setLevels(config.winston.levels);
+ }
+ return winston.loggers.get(name);
+ }
+
return {
- "retrieve" : retrieve,
- "invokeApi" : invokeApi,
- "extractData" : extractData,
- "callApi" : callApi
+ 'getLogger' : getLogger,
+ 'retrieve' : retrieve,
+ 'invokeApi' : invokeApi,
+ 'extractData' : extractData,
+ 'callApi' : callApi
}
};
View
38 lib/events.js
@@ -1,15 +1,14 @@
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Events from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Events
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Events");
+ var core = require('./core')(config),
+ logger = core.getLogger('events');
/**
* Retrieve an event from Foursquare.
@@ -20,15 +19,16 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/photos/photos.html
*/
function getEvent(eventId, accessToken, callback) {
- logger.debug("ENTERING: Events.getEvent");
+ logger.enter('getEvent');
if(!eventId) {
- logger.error("getEvent: eventId is required.");
- callback(new Error("Events.getEvent: eventId is required."));
+ logger.error('getEvent: eventId is required.');
+ callback(new Error('Events.getEvent: eventId is required.'));
return;
}
-
- core.callApi(path.join("/events", eventId), accessToken, null, callback);
+
+ logger.debug('getEvent:eventId: ' + eventId);
+ core.callApi(path.join('/events', eventId), accessToken, null, callback);
}
/**
@@ -41,8 +41,9 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/events/search.html
*/
function search(params, accessToken, callback) {
- logger.debug("ENTERING: Events.getTip");
- core.callApi("/events/search", accessToken, params || {}, callback);
+ logger.enter('getTip');
+ logger.debug('search:params: ' + util.inspect(params));
+ core.callApi('/events/search', accessToken, params || {}, callback);
}
/**
@@ -55,14 +56,15 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/events/categories.html
*/
function getCategories(params, accessToken, callback) {
- logger.debug("ENTERING: Events.getCategories");
- core.callApi("/events/categories", accessToken, params || {}, callback);
+ logger.enter('getCategories');
+ logger.debug('getCategories:params: ' + util.inspect(params));
+ core.callApi('/events/categories', accessToken, params || {}, callback);
}
return {
- "getEvent" : getEvent,
- "search" : search,
- "getCategories" : getCategories
+ 'getCategories' : getCategories,
+ 'getEvent' : getEvent,
+ 'search' : search
}
};
View
92 lib/lists.js
@@ -1,130 +1,142 @@
+
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Photos from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Photos
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Lists");
+ var core = require('./core')(config),
+ logger = core.getLogger('events');
/**
* Retrieve a list from Foursquare.
* @memberof module:node-foursquare/Lists
- * @param {String} listId The id of the List to retrieve; accepts IDs such as "self/tips" or "USER_ID/todos".
+ * @param {String} listId The id of the List to retrieve; accepts IDs such as 'self/tips' or 'USER_ID/todos'.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/lists/lists.html
*/
function getList(listId, accessToken, callback) {
- logger.debug("ENTERING: Lists.getList");
+ logger.enter('getList');
if(!listId) {
- logger.error("getList: listId is required.");
- callback(new Error("Lists.getList: listId is required."));
+ logger.error('getList: listId is required.');
+ callback(new Error('Lists.getList: listId is required.'));
return;
}
- core.callApi(path.join("/lists", listId), accessToken, null, callback);
+
+ logger.debug('getList:listId: ' + listId);
+ core.callApi(path.join('/lists', listId), accessToken, null, callback);
}
/**
* Retrieve followers of a List from Foursquare.
* @memberof module:node-foursquare/Lists
- * @param {String} listId The id of the List; accepts IDs such as "self/tips" or "USER_ID/todos".
+ * @param {String} listId The id of the List; accepts IDs such as 'self/tips' or 'USER_ID/todos'.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/lists/followers.html
*/
function getFollowers(listId, accessToken, callback) {
- logger.debug("ENTERING: Lists.getFollowers");
+ logger.enter('getFollowers');
if(!listId) {
- logger.error("getFollowers: listId is required.");
- callback(new Error("Lists.getFollowers: listId is required."));
+ logger.error('getFollowers: listId is required.');
+ callback(new Error('Lists.getFollowers: listId is required.'));
return;
}
- core.callApi(path.join("/lists", listId, "followers"), accessToken, null, callback);
+
+ logger.debug('getList:listId: ' + listId);
+ core.callApi(path.join('/lists', listId, 'followers'), accessToken, null, callback);
}
/**
* Retrieve venues suggested for a List from Foursquare.
* @memberof module:node-foursquare/Lists
- * @param {String} listId The id of the List; accepts IDs such as "self/tips" or "USER_ID/todos".
+ * @param {String} listId The id of the List; accepts IDs such as 'self/tips' or 'USER_ID/todos'.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/lists/followers.html
*/
function getSuggestedVenues(listId, accessToken, callback) {
- logger.debug("ENTERING: Lists.getSuggestedVenues");
+ logger.enter('getSuggestedVenues');
if(!listId) {
- logger.error("getSuggestedVenues: listId is required.");
- callback(new Error("Lists.getSuggestedVenues: listId is required."));
+ logger.error('getSuggestedVenues: listId is required.');
+ callback(new Error('Lists.getSuggestedVenues: listId is required.'));
return;
}
- core.callApi(path.join("/lists", listId, "suggestvenues"), accessToken, null, callback);
+
+ logger.debug('getList:listId: ' + listId);
+ core.callApi(path.join('/lists', listId, 'suggestvenues'), accessToken, null, callback);
}
/**
* Retrieve venues suggested for an item in a List from Foursquare.
* @memberof module:node-foursquare/Lists
- * @param {String} listId The id of the List; accepts IDs such as "self/tips" or "USER_ID/todos".
+ * @param {String} listId The id of the List; accepts IDs such as 'self/tips' or 'USER_ID/todos'.
* @param {String} itemId The id of an item in the List.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/lists/followers.html
*/
function getSuggestedPhotos(listId, itemId, accessToken, callback) {
- logger.debug("ENTERING: Lists.getSuggestedPhotos");
+ logger.enter('getSuggestedPhotos');
if(!listId) {
- logger.error("getSuggestedPhotos: listId is required.");
- callback(new Error("Lists.getSuggestedPhotos: listId is required."));
+ logger.error('getSuggestedPhotos: listId is required.');
+ callback(new Error('Lists.getSuggestedPhotos: listId is required.'));
return;
}
if(!itemId) {
- logger.error("getSuggestedPhotos: itemId is required.");
- callback(new Error("Lists.getSuggestedPhotos: itemId is required."));
+ logger.error('getSuggestedPhotos: itemId is required.');
+ callback(new Error('Lists.getSuggestedPhotos: itemId is required.'));
return;
}
- core.callApi(path.join("/lists", listId, "suggestphoto"), accessToken, { "itemId" : itemId }, callback);
+
+ logger.debug('getList:listId: ' + listId);
+ logger.debug('getList:itemId: ' + itemId);
+ core.callApi(path.join('/lists', listId, 'suggestphoto'), accessToken, { 'itemId' : itemId }, callback);
}
/**
* Retrieve tips suggested for an item in a List from Foursquare.
* @memberof module:node-foursquare/Lists
- * @param {String} listId The id of the List; accepts IDs such as "self/tips" or "USER_ID/todos".
+ * @param {String} listId The id of the List; accepts IDs such as 'self/tips' or 'USER_ID/todos'.
* @param {String} itemId The id of an item in the List.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/lists/followers.html
*/
function getSuggestedTips(listId, itemId, accessToken, callback) {
- logger.debug("ENTERING: Lists.getSuggestedTips");
+ logger.enter('getSuggestedTips');
if(!listId) {
- logger.error("getSuggestedTips: listId is required.");
- callback(new Error("Lists.getSuggestedTips: listId is required."));
+ logger.error('getSuggestedTips: listId is required.');
+ callback(new Error('Lists.getSuggestedTips: listId is required.'));
return;
}
if(!itemId) {
- logger.error("getSuggestedTips: itemId is required.");
- callback(new Error("Lists.getSuggestedTips: itemId is required."));
+ logger.error('getSuggestedTips: itemId is required.');
+ callback(new Error('Lists.getSuggestedTips: itemId is required.'));
return;
}
- core.callApi(path.join("/lists", listId, "suggesttip"), accessToken, { "itemId" : itemId }, callback);
+
+ logger.debug('getList:listId: ' + listId);
+ logger.debug('getList:itemId: ' + itemId);
+ core.callApi(path.join('/lists', listId, 'suggesttip'), accessToken, { 'itemId' : itemId }, callback);
}
return {
- "getList" : getList,
- "getFollowers" : getFollowers,
- "getSuggestedVenues" : getSuggestedVenues,
- "getSuggestedPhotos" : getSuggestedPhotos,
- "getSuggestedTips" : getSuggestedTips
+ 'getList' : getList,
+ 'getFollowers' : getFollowers,
+ 'getSuggestedPhotos' : getSuggestedPhotos,
+ 'getSuggestedTips' : getSuggestedTips,
+ 'getSuggestedVenues' : getSuggestedVenues
}
};
View
82 lib/node-foursquare.js
@@ -1,22 +1,22 @@
/**
* A NodeJS module for interfacing with Foursquare.
* @module node-foursquare
- * @version 0.1.3
+ * @version 0.2
* @author Clint Andrew Hall
* @description A NodeJS module for interacting with Foursquare.
* @param {Object} config A valid configuration.
*/
var qs = require('querystring'),
- sys = require("util"),
- defaultConfig = require("./config-default"),
- log4js = require("log4js");
+ util = require('util'),
+ defaultConfig = require('./config-default'),
+ winston = require('winston');
function mergeDefaults(o1, o2) {
for(var p in o2) {
try {
- if(typeof o2[p] == "object") {
+ if(typeof o2[p] == 'object') {
o1[p] = mergeDefaults(o1[p], o2[p]);
- } else if(typeof o1[p] == "undefined") {
+ } else if(typeof o1[p] == 'undefined') {
o1[p] = o2[p];
}
} catch(e) {
@@ -29,60 +29,62 @@ function mergeDefaults(o1, o2) {
module.exports = function(config) {
- function getLogger(config) {
- log4js.configure(config.log4js);
- return log4js.getLogger("node-foursquare");
- }
-
function configure(config) {
config = config || {};
mergeDefaults(config, defaultConfig);
- var logger = getLogger(config);
+ winston.addColors(config.winston.colors);
+
+ var logger = new (winston.Logger)();
+ logger.setLevels(config.winston.levels);
if(!config.secrets || !config.secrets.clientId || !config.secrets.clientSecret || !config.secrets.redirectUrl) {
- logger.error("Client configuration not supplied; add config.secrets information, (clientId, clientSecret, redirectUrl).");
- throw new Error("Configuration Error: Client information not supplied.");
+ logger.error(
+ 'Client configuration not supplied; add config.secrets information, (clientId, clientSecret, redirectUrl).'
+ );
+ throw new Error('Configuration Error: Client information not supplied.');
}
if(!config.foursquare.accessTokenUrl || !config.foursquare.apiUrl) {
- logger.error("Foursquare configuration not supplied; add config.foursquare information, (accessTokenUrl, apiUrl)");
- throw new TypeError("Configuration Error: Foursquare information not supplied.");
+ logger.error(
+ 'Foursquare configuration not supplied; add config.foursquare information, (accessTokenUrl, apiUrl)'
+ );
+ throw new TypeError('Configuration Error: Foursquare information not supplied.');
}
- if(!config.foursquare.version || config.foursquare.version === "LATEST") {
+ if(!config.foursquare.version || config.foursquare.version === 'LATEST') {
var d = new Date(), month = d.getMonth() + 1, date = d.getDate();
- config.foursquare.version = d.getFullYear() + ((month < 10 ? "0" : "") + month) + ((date < 10 ? "0" : "") + date);
- logger.warn("Foursquare API version not defined in configuration; defaulting to latest: " + config.foursquare.version);
+ config.foursquare.version =
+ d.getFullYear() + ((month < 10 ? '0' : '') + month) + ((date < 10 ? '0' : '') + date);
+ logger.warn(
+ 'Foursquare API version not defined in configuration; defaulting to latest: ' + config.foursquare.version
+ );
}
return config;
}
config = configure(config);
- var logger = getLogger(config),
- core = require("./core")(config);
-
- logger.debug("Configuration: " + sys.inspect(config));
+ var core = require('./core')(config);
/**
* Exchange a user authorization code for an access token.
* @memberof module:node-foursquare
* @param {Object} params A collection of parameters for the Access Token request.
* @param {String} params.code The code provided by Foursquare as the result of the user redirect.
- * @param {String} [params.grant_type="authorization_code"] The type of authorization to request.
+ * @param {String} [params.grant_type='authorization_code'] The type of authorization to request.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
* @see https://developer.foursquare.com/docs/oauth.html
*/
function getAccessToken(params, callback) {
params = params || {};
- params.grant_type = params.grant_type || "authorization_code";
+ params.grant_type = params.grant_type || 'authorization_code';
params.client_id = config.secrets.clientId;
params.client_secret = config.secrets.clientSecret;
params.redirect_uri = config.secrets.redirectUrl;
- core.retrieve(config.foursquare.accessTokenUrl + "?" + qs.stringify(params),
+ core.retrieve(config.foursquare.accessTokenUrl + '?' + qs.stringify(params),
function(error, status, result) {
if(error) {
callback(error);
@@ -103,21 +105,23 @@ module.exports = function(config) {
* @memberof module:node-foursquare
*/
function getAuthClientRedirectUrl() {
- return config.foursquare.authenticateUrl + "?client_id=" + config.secrets.clientId + "&response_type=code&redirect_uri=" + config.secrets.redirectUrl;
+ return config.foursquare.authenticateUrl + '?client_id=' +
+ config.secrets.clientId + '&response_type=code&redirect_uri=' +
+ config.secrets.redirectUrl;
}
return {
- "Users" : require("./users")(config),
- "Venues" : require("./venues")(config),
- "Checkins" : require("./checkins")(config),
- "Tips" : require("./tips")(config),
- "Lists" : require("./lists")(config),
- "Photos" : require("./photos")(config),
- "Settings" : require("./settings")(config),
- "Specials" : require("./specials")(config),
- "Updates" : require("./updates")(config),
- "Events" : require("./events")(config),
- "getAccessToken" : getAccessToken,
- "getAuthClientRedirectUrl" : getAuthClientRedirectUrl
+ 'Users' : require('./users')(config),
+ 'Venues' : require('./venues')(config),
+ 'Checkins' : require('./checkins')(config),
+ 'Tips' : require('./tips')(config),
+ 'Lists' : require('./lists')(config),
+ 'Photos' : require('./photos')(config),
+ 'Settings' : require('./settings')(config),
+ 'Specials' : require('./specials')(config),
+ 'Updates' : require('./updates')(config),
+ 'Events' : require('./events')(config),
+ 'getAccessToken' : getAccessToken,
+ 'getAuthClientRedirectUrl' : getAuthClientRedirectUrl
}
};
View
23 lib/photos.js
@@ -1,15 +1,14 @@
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Photos from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Photos
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Photos");
+ var core = require('./core')(config),
+ logger = core.getLogger('photos');
/**
* Retrieve a photo from Foursquare.
@@ -20,17 +19,19 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/photos/photos.html
*/
function getPhoto(photoId, accessToken, callback) {
- logger.debug("ENTERING: Photos.getPhoto");
+ logger.enter('getPhoto');
if(!photoId) {
- logger.error("getPhoto: photoId is required.");
- callback(new Error("Photos.getPhoto: photoId is required."));
+ logger.error('getPhoto: photoId is required.');
+ callback(new Error('Photos.getPhoto: photoId is required.'));
return;
}
- core.callApi(path.join("/photos", photoId), accessToken, null, callback);
+
+ logger.debug('search:photoId: ' + photoId);
+ core.callApi(path.join('/photos', photoId), accessToken, null, callback);
}
return {
- "getPhoto" : getPhoto
+ 'getPhoto' : getPhoto
}
};
View
27 lib/settings.js
@@ -1,15 +1,13 @@
+var path = require('path');
+
/**
* A module for retrieving information about Settings from Foursquare.
* @module node-foursquare/Settings
* @param {Object} config A valid configuration.
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Settings");
+ var core = require('./core')(config),
+ logger = core.getLogger('settings');
/**
* Retreive Foursquare settings for the current user.
@@ -19,8 +17,8 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/settings/all.html
*/
function getSettings(accessToken, callback) {
- logger.debug("ENTERING: Settings.getSettings");
- core.callApi("/settings/all", accessToken, null, callback);
+ logger.enter('getSettings');
+ core.callApi('/settings/all', accessToken, null, callback);
}
/**
@@ -32,19 +30,20 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/settings/all.html
*/
function getSetting(name, accessToken, callback) {
- logger.debug("ENTERING: Settings.getSetting");
+ logger.enter('getSetting');
if (!name) {
- logger.error("getSetting: name is required.");
- callback(new Error("Settings.getSetting: name is required."));
+ logger.error('getSetting: name is required.');
+ callback(new Error('Settings.getSetting: name is required.'));
return;
}
- core.callApi(path.join("/settings/", name), accessToken, null, callback);
+ logger.debug('getSetting:name: ' + name);
+ core.callApi(path.join('/settings/', name), accessToken, null, callback);
}
return {
- "getSettings" : getSettings,
- "getSetting" : getSetting
+ 'getSetting' : getSetting,
+ 'getSettings' : getSettings
}
};
View
96 lib/specials.js
@@ -1,14 +1,13 @@
+var util = require('util');
+
/**
* A module for retrieving information about Specials from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Specials
*/
module.exports = function(config){
- var core = require("./core")(config),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Specials");
+ var core = require('./core')(config),
+ logger = core.getLogger('specials');
/**
* Search for Foursquare specials.
@@ -19,54 +18,109 @@ module.exports = function(config){
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/specials/search.html
+ * @see https://developer.foursquare.com/docs/specials/search
*/
function search(lat, lng, params, accessToken, callback) {
- logger.debug("ENTERING: Specials.search");
+ logger.enter('search');
params = params || {};
if(!lat || !lng) {
- logger.error("Lat and Lng are both required parameters.");
- callback(new Error("Specials.search: lat and lng are both required."));
+ logger.error('Lat and Lng are both required parameters.');
+ callback(new Error('Specials.search: lat and lng are both required.'));
return;
}
- params.ll = lat + "," + lng;
+ logger.debug('search:lat: ' + lat);
+ logger.debug('search:lng: ' + lng);
+ logger.debug('search:params: ' + util.inspect(params));
+ params.ll = lat + ',' + lng;
- core.callApi("/specials/search", accessToken, params, callback);
+ core.callApi('/specials/search', accessToken, params, callback);
}
/**
- * Search for Foursquare specials.
+ * Retrieve a Foursquare specials.
* @memberof module:node-foursquare/Specials
* @param {String} specialId The id of the special to retrieve.
* @param {String} venueId The id of the venue at which the special is running.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/specials/specials.html
+ * @see https://developer.foursquare.com/docs/specials/specials
*/
function getSpecial(specialId, venueId, params, accessToken, callback) {
- logger.debug("ENTERING: Specials.search");
+ logger.enter('getSpecial');
params = params || {};
if (!specialId) {
- logger.error("getSpecial: specialId is required.");
- callback(new Error("Specials.getSpecial: specialId is required."));
+ logger.error('getSpecial: specialId is required.');
+ callback(new Error('Specials.getSpecial: specialId is required.'));
return;
}
if (!venueId) {
- logger.error("getSpecial: venueId is required.");
- callback(new Error("Specials.getSpecial: venueId is required."));
+ logger.error('getSpecial: venueId is required.');
+ callback(new Error('Specials.getSpecial: venueId is required.'));
+ return;
+ }
+ logger.debug('getSpecial:specialId: ' + specialId);
+ logger.debug('getSpecial:venueId: ' + venueId);
+ logger.debug('getSpecial:params: ' + util.inspect(params));
+
+ core.callApi('/specials/search', accessToken, params, callback);
+ }
+
+ /**
+ * List Foursquare specials.
+ * @memberof module:node-foursquare/Specials
+ * @param {String} venueId The id of the venue at which the special is running.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/specials/list
+ */
+ function getList(venueId, params, accessToken, callback) {
+ logger.enter('getList');
+ params = params || {};
+
+ if (!venueId) {
+ logger.error('getList: venueId is required.');
+ callback(new Error('Specials.getList: venueId is required.'));
return;
}
+ logger.debug('getList:venueId: ' + venueId);
+ logger.debug('getList:params: ' + util.inspect(params));
+
+ core.callApi('/specials/list', accessToken, params, callback);
+ }
+
+ /**
+ * Retrieve the configuration detail for a Special.
+ * @memberof module:node-foursquare/Specials
+ * @param {String} specialId The id of the special to retrieve.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/specials/configuration
+ */
+ function getConfiguration(specialId, accessToken, callback) {
+ logger.enter('getConfiguration');
+ params = params || {};
+
+ if (!specialId) {
+ logger.error('getConfiguration: specialId is required.');
+ callback(new Error('Specials.getConfiguration: specialId is required.'));
+ return;
+ }
+
+ logger.debug('getConfiguration:specialId: ' + specialId);
- core.callApi("/specials/search", accessToken, params, callback);
+ core.callApi(path.join('/specials', specialId, 'configuation'), accessToken, {}, callback);
}
return {
- "search" : search,
- "getSpecial" : getSpecial
+ 'getConfiguration' : getConfiguration,
+ 'getSpecial' : getSpecial,
+ 'search' : search
}
};
View
112 lib/tips.js
@@ -1,34 +1,102 @@
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Tips from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Tips
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Tips");
+ var core = require('./core')(config),
+ logger = core.getLogger('tips');
/**
* Retrieve a Tip.
* @memberof module:node-foursquare/Tips
* @param {String} tipId The id of a Tip.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/tips/tips.html
+ * @see https://developer.foursquare.com/docs/tips/tips
*/
function getTip(tipId, accessToken, callback) {
- logger.debug("ENTERING: Tips.getTip");
+ logger.enter('getTip');
+
+ if(!tipId) {
+ logger.error('getTip: tipId is required.');
+ callback(new Error('Tips.getTip: tipId is required.'));
+ return;
+ }
+
+ logger.debug('getTip:tipId: ' + tipId);
+ core.callApi(path.join('/tips', tipId), accessToken, null, callback);
+ }
+ /**
+ * Retrieve the likes for a Tip.
+ * @memberof module:node-foursquare/Tips
+ * @param {String} tipId The id of a Tip.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/tips/likes
+ */
+ function getLikes(tipId, accessToken, callback) {
+ logger.enter('getLikes');
+
+ if(!tipId) {
+ logger.error('getLikes: tipId is required.');
+ callback(new Error('Tips.getLikes: tipId is required.'));
+ return;
+ }
+
+ logger.debug('getLikes:tipId: ' + tipId);
+ core.callApi(path.join('/tips', tipId, 'likes'), accessToken, null, callback);
+ }
+
+ /**
+ * Retrieve an array of users who have done a Tip.
+ * @memberof module:node-foursquare/Tips
+ * @param {String} tipId The id of a Tip.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/tips/done
+ */
+ function getDone(tipId, params, accessToken, callback) {
+ logger.enter('getDone');
+ params = params || {};
+
+ if(!tipId) {
+ logger.error('getDone: tipId is required.');
+ callback(new Error('Tips.getDone: tipId is required.'));
+ return;
+ }
+
+ logger.debug('getDone:tipId: ' + tipId);
+ core.callApi(path.join('/tips', tipId, 'done'), accessToken, params, callback);
+ }
+
+ /**
+ * Retrieve an array of lists where a Tip appears.
+ * @memberof module:node-foursquare/Tips
+ * @param {String} tipId The id of a Tip.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/tips/listed
+ */
+ function getListed(tipId, params, accessToken, callback) {
+ logger.enter('getLists');
+ params = params || {};
if(!tipId) {
- logger.error("getTip: tipId is required.");
- callback(new Error("Tips.getTip: tipId is required."));
+ logger.error('getLists: tipId is required.');
+ callback(new Error('Tips.getLists: tipId is required.'));
return;
}
- core.callApi(path.join("/tips", tipId), accessToken, null, callback);
+ logger.debug('getLists:tipId: ' + tipId);
+ core.callApi(path.join('/tips', tipId, 'lists'), accessToken, params, callback);
}
/**
@@ -40,24 +108,30 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see http://developer.foursquare.com/docs/tips/search.html
+ * @see http://developer.foursquare.com/docs/tips/search
*/
function search(lat, lng, params, accessToken, callback) {
- logger.debug("ENTERING: Tips.getTip");
+ logger.enter('getTip');
params = params || {};
if(!lat || !lng) {
- logger.error("getTips: Lat and Lng are both required parameters.");
- callback(new Error("searchTips: lat and lng are both required."));
+ logger.error('getTips: Lat and Lng are both required parameters.');
+ callback(new Error('searchTips: lat and lng are both required.'));
return;
}
- params.ll = lat + "," + lng;
+ logger.debug('search:lat: ' + lat);
+ logger.debug('search:lng: ' + lng);
+ logger.debug('search:params: ' + util.inspect(params));
+ params.ll = lat + ',' + lng;
- core.callApi("/tips/search", accessToken, params, callback);
+ core.callApi('/tips/search', accessToken, params, callback);
}
return {
- "getTip" : getTip,
- "search" : search
+ 'getDone' : getDone,
+ 'getLikes' : getLikes,
+ 'getListed' : getListed,
+ 'getTip' : getTip,
+ 'search' : search
}
};
View
30 lib/updates.js
@@ -1,15 +1,15 @@
+
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Updates and Notifications from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Updates
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require("path"),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Updates");
+ var core = require('./core')(config),
+ logger = core.getLogger('updates');
/**
* Retrieve an Update.
@@ -20,15 +20,16 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/updates/updates.html
*/
function getUpdate(updateId, accessToken, callback) {
- logger.debug("ENTERING: Updates.getUpdate");
+ logger.enter('getUpdate');
if(!updateId) {
- logger.error("getUpdate: updateId is required.");
- callback(new Error("Updates.getUpdate: updateId is required."));
+ logger.error('getUpdate: updateId is required.');
+ callback(new Error('Updates.getUpdate: updateId is required.'));
return;
}
- core.callApi(path.join("/updates", updateId), accessToken, null, callback);
+ logger.debug('getUpdate:updateId: ' + updateId);
+ core.callApi(path.join('/updates', updateId), accessToken, null, callback);
}
/**
* Retrieve notifications for the current user.
@@ -40,12 +41,13 @@ module.exports = function(config) {
* @see https://developer.foursquare.com/docs/updates/notifications.html
*/
function getNotifications(params, accessToken, callback) {
- logger.debug("ENTERING: Updates.getNotifications");
- core.callApi("/updates/notifications", accessToken, params || {}, callback);
+ logger.enter('getNotifications');
+ logger.debug('getNotifications:params: ' + util.inspect(params));
+ core.callApi('/updates/notifications', accessToken, params || {}, callback);
}
return {
- "getUpdate" : getUpdate,
- "getNotifications" : getNotifications
+ 'getUpdate' : getUpdate,
+ 'getNotifications' : getNotifications
}
};
View
185 lib/users.js
@@ -1,27 +1,27 @@
+var util = require('util');
+
/**
* A module for retrieving information about Users from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Users
*/
module.exports = function(config) {
- var core = require("./core")(config),
- log4js = require("log4js");
+ var core = require('./core')(config),
+ logger = core.getLogger('users');
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Users");
-
/**
* Returns the leaderboard for the User identified by the supplied accessToken.
* @memberof module:node-foursquare/Users
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/leaderboard.html
+ * @see https://developer.foursquare.com/docs/users/leaderboard
*/
function getLeaderboard(params, accessToken, callback) {
- logger.debug("ENTERING: Users.getLeaderboard");
- core.callApi("/users/leaderboard", accessToken, params || {}, callback);
+ logger.enter('getLeaderboard');
+ logger.debug('getLeaderboard:params: ' + util.inspect(params));
+ core.callApi('/users/leaderboard', accessToken, params || {}, callback);
}
/**
@@ -31,11 +31,12 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/search.html
+ * @see https://developer.foursquare.com/docs/users/search
*/
function search(params, accessToken, callback) {
- logger.debug("ENTERING: Users.search");
- core.callApi("/users/search", accessToken, params || {}, callback);
+ logger.enter('search');
+ logger.debug('search:params: ' + util.inspect(params));
+ core.callApi('/users/search', accessToken, params || {}, callback);
}
@@ -44,11 +45,11 @@ module.exports = function(config) {
* @memberof module:node-foursquare/Users
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/requests.html
+ * @see https://developer.foursquare.com/docs/users/requests
*/
function getRequests(accessToken, callback) {
- logger.debug("ENTERING: Users.getRequests");
- core.callApi("/users/requests", accessToken, {}, callback);
+ logger.enter('getRequests');
+ core.callApi('/users/requests', accessToken, {}, callback);
}
/**
@@ -57,166 +58,218 @@ module.exports = function(config) {
* @param {String} userId The id of the User to retreive.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/users.html
+ * @see https://developer.foursquare.com/docs/users/users
*/
function getUser(userId, accessToken, callback) {
- logger.debug("ENTERING: Users.getUser");
+ logger.enter('getUser');
if(!userId) {
- logger.error("getUser: userId is required.");
- callback(new Error("Users.getUser: userId is required."));
+ logger.error('getUser: userId is required.');
+ callback(new Error('Users.getUser: userId is required.'));
return;
}
- core.callApi("/users/" + userId, accessToken, null, callback);
+ logger.debug('getUser:userId: ' + userId);
+ core.callApi('/users/' + userId, accessToken, null, callback);
}
/**
* Retreive a named aspect for a User from the Foursquare API.
* @memberof module:node-foursquare/Users
* @param {String} aspect The aspect to retrieve. Refer to Foursquare documentation for details on currently
* supported aspects.
- * @param {String} [userId="self"] The id of the User to retreive.
+ * @param {String} [userId='self'] The id of the User to retreive.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/index_docs.html
+ * @see https://developer.foursquare.com/docs/index_docs
*/
function getUserAspect(aspect, userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getUser");
+ logger.enter('getUser');
if(!aspect) {
- logger.error("getUserAspect: aspect is required.");
- callback(new Error("Users.getUserAspect: aspect is required."));
+ logger.error('getUserAspect: aspect is required.');
+ callback(new Error('Users.getUserAspect: aspect is required.'));
return;
}
+ logger.debug('getUserAspect:aspect,userId: ' + aspect + ',' + userId);
+ logger.debug('getUserAspect:params: ' + util.inspect(params));
- core.callApi("/users/" + (userId || "self") + "/" + aspect, accessToken, params, callback);
+ core.callApi('/users/' + (userId || 'self') + '/' + aspect, accessToken, params, callback);
}
/**
* Retrieve a list of badges.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/badges.html
+ * @see https://developer.foursquare.com/docs/users/badges
*/
function getBadges(userId, accessToken, callback) {
- logger.debug("ENTERING: Users.getBadges");
- getUserAspect("badges", userId, null, accessToken, callback);
+ logger.enter('getBadges');
+ logger.debug('getBadges:userId ' + userId);
+ getUserAspect('badges', userId, null, accessToken, callback);
}
/**
* Retrieve Check-ins for a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/checkins.html
+ * @see https://developer.foursquare.com/docs/users/checkins
*/
function getCheckins(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getCheckins");
- getUserAspect("checkins", userId, params, accessToken, callback);
+ logger.enter('getCheckins');
+ logger.debug('getCheckins:params: ' + util.inspect(params));
+ getUserAspect('checkins', userId, params, accessToken, callback);
}
/**
* Retrieve Friends for a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/friends.html
+ * @see https://developer.foursquare.com/docs/users/friends
*/
function getFriends(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getFriends");
- getUserAspect("friends", userId, params, accessToken, callback);
+ logger.enter('getFriends');
+ logger.debug('getFriends:params: ' + util.inspect(params));
+ getUserAspect('friends', userId, params, accessToken, callback);
}
/**
* Retrieve Friends for a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/friends.html
+ * @see https://developer.foursquare.com/docs/users/friends
*/
function getMayorships(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getMayorships");
- getUserAspect("mayorships", userId, params, accessToken, callback);
+ logger.enter('getMayorships');
+ logger.debug('getMayorships:userId: ' + userId);
+ logger.debug('getMayorships:params: ' + util.inspect(params));
+ getUserAspect('mayorships', userId, params, accessToken, callback);
+ }
+
+
+ /**
+ * Retrieve Lists for a Foursquare User.
+ * @memberof module:node-foursquare/Users
+ * @param {String} [userId='self'] The id of the user.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} accessToken The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/users/lists
+ */
+ function getLists(userId, params, accessToken, callback) {
+ logger.enter('getLists');
+ logger.debug('getLists:userId: ' + userId);
+ logger.debug('getLists:params: ' + util.inspect(params));
+ getUserAspect('lists', userId, params, accessToken, callback);
+ }
+
+
+ /**
+ * Retrieve Photos for a Foursquare User.
+ * @memberof module:node-foursquare/Users
+ * @param {String} [userId='self'] The id of the user.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} accessToken The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/users/lists
+ */
+ function getPhotos(userId, params, accessToken, callback) {
+ logger.enter('getPhotos');
+ logger.debug('getPhotos:userId: ' + userId);
+ logger.debug('getPhotos:params: ' + util.inspect(params));
+ getUserAspect('photos', userId, params, accessToken, callback);
}
/**
* Retrieve Tips for a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String|Number} [params.lat] The latitude of the location around which to search.
* @param {String|Number} [params.lng] The longitude of the location around which to search.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/tips.html
+ * @see https://developer.foursquare.com/docs/users/tips
*/
function getTips(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getTips");
- getUserAspect("tips", userId, params, accessToken, callback);
+ logger.enter('getTips');
+ logger.debug('getTips:userId: ' + userId);
+ logger.debug('getTips:params: ' + util.inspect(params));
+ getUserAspect('tips', userId, params, accessToken, callback);
}
/**
* Retrieve Todos for a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String|Number} [params.lat] The latitude of the location around which to search.
* @param {String|Number} [params.lng] The longitude of the location around which to search.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/todos.html
+ * @see https://developer.foursquare.com/docs/users/todos
*/
function getTodos(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getTodos");
+ logger.enter('getTodos');
params = params || {};
- params.sort = params.sort || "recent";
- getUserAspect("todos", userId, params, accessToken, callback);
+ params.sort = params.sort || 'recent';
+ logger.debug('getTodos:userId: ' + userId);
+ logger.debug('getTodos:params: ' + util.inspect(params));
+ getUserAspect('todos', userId, params, accessToken, callback);
}
/**
* Retrieve Venues visited by a Foursquare User.
* @memberof module:node-foursquare/Users
- * @param {String} [userId="self"] The id of the user.
+ * @param {String} [userId='self'] The id of the user.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} accessToken The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/users/venuehistory.html
+ * @see https://developer.foursquare.com/docs/users/venuehistory
*/
function getVenueHistory(userId, params, accessToken, callback) {
- logger.debug("ENTERING: Users.getVenueHistory");
- getUserAspect("venuehistory", userId, params, accessToken, callback);
+ logger.enter('getVenueHistory');
+ logger.debug('getVenueHistory:userId: ' + userId);
+ logger.debug('getVenueHistory:params: ' + util.inspect(params));
+ getUserAspect('venuehistory', userId, params, accessToken, callback);
}
return {
- "getLeaderboard" : getLeaderboard,
- "search" : search,
- "getRequests" : getRequests,
- "getUser" : getUser,
- "getUserAspect" : getUserAspect,
- "getBadges" : getBadges,
- "getCheckins" : getCheckins,
- "getFriends" : getFriends,
- "getMayorships" : getMayorships,
- "getTips" : getTips,
- "getTodos" : getTodos,
- "getVenueHistory" : getVenueHistory
+ 'getBadges' : getBadges,
+ 'getCheckins' : getCheckins,
+ 'getFriends' : getFriends,
+ 'getLeaderboard' : getLeaderboard,
+ 'getLists' : getLists,
+ 'getMayorships' : getMayorships,
+ 'getPhotos' : getPhotos,
+ 'getRequests' : getRequests,
+ 'getTips' : getTips,
+ 'getTodos' : getTodos,
+ 'getUser' : getUser,
+ 'getUserAspect' : getUserAspect,
+ 'getVenueHistory' : getVenueHistory,
+ 'search' : search
}
};
View
396 lib/venues.js
@@ -1,15 +1,14 @@
+var path = require('path'),
+ util = require('util');
+
/**
* A module for retrieving information about Venues from Foursquare.
* @param {Object} config A valid configuration.
* @module node-foursquare/Venues
*/
module.exports = function(config) {
- var core = require("./core")(config),
- path = require('path'),
- log4js = require("log4js");
-
- log4js.configure(config.log4js);
- var logger = log4js.getLogger("node-foursquare.Venues");
+ var core = require('./core')(config),
+ logger = core.getLogger('venues');
/**
* Retrieve a list of Venue Categories.
@@ -18,11 +17,12 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/categories.html
+ * @see https://developer.foursquare.com/docs/venues/categories
*/
function getCategories(params, accessToken, callback) {
- logger.debug("ENTERING: Venues.getCategories");
- core.callApi("/venues/categories", accessToken, params || {}, callback);
+ logger.enter('getCategories');
+ logger.debug('getCategories:params: ' + util.inspect(params));
+ core.callApi('/venues/categories', accessToken, params || {}, callback);
}
/**
@@ -34,56 +34,56 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/explore.html
+ * @see https://developer.foursquare.com/docs/venues/explore
*/
function explore(lat, lng, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.explore");
+ logger.enter('explore');
params = params || {};
if(!lat || !lng) {
- logger.error("Lat and Lng are both required parameters.");
- callback(new Error("Venues.explore: lat and lng are both required."));
+ logger.error('Lat and Lng are both required parameters.');
+ callback(new Error('Venues.explore: lat and lng are both required.'));
return;
}
- params.ll = lat + "," + lng;
+ logger.debug('explore:params: ' + util.inspect(params));
+ params.ll = lat + ',' + lng;
- core.callApi("/venues/explore", accessToken, params, callback);
+ core.callApi('/venues/explore', accessToken, params, callback);
}
/**
* Search Foursquare Venues.
* @memberof module:node-foursquare/Venues
* @param {String|Number} lat The latitude of the location around which to search.
* @param {String|Number} lng The longitude of the location around which to search.
- * @param {String} near The string representation of a location in "Anytown, CA" format.
+ * @param {String} near The string representation of a location in 'Anytown, CA' format.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/search.html
+ * @see https://developer.foursquare.com/docs/venues/search
*/
function search(lat, lng, near, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.search");
+ logger.enter('search');
params = params || {};
if(!lat || !lng) {
if(!near) {
- logger.error("Either lat and lng or near are required as parameters.");
- callback(new Error("Venues.explore: near must be specified if lat and lng are not set."));
+ logger.error('Either lat and lng or near are required as parameters.');
+ callback(new Error('Venues.explore: near must be specified if lat and lng are not set.'));
return;
} else {
params.near = near;
}
- //logger.error("Lat and Lng are both required parameters.");
- //callback(new Error("Venues.explore: lat and lng are both required."));
- //return;
-
} else {
-
-
- params.ll = lat + "," + lng;
+ params.ll = lat + ',' + lng;
}
- core.callApi("/venues/search", accessToken, params, callback);
+
+ logger.debug('search:lat: ' + lat);
+ logger.debug('search:lng: ' + lng);
+ logger.debug('search:near: ' + near);
+ logger.debug('search:params: ' + util.inspect(params));
+ core.callApi('/venues/search', accessToken, params, callback);
}
/**
@@ -95,20 +95,23 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/trending.html
+ * @see https://developer.foursquare.com/docs/venues/trending
*/
function getTrending(lat, lng, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.trending");
+ logger.enter('trending');
params = params || {};
if(!lat || !lng) {
- logger.error("Lat and Lng are both required parameters.");
- callback(new Error("Venues.explore: lat and lng are both required."));
+ logger.error('Lat and Lng are both required parameters.');
+ callback(new Error('Venues.explore: lat and lng are both required.'));
return;
}
- params.ll = lat + "," + lng;
- core.callApi("/venues/trending", accessToken, params, callback);
+ logger.debug('search:lat: ' + lat);
+ logger.debug('search:lng: ' + lng);
+ logger.debug('getTrending:params: ' + util.inspect(params));
+ params.ll = lat + ',' + lng;
+ core.callApi('/venues/trending', accessToken, params, callback);
}
/**
@@ -117,18 +120,19 @@ module.exports = function(config) {
* @param {String} venueId The id of a Foursquare Venue.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/venues.html
+ * @see https://developer.foursquare.com/docs/venues/venues
*/
function getVenue(venueId, accessToken, callback) {
- logger.debug("ENTERING: Venues.getVenue");
+ logger.enter('getVenue');
if (!venueId) {
- logger.error("getVenue: venueId is required.");
- callback(new Error("Venues.getVenue: venueId is required."));
+ logger.error('getVenue: venueId is required.');
+ callback(new Error('Venues.getVenue: venueId is required.'));
return;
}
- core.callApi(path.join("/venues", venueId), accessToken, null, callback);
+ logger.debug('getVenue:venueId: ' + venueId);
+ core.callApi(path.join('/venues', venueId), accessToken, null, callback);
}
/**
@@ -141,46 +145,51 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/index_docs.html
+ * @see https://developer.foursquare.com/docs/index_docs
*/
function getVenueAspect(venueId, aspect, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.getVenueAspect");
+ logger.enter('getVenueAspect');
if (!venueId) {
- logger.error("getVenueAspect: venueId is required.");
- callback(new Error("Venues.getVenueAspect: venueId is required."));
+ logger.error('getVenueAspect: venueId is required.');
+ callback(new Error('Venues.getVenueAspect: venueId is required.'));
return;
}
if (!aspect) {
- logger.error("getVenueAspect: aspect is required.");
- callback(new Error("Venues.getVenueAspect: aspect is required."));
+ logger.error('getVenueAspect: aspect is required.');
+ callback(new Error('Venues.getVenueAspect: aspect is required.'));
return;
}
- core.callApi(path.join("/venues", venueId, aspect), accessToken, params || {}, callback);
+ logger.debug('getVenueAspect:venueId: ' + venueId);
+ logger.debug('getVenueAspect:aspect: ' + aspect);
+ logger.debug('getVenueAspect:params: ' + util.inspect(params));
+ core.callApi(path.join('/venues', venueId, aspect), accessToken, params || {}, callback);
}
/**
- * Retrieve Check-ins for Users who are at a Venue "now".
+ * Retrieve Check-ins for Users who are at a Venue 'now'.
* @memberof module:node-foursquare/Venues
* @param {String} venueId The id of a Foursquare Venue.
* @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/herenow.html
+ * @see https://developer.foursquare.com/docs/venues/herenow
*/
function getHereNow(venueId, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.getHereNow");
+ logger.enter('getHereNow');
if (!venueId) {
- logger.error("getHereNow: venueId is required.");
- callback(new Error("Venues.getHereNow: venueId is required."));
+ logger.error('getHereNow: venueId is required.');
+ callback(new Error('Venues.getHereNow: venueId is required.'));
return;
}
- core.callApi(path.join("/venues", venueId, "herenow"), accessToken, params || {}, callback);
+ logger.debug('getHereNow:venueId: ' + venueId);
+ logger.debug('getHereNow:params: ' + util.inspect(params));
+ core.callApi(path.join('/venues', venueId, 'herenow'), accessToken, params || {}, callback);
}
/**
@@ -191,68 +200,261 @@ module.exports = function(config) {
* on currently supported parameters.
* @param {String} [accessToken] The access token provided by Foursquare for the current user.
* @param {Function} callback The function to call with results, function({Error} error, {Object} results).
- * @see https://developer.foursquare.com/docs/venues/tips.html
+ * @see https://developer.foursquare.com/docs/venues/tips
*/
function getTips(venueId, params, accessToken, callback) {
- logger.debug("ENTERING: Venues.getTips");
+ logger.enter('getTips');
+
+ if (!venueId) {
+ logger.error('getTips: venueId is required.');
+ callback(new Error('Venues.getTips: venueId is required.'));
+ return;
+ }
+
+ logger.debug('getTips:venueId: ' + venueId);
+ logger.debug('getTips:params: ' + util.inspect(params));
+ getVenueAspect(venueId, 'tips', params, accessToken, callback)
+ }
+
+ /**
+ * Retrieve Lists where a Foursquare Venue is listed.
+ * @memberof module:node-foursquare/Venues
+ * @param {String} venueId The id of a Foursquare Venue.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/venues/listed
+ */
+ function getListed(venueId, params, accessToken, callback) {
+ logger.enter('getLists');
+
+ if (!venueId) {
+ logger.error('getLists: venueId is required.');
+ callback(new Error('Venues.getLists: venueId is required.'));
+ return;
+ }
+
+ logger.debug('getLists:venueId: ' + venueId);
+ logger.debug('getLists:params: ' + util.inspect(params));
+ getVenueAspect(venueId, 'lists', params, accessToken, callback)
+ }
+
+ /**
+ * Retrieve Stats for a Foursquare Venue.
+ * @memberof module:node-foursquare/Venues
+ * @param {String} venueId The id of a Foursquare Venue.
+ * @param {Object} [params] An object containing additional parameters. Refer to Foursquare documentation for details
+ * on currently supported parameters.
+ * @param {String} [accessToken] The access token provided by Foursquare for the current user.
+ * @param {Function} callback The function to call with results, function({Error} error, {Object} results).
+ * @see https://developer.foursquare.com/docs/venues/stats
+ */
+ function getStats(venueId, params, accessToken, callback) {
+ logger.enter('getStats');
if (!venueId) {
- logger.error("getTips: venueId is required.");
- callback(new Error("Venues.getTips: venueId is required."));
+ logger.error('getStats: venueId is required.');
+ callback(new Error('Venues.getStats: venueId is required.'));
return;
}
- getVenueAspect(venueId, "tips", params, accessToken, callback)
+ logger.debug('getStats:venueId: ' + venueId);
+ logger.debug('getStats:params: ' + util.inspect(params));
+ getVenueAspect(venueId, 'stats', params, accessToken, callback)
}
/**
* Retrieve Photos for a Foursquare Venue.
* @memberof module:node-foursquare/Venues
* @param {String} venueId The id of a Foursquare Venue.
- * @param {String} [group="venue"] The type of photos to retrieve. Refer to Foursquare documentation for details
+ * @param {String} [group='venue'] The type of photos to retrieve. Refer to Foursquare documentation for details