Created
July 5, 2011 04:16
-
-
Save nulltask/1064246 to your computer and use it in GitHub Desktop.
twitter_api.js.diff
This file contains hidden or 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
2,4c2,8 | |
< Ti.include('./lib/sha1.js'); | |
< Ti.include('./lib/oauth.js'); | |
< Ti.include('./lib/oauth_adapter.js'); | |
--- | |
> var path_lib = ''; | |
> if(Titanium.Platform.osname == 'iphone' && Titanium.version<'1.7.0'){ | |
> path_lib = '/lib/'; | |
> } | |
> Ti.include(path_lib+'sha1.js'); | |
> Ti.include(path_lib+'oauth.js'); | |
> Ti.include(path_lib+'oauth_adapter.js'); | |
11a16,17 | |
> // Do not use queue feature of oAuthAdapter on Android. | |
> // it causes "sending message to a Handler on a dead thread" issue. | |
15c21,22 | |
< signatureMethod | |
--- | |
> signatureMethod, | |
> { useQueue:false } | |
24,27c31,37 | |
< if (params == null) { | |
< // OAuth | |
< var receivePin = function() { | |
< oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token'); | |
--- | |
> if (params.xauth) | |
> { | |
> if (params.username == null && params.password == null) | |
> { | |
> return false; | |
> } | |
> oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token', function(){ | |
28a39,47 | |
> params.callback(); | |
> }, params); | |
> } | |
> else | |
> { | |
> var receivePin = function() { | |
> oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token', function(){ | |
> oAuthAdapter.saveAccessToken('twitter'); | |
> }); | |
30,35c49,53 | |
< oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?' + | |
< oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token'), receivePin); | |
< } else { | |
< // xAuth | |
< oAuthAdapter.getAccessToken('https://api.twitter.com/oauth/access_token', params); | |
< oAuthAdapter.saveAccessToken('twitter'); | |
--- | |
> oAuthAdapter.getRequestToken('https://api.twitter.com/oauth/request_token', function(token){ | |
> if(token){ | |
> oAuthAdapter.showAuthorizeUI('https://api.twitter.com/oauth/authorize?' + token , receivePin); | |
> } | |
> }); | |
38,48c56,58 | |
< }; | |
< | |
< // delete Access Token | |
< this.deleteAccessToken = function () { | |
< this.oAuthAdapter.deleteAccessToken('twitter'); | |
< }; | |
< | |
< this.callApi = function(params){ | |
< if (!params){ | |
< Ti.API.error('twitter api params error. no params.'); | |
< return; | |
--- | |
> else | |
> { | |
> return true; | |
50,53c60,62 | |
< if (!params.url){ | |
< Ti.API.error('twitter api params error. no params.url.'); | |
< return; | |
< }; | |
--- | |
> }; | |
> | |
> this._callApi = function(params){ | |
77c86 | |
< | |
--- | |
> if (!oAuthAdapter.isAuthorized()) { return; } | |
85a95,96 | |
> }else{ | |
> Ti.API.error('no success handler'); | |
91a103 | |
> Ti.API.error('no error handler'); | |
96a109,132 | |
> this.callApi = function(params){ | |
> if (!params){ | |
> Ti.API.error('twitter api params error. no params.'); | |
> return false; | |
> } | |
> if (!params.url){ | |
> Ti.API.error('twitter api params error. no params.url.'); | |
> return false; | |
> }; | |
> // implement queue feature by myself. see init() function comment. | |
> if (this.oAuthAdapter.isAuthorized()){ | |
> return self._callApi(params); | |
> }else{ | |
> setTimeout( function(){ self.callApi(params); } , 1000 ); | |
> } | |
> }; | |
> | |
> this.clear_accesstoken = function(){ | |
> self.oAuthAdapter.clearAccessToken('twitter'); | |
> }; | |
> | |
> this.clear_actionsqueue = function(){ | |
> self.oAuthAdapter.clearActionsQueue(); | |
> }; | |
197c233 | |
< params.method = 'POST'; | |
--- | |
> params.method = 'GET'; | |
340,341c376 | |
< params.url = 'http://api.twitter.com/version/friendships/create.json'; | |
< // params.method = 'GET'; | |
--- | |
> params.url = 'http://api.twitter.com/1/friendships/create.json'; | |
372c407 | |
< params.url = 'http://api.twitter.com/version/account/verify_credentials.json'; | |
--- | |
> params.url = 'http://api.twitter.com/1/account/verify_credentials.json'; | |
404c439,456 | |
< return self.callApi(params); | |
--- | |
> | |
> var parameters =[]; | |
> if (params.parameters){ | |
> for(var key in params.parameters){ | |
> parameters.push( [key, params.parameters[key]] ); | |
> }; | |
> }; | |
> | |
> var oAuthAdapter = this.oAuthAdapter; | |
> oAuthAdapter.loadAccessToken('twitter'); | |
> var response = oAuthAdapter.sendMultiPart( | |
> params.url, | |
> "", | |
> parameters, | |
> params.title, | |
> params.success_message, | |
> params.failed_message | |
> ) | |
415c467 | |
< params.url = 'http://api.twitter.com/version/favorites.json'; | |
--- | |
> params.url = 'http://api.twitter.com/1/favorites.json'; | |
458c510 | |
< this.blocks_blocking = function(params){ | |
--- | |
> this.blocks_blocking_ids = function(params){ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment