Пример #1
0
 static function subscribe($campaign, $data = array())
 {
     $data['EMAIL_ADDRESS_'] = $data['email'];
     if (isset($data['country'])) {
         $data['COUNTRY_'] = $data['country'];
     }
     $data['EMAIL_FORMAT_'] = 'H';
     if (isset($data['format']) && strtolower($data['format']) == 'text') {
         $data['EMAIL_FORMAT_'] = 'T';
     }
     $data[$campaign . '_FLG'] = 'Y';
     $data[$campaign . '_DATE'] = date('Y-m-d');
     return Responsys::post($data);
 }
Пример #2
0
 /**
  * Send HTTP request
  * @param string $uri
  * @param array $data
  * @param string $method
  * @param array $headers
  * @return array
  */
 private function sendRequest($uri, array $data = array(), $method = 'POST', array $headers = array())
 {
     $ch = curl_init($uri);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
     $defaultHeders = array('content_type' => 'Content-Type: application/json', 'user_agent' => 'User-Agent: eZ Publish Responsys API');
     $headers = array_merge($defaultHeders, $headers);
     $dataJSON = json_encode($data);
     // Fix double slashes for unicode sequences
     $dataJSON = preg_replace('/\\\\\\\\u([0-9a-fA-F]{4})/u', '\\u$1', $dataJSON);
     switch ($method) {
         case 'POST':
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJSON);
             break;
         case 'PUT':
             curl_setopt($curl, CURLOPT_PUT, true);
             break;
     }
     if (count($headers) > 0) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     }
     if ($this->ignoreSSL) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     }
     $response = curl_exec($ch);
     $info = curl_getinfo($ch);
     $header = trim(substr($response, 0, $info['header_size']));
     $body = trim(substr($response, $info['header_size']));
     $log = new ResponsysLog();
     $log->setAttribute('request_uri', $uri);
     $log->setAttribute('request', self::json_pretty($dataJSON));
     $log->setAttribute('request_headers', implode("\n", $headers));
     $log->setAttribute('response_status', $info['http_code']);
     $log->setAttribute('response_headers', $header);
     $log->setAttribute('response_time', $info['total_time']);
     $log->setAttribute('response', $body);
     if (curl_error($ch)) {
         $log->setAttribute('response_error', curl_error($curl));
     }
     $log->store();
     self::$lastLogItem = $log;
     curl_close($ch);
     $result = json_decode($response, true);
     if ($result === null) {
         $error = 'Invalid response from Responsys.';
         if (strlen($log->attribute('response_error')) === 0) {
             $log->setAttribute('response_error', $error);
             $log->store();
         }
         throw new Exception($error);
     }
     $error = null;
     if (isset($result['errorCode'])) {
         $error = isset($result['detail']) && empty($result['detail']) === false ? $result['detail'] : $result['title'];
     } elseif (isset($result[0]['errorMessage'])) {
         $error = $result[0]['errorMessage'];
     }
     if ($error !== null) {
         if (strlen($log->attribute('response_error')) === 0) {
             $log->setAttribute('response_error', $error);
             $log->store();
         }
         throw new Exception($error);
     }
     return $result;
 }
Пример #3
0
 function subscribe()
 {
     Responsys::subscribe($this->campaign, $this->data);
 }