Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. <?php
  2.  
  3. class ZenDesk {
  4.  
  5. private static $ZDAPIKEY = "anJEpMqgTGsrOEqIKsHrp5yCS35yz7bcRrQ9Trgg";
  6. private static $ZDUSER = "marcos.dordetti@eduzz.com";
  7. private static $ZDPASSWORD = "7!JGRUPP#Zend";
  8. private static $ZDURL = "https://eduzz.zendesk.com/api/v2";
  9.  
  10. /* Note: do not put a trailing slash at the end of v2 */
  11.  
  12. public function __construct()
  13. { }
  14.  
  15. public function curlWrap($url, $json, $action, $sufix = '')
  16. {
  17. $ch = curl_init();
  18. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  19. curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
  20. curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url.$sufix);
  21. curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
  22. switch($action){
  23. case "POST":
  24. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  25. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  26. break;
  27. case "GET":
  28. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  29. break;
  30. case "PUT":
  31. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  32. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  33. break;
  34. case "DELETE":
  35. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  36. break;
  37. default:
  38. break;
  39. }
  40.  
  41. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  42. curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
  43. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  44. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  45. $output = curl_exec($ch);
  46.  
  47. curl_close($ch);
  48. $decoded = json_decode($output);
  49. return $decoded;
  50. }
  51.  
  52. public function curlUpload($url,$baseurl, $name)
  53. {
  54.  
  55. // upload file info
  56. $fileName = $name;
  57. $filePath = $baseurl."uploads/attachments/".$fileName;
  58.  
  59. $fildata = file_get_contents($filePath);
  60.  
  61. $ch = curl_init();
  62. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  63. curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
  64. curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url);
  65. curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
  66.  
  67. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  68. curl_setopt($ch, CURLOPT_POSTFIELDS, $fildata);
  69. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/binary','Accept: application/json'));
  70.  
  71. curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
  72. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  73. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  74. $output = curl_exec($ch);
  75.  
  76. curl_close($ch);
  77. $decoded = json_decode($output);
  78. return $decoded;
  79. }
  80.  
  81.  
  82. public function curlJson($url, $json, $action, $sufix = '')
  83. {
  84. $ch = curl_init();
  85. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  86. curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
  87. curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url.$sufix);
  88. curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
  89. switch($action){
  90. case "POST":
  91. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  92. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  93. break;
  94. case "GET":
  95. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  96. break;
  97. case "PUT":
  98. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  99. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  100. break;
  101. case "DELETE":
  102. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  103. break;
  104. default:
  105. break;
  106. }
  107.  
  108. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  109. curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
  110. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  111. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  112. $output = curl_exec($ch);
  113. curl_close($ch);
  114. return $output;
  115. }
  116. }
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement