Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ZenDesk {
- private static $ZDAPIKEY = "anJEpMqgTGsrOEqIKsHrp5yCS35yz7bcRrQ9Trgg";
- private static $ZDUSER = "marcos.dordetti@eduzz.com";
- private static $ZDPASSWORD = "7!JGRUPP#Zend";
- private static $ZDURL = "https://eduzz.zendesk.com/api/v2";
- /* Note: do not put a trailing slash at the end of v2 */
- public function __construct()
- { }
- public function curlWrap($url, $json, $action, $sufix = '')
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
- curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url.$sufix);
- curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
- switch($action){
- case "POST":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
- break;
- case "GET":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
- break;
- case "PUT":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
- break;
- case "DELETE":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
- break;
- default:
- break;
- }
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
- curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- $output = curl_exec($ch);
- curl_close($ch);
- $decoded = json_decode($output);
- return $decoded;
- }
- public function curlUpload($url,$baseurl, $name)
- {
- // upload file info
- $fileName = $name;
- $filePath = $baseurl."uploads/attachments/".$fileName;
- $fildata = file_get_contents($filePath);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
- curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url);
- curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fildata);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/binary','Accept: application/json'));
- curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- $output = curl_exec($ch);
- curl_close($ch);
- $decoded = json_decode($output);
- return $decoded;
- }
- public function curlJson($url, $json, $action, $sufix = '')
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
- curl_setopt($ch, CURLOPT_URL, self::$ZDURL.$url.$sufix);
- curl_setopt($ch, CURLOPT_USERPWD, self::$ZDUSER."/token:".self::$ZDAPIKEY);
- switch($action){
- case "POST":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
- break;
- case "GET":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
- break;
- case "PUT":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
- break;
- case "DELETE":
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
- break;
- default:
- break;
- }
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
- curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement