Permalink
Browse files

Handling request method (POST/GET)

  • Loading branch information...
1 parent 1519a21 commit 6fdbd0cfee704d74afb4f5f87129c3e6dfe42a19 @matteoagosti committed Jun 28, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/core.js
View
@@ -16,8 +16,9 @@ module.exports = function(config) {
log4js.configure(config.log4js);
var logger = log4js.getLogger("node-foursquare.core");
- function retrieve(url, callback) {
+ function retrieve(url, callback, method) {
callback = callback || emptyCallback;
+ method = 'POST' === method ? 'POST' : 'GET';
var parsedUrl = urlParser.parse(url, true), request, result = "";
@@ -29,12 +30,13 @@ module.exports = function(config) {
parsedUrl.query = {};
}
var path = parsedUrl.pathname + "?" + qs.stringify(parsedUrl.query);
+
logger.debug("Requesting: " + path);
request = https.request({
"host" : parsedUrl.hostname,
"port" : parsedUrl.port,
"path" : path,
- "method" : "GET",
+ "method" : method,
"headers" : {
"Content-Length": 0
}
@@ -54,9 +56,10 @@ module.exports = function(config) {
request.end();
}
- function invokeApi(url, accessToken, callback) {
+ function invokeApi(url, accessToken, callback, method) {
callback = callback || emptyCallback;
+ method = 'POST' === method ? 'POST' : 'GET';
var parsedUrl = urlParser.parse(url, true);
@@ -84,7 +87,7 @@ module.exports = function(config) {
logger.trace(sys.inspect(result));
callback(null, status, result);
}
- });
+ }, method);
}
function extractData(url, status, result, callback) {
@@ -136,7 +139,7 @@ module.exports = function(config) {
}
}
- function callApi(path, accessToken, params, callback) {
+ function callApi(path, accessToken, params, callback, method) {
var url = config.foursquare.apiUrl + path;
@@ -157,7 +160,7 @@ module.exports = function(config) {
logger.trace("URL: " + url);
invokeApi(url, accessToken, function(error, status, result) {
extractData(url, status, result, callback);
- });
+ }, method);
}
return {

0 comments on commit 6fdbd0c

Please sign in to comment.