Skip to content

Commit

Permalink
Merge pull request #271 from skrenek/master
Browse files Browse the repository at this point in the history
Adjusted feather.rest calls so you can pass in (options, cb) and include...
  • Loading branch information
skrenek committed Feb 26, 2014
2 parents 452c8fa + 5ac0033 commit 3a6b2f5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/feather-client/restProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
feather.rest[api.name] = {};
_.each(api.methods, function(method) {
feather.rest[api.name][method.name] = function(path, data, cb) {
var options = null;

// Freakish hack to allow users to pass in standard function call style of func(options, cb).
// This allows us flexibility for passing more options to $.ajax in the future.
if (typeof path === "object" && typeof data === "function") {
options = path;
cb = data;
data = null;
} else {
options = {
path: path,
data: data
};
}

if (typeof data === "function") {
cb = data;
data = null;
Expand All @@ -26,10 +41,11 @@
}

$.ajax({
url: encodeURI("/_rest/" + api.name + decodeURI(path)),
data: (typeof data === "undefined" || data === null) ? null : JSON.stringify(data),
url: encodeURI("/_rest/" + api.name + decodeURI(options.path)),
data: (typeof options.data === "undefined" || options.data === null) ? null : JSON.stringify(options.data),
type: method.verb,
dataType: "json",
headers: options.headers || null,
contentType: contentType,
success: function(result) {
cb && cb({
Expand Down

0 comments on commit 3a6b2f5

Please sign in to comment.