Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. public with sharing class calloutViewer_Controller {
  2. public String requestEndpoint {get;set;}
  3. public String accountodel {get;set;}
  4. public String createnewtask {get;set;}
  5. public String requestMethod {get;set;}
  6. public String requestBody {get;set;}
  7. public String responseStatus {get;set;}
  8. public Integer responseStatusCode {get;set;}
  9. public String responseBody {get;set;}
  10. public RFAPI.responseResource2 response2 {get;set;}
  11. deserializedQuestions {get;set;}
  12. public List<RFAPI.questionResource2> deserializedQuestions2 {get;set;}
  13. public void callout2(){
  14. httpResponse res2 = RFAPI.callout2(requestMethod, requestEndpoint, requestBody);
  15. responseStatus = res2.getStatus();
  16. responseStatusCode = res2.getStatusCode();
  17. responseBody = res2.getBody();
  18.  
  19.  
  20. public void deserializeQuestions2(){
  21. if ( string.isNotBlank(responseBody) ){
  22. response2 = (RFAPI.responseResource2)JSON.deserialize(responseBody,RFAPI.responseResource2.class);
  23. deserializedQuestions2 = response2.items2;
  24. }
  25.  
  26. }
  27.  
  28. public with sharing class RFAPI {
  29. public static String BASE_URL = 'My api url';
  30.  
  31.  
  32.  
  33. public static httpResponse callout2(String httpMethod, String endpoint, String body){
  34.  
  35. String token = 'My API token';
  36. httpRequest req = new httpRequest();
  37. req.setHeader('X-RFToken', token);
  38. req.setMethod(httpMethod);
  39. req.setEndpoint(endpoint);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. system.debug(res2.toString());
  47. system.debug(res2.getBody());
  48. return res2;
  49.  
  50. }
  51.  
  52. public static responseResource2 deserialize(httpResponse res2){
  53. return (responseResource2)JSON.deserialize(res2.getBody(),responseResource2.class);
  54.  
  55. }
  56.  
  57.  
  58. public class responseResource2 {
  59. public List<questionResource2> items2{get;set;}
  60. }
  61.  
  62. public class questionResource2 {
  63. public Timestamps timestamps {get;set;}
  64. public Counts counts {get;set;}
  65. public Entity entity {get;set;}
  66.  
  67. }
  68.  
  69.  
  70. public class Timestamps {
  71. public String firstSeen {get;set;}
  72. public String lastSeen {get;set;}
  73. }
  74.  
  75. public class Entity {
  76. public String id {get;set;}
  77. public String name {get;set;}
  78. public String type_Z {get;set;}
  79. }
  80.  
  81. public class Counts {
  82. public Integer returned {get;set;}
  83. public Integer total {get;set;}
  84. }
  85.  
  86. <apex:pageBlockSection columns="1" title="JSON Deserializer" rendered="{!deserializedQuestions2 != null}" collapsible="false" >
  87. <apex:pageBlockTable value="{!deserializedQuestions2}" var="i" >
  88. <apex:column headerValue="Owner" style="width:100px;" >
  89. </apex:column>
  90. <apex:column headerValue="Question Id" style="width:75px;" >
  91. <apex:outputText value="{!i.timestamps.firstseen}" />
  92. </apex:column>
  93. <apex:column headerValue="Creation Date" style="width:75px;" >
  94. <apex:outputText value="{!i.timestamps.lastseen}" />
  95. </apex:column>
  96. <apex:column headerValue="View Count" style="width:75px;" >
  97. <apex:outputText value="{!i.entity.id}" />
  98. </apex:column>
  99. <apex:column headerValue="Answer Count" style="width:75px;" >
  100. <apex:outputText value="{!i.entity.name}" />
  101. </apex:column>
  102. <apex:column headerValue="Score" style="width:50px;" >
  103. <apex:outputText value="{!i.entity.type_Z}" />
  104. </apex:column>
  105. <apex:column headerValue="Score" style="width:50px;" >
  106. <apex:outputText value="{!i.counts.returned}" />
  107. </apex:column>
  108. <apex:column headerValue="Score" style="width:50px;" >
  109.  
  110. </apex:column>
  111. </apex:pageBlockTable>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement