Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Infoflot;
- class GetResponse
- {
- const X_AUTH_TOKEN = 'hvjldi9exj0huhjpgiloq2zp0ujp3i4n';
- const X_DOMAIN = 'email.infoflot.com';
- const API_LINK = 'https://api3.getresponse360.pl/v3';
- private $ch;
- public function __construct() {
- $this->ch = curl_init();
- $http_headers = [
- 'Content-type: application/json',
- sprintf('X-Auth-Token: api-key %s', self::X_AUTH_TOKEN),
- sprintf('X-Domain: %s', self::X_DOMAIN)
- ];
- curl_setopt($this->ch, CURLOPT_HTTPHEADER, $http_headers);
- curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
- }
- public function addContact(array $params) {
- if ($default_campaign = $this->getDefaultCampaign()) {
- $params['campaign'] = ['campaignId' => $default_campaign];
- curl_setopt($this->ch, CURLOPT_URL, sprintf('%s/contacts', self::API_LINK));
- curl_setopt($this->ch, CURLOPT_POST, true);
- curl_setopt($this->ch, CURLOPT_POSTFIELDS, json_encode($params));
- return $this->executeRequest(202);
- }
- return false;
- }
- public function editContact() {
- /**
- * @todo write code)
- */
- }
- private function getDefaultCampaign() {
- curl_setopt($this->ch, CURLOPT_URL, sprintf('%s/campaigns', self::API_LINK));
- curl_setopt($this->ch, CURLOPT_POST, false);
- $campaigns = json_decode(curl_exec($this->ch), true);
- $http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
- if ($http_code == 200 && !empty($campaigns)) {
- foreach ($campaigns as $campaign) {
- if ($campaign['isDefault']) {
- return $campaign['campaignId'];
- }
- }
- }
- return false;
- }
- private function executeRequest($response_code) {
- curl_exec($this->ch);
- $http_code = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
- return ($http_code == $response_code) ? true : false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement