Skip to content

Commit

Permalink
httpResponses returns in adapter for both error and success - Readme …
Browse files Browse the repository at this point in the history
…updated.
  • Loading branch information
stereoket committed Jun 24, 2011
1 parent c1668f6 commit 57731cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 22 additions & 14 deletions oauth_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,37 +562,45 @@ Ti.API.debug('access Tokens: ' + accessToken + ':' + accessTokenSecret);
Ti.API.debug('url for GET:' + pUrl);
}
var client = Ti.Network.createHTTPClient();
Ti.API.debug('Network client setup');

Ti.API.info('Network client for sending oAuth POST/GET request');
client.setTimeout(25000);
client.onerror = function(e){
Ti.API.debug('Error Found');
Ti.API.debug(e);
if(params.onError){
params.onError(e);
}
Ti.API.debug('Error Returned from Server');
Ti.API.debug('Status:'+client.status);
Ti.API.debug(e);
if(params.onError){
params.onError(e);
}
};
client.onload = function(){
Ti.API.info('connection load');
Ti.API.debug('*** sendStatus, Response: [' + client.status + '] ' + client.responseText);
if (('' + client.status).match(/^20[0-9]/)) {
if(params.onSuccess){
params.onSuccess(client.responseText);
return client.responseText;
var httpResponse = {
successMessage: 'Success',
httpStatus: client.status,
responseText: client.responseText
}
return httpResponse;
};
} else {
if(params.onError){
var errorResponse = {
var httpResponse = {
errorMessage: JSON.parse(client.responseText).error,
errorStatus: client.status
httpStatus: client.status,
responseText: client.responseText
};
params.onError(errorResponse);
return client.responseText;
Ti.API.debug(httpResponse);
params.onError(httpResponse);
return httpResponse;
};
}
};
var finalUrl = OAuth.addToURL(pUrl, parameterMap);
client.open(pMethod, finalUrl, false);
Ti.API.debug('Connection Opened');
Ti.API.info('oAuth POST/GET request connection Opened');
if(stickOAuthParam){ // Google Auth
var header = makeHeaderParam(parameterMap);

Expand All @@ -603,7 +611,7 @@ Ti.API.debug('access Tokens: ' + accessToken + ':' + accessTokenSecret);
}
;
client.send();
Ti.API.debug('Request Sent');
Ti.API.info('oAuth POST/GET request Sent to network service');
return client.responseText;
};
this.send = send;
Expand Down
4 changes: 3 additions & 1 deletion readme
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ if (oa.oAuthAdapter.isAuthorized() != false) {
onSuccess:function(response){
response = JSON.parse(response);
alert(response.screen_name+' authenticated');
}
},
onError:function(response){
alert(response.errorMessage),
});
}

Expand Down

0 comments on commit 57731cb

Please sign in to comment.