Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Cacio committed Nov 12, 2014
1 parent d0ba353 commit 5d758a8
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/adapters/XHRJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
this.fail = null;
}

/**
* Check if an URL starts and ends with /
* @param {String} string URL
* @return {String} The fixed URL string
*/
function checkURL(string) {
if (typeof string !== 'string') {
return '/';
Expand All @@ -29,6 +34,10 @@
return string;
}

/**
* Constructor
* @param {String} url The API URL
*/
XHRJson.prototype.init = function(url) {
var self = this;

Expand All @@ -50,22 +59,43 @@
};
};

/**
* URL getter
* @return {String} URL string
*/
XHRJson.prototype.getAPIURL = function() {
return this.apiUrl;
};

/**
* Callback which is if the request is done
* @param {Function} callback Callback function
* @return {Object} Mjs
*/
XHRJson.prototype.onDone = function(callback) {
this.done = callback;

return this;
};

/**
* Callback which is if the request failed
* @param {Function} callback Callback function
* @return {Object} Mjs
*/
XHRJson.prototype.onFail = function(callback) {
this.fail = callback;

return this;
};

/**
* Perform an AJAX request
* @param {String} method HTTP method
* @param {String} url URL string
* @param {Boolean} async
* @param {Object} data POST/PUT data
*/
XHRJson.prototype.ajax = function(method, url, async, data) {
method = method.toUpperCase();
this.xhr.open(method, this.apiUrl + url, async);
Expand Down

0 comments on commit 5d758a8

Please sign in to comment.