Permalink
Browse files

Making Connection#request body optional and cleaning up methods

  • Loading branch information...
1 parent 094eeaf commit f60730e313c945d3b64d839c4df8db043da24bae @mrduncan mrduncan committed Jan 29, 2011
Showing with 6 additions and 16 deletions.
  1. +6 −16 lib/ranger/connection.js
View
@@ -69,12 +69,17 @@ exports.Connection = function (account, token) {
* Performs a request on the connection.
* @param {string} method The http request method.
* @param {string} path The path to request.
- * @param {Object} body The object to send as the body of the request.
+ * @param {Object=} body The object to send as the body of the request.
* @param {function()=} callback The callback to call when the request completes.
*/
this.request = function (method, path, body, callback) {
var headers, jsonBody, client, request;
+ if (typeof body === "function") {
+ callback = body;
+ body = null;
+ }
+
headers = {
"Authorization": authorization,
"Host": account + ".campfirenow.com",
@@ -135,11 +140,6 @@ exports.Connection = function (account, token) {
* @param {function()=} callback The optional function to call when the request completes.
*/
this.get = function (path, params, callback) {
- if (typeof params === "function") {
- callback = params;
- params = null;
- }
-
this.request("GET", path, params, callback);
};
@@ -150,11 +150,6 @@ exports.Connection = function (account, token) {
* @param {function()=} callback The function to call when the request completes.
*/
this.post = function (path, body, callback) {
- if (typeof body === "function") {
- callback = body;
- body = null;
- }
-
this.request("POST", path, body, callback);
};
@@ -165,11 +160,6 @@ exports.Connection = function (account, token) {
* @param {function()=} callback The function to call when the request completes.
*/
this.put = function (path, body, callback) {
- if (typeof body === "function") {
- callback = body;
- body = null;
- }
-
this.request("PUT", path, body, callback);
};

0 comments on commit f60730e

Please sign in to comment.