Guest User

Untitled

a guest
Jan 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /**
  2. * modifications by Micael Estrazulas
  3. * @param pUrl
  4. * @param pParameters
  5. * @return responseText
  6. */
  7. var sendWithReturn = function(pUrl, pParameters)
  8. {
  9. Ti.API.debug('Sending a message to the service at [' + pUrl + '] with the following params: ' + JSON.stringify(pParameters));
  10.  
  11. if (accessToken == null || accessTokenSecret == null)
  12. {
  13.  
  14. Ti.API.debug('The send status cannot be processed as the client doesn\'t have an access token. The status update will be sent as soon as the client has an access token.');
  15.  
  16. actionsQueue.push({
  17. url: pUrl,
  18. parameters: pParameters,
  19. title: pTitle,
  20. successMessage: pSuccessMessage,
  21. errorMessage: pErrorMessage
  22. });
  23. return;
  24. }
  25.  
  26. accessor.tokenSecret = accessTokenSecret;
  27.  
  28. var message = createMessage(pUrl);
  29. message.parameters.push(['oauth_token', accessToken]);
  30. for (p in pParameters) {
  31. message.parameters.push(pParameters[p]);
  32. }
  33. OAuth.setTimestampAndNonce(message);
  34. OAuth.SignatureMethod.sign(message, accessor);
  35.  
  36. var parameterMap = OAuth.getParameterMap(message.parameters);
  37. var client = Ti.Network.createHTTPClient();
  38.  
  39. var params = "?oauth_version=1";
  40. // var params = {};
  41. for (var p in parameterMap) {
  42. Ti.API.debug(p + ': ' + parameterMap[p]);
  43. // eval("params."+p+" = parameterMap[p]");
  44. params += "&"+p+"="+escape(parameterMap[p]);
  45. // client.setRequestHeader("OAuth",params)
  46. }
  47. Ti.API.info(params);
  48.  
  49. client.open('GET', pUrl+params, false);
  50. // client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  51. // client.send(params);
  52. client.onload = function() {
  53.  
  54. Ti.API.info(client.responseText);
  55. if (client.status == 200) {
  56. return client.responseText;
  57.  
  58. } else {
  59. return false;
  60. }
  61. };
  62. Ti.API.debug('*** sendStatus, Response: [' + client.status + '] ' + client.responseText);
  63.  
  64. return client.responseText;
  65.  
  66. };
Add Comment
Please, Sign In to add comment