Skip to content

Instantly share code, notes, and snippets.

@ilbambino
Created November 8, 2012 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ilbambino/4038850 to your computer and use it in GitHub Desktop.
Save ilbambino/4038850 to your computer and use it in GitHub Desktop.
JavaScript StackMob SDK using OAuth 1.0
_.extend(StackMob, {
'ajax': function(model, params, method) {
var oauth = new OAuth({
consumerKey: 'XXXXXXXXXXXXXXXXXXXXXX',
consumerSecret: 'XXXXXXXXXXXXXXXXXXXXXXX'}
);
var success = params['success'];
var defaultSuccess = function(response, options) {
var result = response && response.text ? JSON.parse(response.text) : null;
if(params["stackmob_count"] === true)
result = response;
StackMob.onsuccess(model, method, params, result, success);
};
var error = params['error'];
var defaultError = function(response, options) {
var responseText = response.responseText || response.text;
StackMob.onerror(response, responseText, null, model, params, error);
}
var header = params['headers'];
header['Content-Type'] = 'application/json';
oauth.request({
method : params['type'],
headers: header,
url: params['url'],
data: params['data'],
success: defaultSuccess,
failure: defaultError
});
},
'apiURL': 'http://api.stackmob.com'
}
);
@ericktai
Copy link

You can also do: https://api.stackmob.com if you'd like SSL :)

@ilbambino
Copy link
Author

there was a bug in the original code, if the content-type is not set, the POSTs fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment