Advertisement
Guest User

Untitled

a guest
Aug 25th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. global class cstschedulable implements schedulable{
  2.  
  3.  
  4. global User cstUser {get;set;}
  5. public string Idstring;
  6. public string cstUsername {get;set;}
  7. public string cstPassword {get;set;}
  8. public Id ClientAcctId {get;set;}
  9. public datetime cstLastUpdate{get;set;}
  10. public string loginstring {get;set;}
  11. public map<String, string> cstUserMap{get;set;}
  12.  
  13. global void execute(SchedulableContext sc){
  14. returnAuth();
  15. }
  16.  
  17. @future(callout=true)
  18. static void returnAuth(){
  19. string xAuthToken;
  20. string st_Today;
  21.  
  22. If (cstUser == null){
  23. User cstUser = [select Id, CST_User_Name__c,CST_Password__c, CSTlastupdate__c from User where CST_User_Name__c != null ];
  24.  
  25. if(cstUser.CST_User_Name__c == null)
  26. {
  27. system.debug('cstUser null at UserData');
  28. }
  29. else{
  30. system.debug('cstUser not null at UserData');
  31. }
  32. if(cstUser.CST_User_Name__c != null){
  33. String loginstring = ('"'+cstUser.CST_User_Name__c+'" "password": "'+cstUser.CST_Password__c+'"}');
  34. String Idstring = string.valueof(cstUser.Id);
  35. }
  36.  
  37.  
  38. if(loginstring != null){
  39.  
  40. HttpRequest req = new HttpRequest();
  41. HttpResponse res = new HttpResponse();
  42. Http http = new Http();
  43.  
  44. req.setMethod('POST' ); // Method Type
  45.  
  46. req.setEndpoint('web210.ntree.com/twig-cstc3/v1/login');//salestree url
  47.  
  48. req.setHeader('Content-Type','application/json');
  49. req.setHeader('{ "username" : ', loginstring);
  50.  
  51.  
  52. res = http.send(req);
  53.  
  54. if(res.getBody() != null){
  55. if(res.getBody() == 'Rejected: check_login returned false:'){
  56. system.debug('Rejected: check_login returned false:');
  57. }
  58.  
  59. }else{
  60. system.debug('SalesTree Failed to respond');
  61. }
  62.  
  63. if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
  64. (parser.getText() == 'st:today')){
  65. parser.nextToken();
  66. parser.nextToken();
  67. st_Today = parser.getText();
  68.  
  69. }
  70. if (xAuthToken != null){
  71. system.debug('Auth Token received');
  72. }
  73. else
  74. {
  75. system.debug('Auth Token not received');
  76. }
  77. if(xAuthToken != null){
  78. User UpdateUser = new User();
  79. UpdateUser.Id = Id.valueof(Idstring);
  80.  
  81. UpdateUser.X_Auth_token__c = xAuthToken;
  82. UpdateUser.CSTlastupdate__c = Datetime.now();
  83. Update UpdateUser;
  84.  
  85.  
  86. }
  87.  
  88. }
  89. }
  90. }
  91. }
  92. }
  93. else{
  94. system.debug('loginstring null');
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement