Friday, May 13, 2016

Sears API

Sears New API:
About time they begin to work on this.


 class SearsComm  
 {  
      private $email = '';  
      private $timestamp = null;  
      private $seller = '';  
      private $key = '';  
      function __construct()  
      {  
           date_default_timezone_set('Etc/GMT');  
           $this->timestamp = date('Y-m-d\TH:i:s\Z', time());  
           sleep(5);//needed cause Sears appears to be a little slow  
      }  
      function getSears($url)  
      {  
           $curl = curl_init($url);  
           curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");  
           curl_setopt($curl, CURLOPT_HEADER, false);  
           curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
           curl_setopt($curl, CURLOPT_HTTPHEADER, array($this->createSig()));  
           curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);//should really use a perm file instead  
           // Make the REST call, returning the result  
           $response = curl_exec($curl);  
           curl_close($curl);  
           if (!$response) {  
                die("Connection Failure.");  
           }  
           else  
                return $response;  
      }  
      function putSears($url, $data)  
      {  
           $curl = curl_init($url);  
           curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");  
           curl_setopt($curl, CURLOPT_HEADER, false);  
           curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
           curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $this->createSig()));  
           curl_setopt($curl, CURLOPT_POSTFIELDS, $data);  
           curl_setopt($curl, CURLOPT_SSL_VERIFYPEER , false);//should really use a perm file instead  
           // Make the REST call, returning the result  
           $response = curl_exec($curl);  
           curl_close($curl);  
           if (!$response) {  
                die("Connection Failure.");  
           }  
           else  
                echo $response;  
      }  
      function createSig()  
      {  
           return "authorization:HMAC-SHA256 emailaddress=".$this->email.",timestamp=".$this->timestamp.",signature=" . hash_hmac ( 'sha256' , $this->seller.":".$this->email.":".$this->timestamp, $this->key);  
      }  
 }