Skip to content

@ayoung /client.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
closure problem
var rest = require('restler');
function Client(baseUrl) {
if (this instanceof Client) {
this.baseUrl = baseUrl;
}
else {
return new Client(baseUrl);
}
};
/*
* Performs an HTTP get to the given path.
* @param {string} path: the url to get
* @param {object} data: the data to send
* @param {function} callback: the callback to run on complete.
* if null it will run this.callback
*/
Client.prototype.get = function(path) {
var self = this;
return function() {
rest.get(self.baseUrl + path).on('complete', this.callback);
}
};
/*
* Performs an HTTP post to the given path.
* @param {string} path: the url to post to
* @param {object} data: the data to send
* @param {function} callback: the callback to run on complete.
* if null it will run this.callback
*/
Client.prototype.post = function(path, data, callback) {
var self = this;
var cb = callback;
return function() {
console.log(path);
console.log(cb);
rest.post(self.baseUrl + path, data).on('complete', cb || this.callback);
}
};
/*
* Performs an HTTP post to the given path.
* @param {string} path: the url to post to
* @param {object} data: the data to send
* @param {function} callback: the callback to run on complete.
* if null it will run this.callback
*/
Client.prototype.put = function(path, data) {
var self = this;
return function() {
rest.put(self.baseUrl + path, data).on('complete', this.callback);
}
};
module.exports = Client;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.