Created
February 24, 2012 19:14
-
-
Save BFalkner/1903065 to your computer and use it in GitHub Desktop.
JavaScript has bad functional/monadic syntax.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
_ajax: function(path, method, data, retry) { | |
var self = this; | |
var response = self._session.pipe(function(session) { | |
return $.ajax({ | |
type: method || "GET", | |
url: SalesForceSettings.proxyUrl, | |
cache: false, | |
processData: false, | |
data: data, | |
contentType: "application/json", | |
dataType: "json", | |
headers: { | |
"SalesforceProxy-Endpoint": session.serverUrl + "/services/data" + path, | |
"X-Authorization": "OAuth " + session.sessionId, | |
"X-User-Agent": "salesforce-toolkit-rest-javascript/" + SalesForceSettings.apiVersion | |
} | |
}); | |
}); | |
// Only return the first argument. | |
if (retry) return response.pipe(function(json) { return json; }); | |
return response.pipe( | |
function(json) { return json; }, | |
function(jqXHR) { | |
if (jqXHR.status === 401) { | |
return self._session.pipe(function(session) { | |
return self._login(session.user.username, | |
session.user.password, | |
session.user.securityToken) | |
.pipe(function() { return self._ajax(path, method, data, true); }); | |
}); | |
} else { | |
return $.parseJSON(jqXHR.responseText)[0]; | |
} | |
}).promise(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment