Created
November 8, 2012 13:38
-
-
Save ilbambino/4038850 to your computer and use it in GitHub Desktop.
JavaScript StackMob SDK using OAuth 1.0
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
_.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' | |
} | |
); |
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
You can also do:
https://api.stackmob.com
if you'd like SSL :)