├── README.md ├── composer.json ├── gitignore └── src └── GetResponseAPI3.class.php /README.md: -------------------------------------------------------------------------------- 1 | ### This project is abandoned, please use [getresponse/sdk-php](https://github.com/GetResponse/sdk-php) 2 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "getresponse/getresponse", 3 | "description": "GetResponse API v3 client library.", 4 | "version": "0.0.2", 5 | "homepage": "https://github.com/GetResponse/getresponse-api-php", 6 | "keywords": ["GetResponse", "api", "email"], 7 | "type": "library", 8 | "license": "MIT", 9 | "abandoned": "getresponse/sdk-php", 10 | "authors": [ 11 | { 12 | "name": "Pawel Maslak", 13 | "email": "pawel.maslak@getresponse.com" 14 | }, 15 | { 16 | "name": "Grzegorz Struczynski", 17 | "email": "grzegorz.struczynski@getresponse.com" 18 | } 19 | ], 20 | "require": { 21 | "php": ">=5.2.0", 22 | "ext-curl": "*" 23 | }, 24 | "autoload": { 25 | "files": ["src/GetResponseAPI3.class.php"] 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /src/GetResponseAPI3.class.php: -------------------------------------------------------------------------------- 1 | 7 | * @author Grzegorz Struczynski 8 | * 9 | * @see http://apidocs.getresponse.com/en/v3/resources 10 | * @see https://github.com/GetResponse/getresponse-api-php 11 | */ 12 | class GetResponse 13 | { 14 | 15 | private $api_key; 16 | private $api_url = 'https://api.getresponse.com/v3'; 17 | private $timeout = 8; 18 | public $http_status; 19 | 20 | /** 21 | * X-Domain header value if empty header will be not provided 22 | * @var string|null 23 | */ 24 | private $enterprise_domain = null; 25 | 26 | /** 27 | * X-APP-ID header value if empty header will be not provided 28 | * @var string|null 29 | */ 30 | private $app_id = null; 31 | 32 | /** 33 | * Set api key and optionally API endpoint 34 | * @param $api_key 35 | * @param null $api_url 36 | */ 37 | public function __construct($api_key, $api_url = null) 38 | { 39 | $this->api_key = $api_key; 40 | 41 | if (!empty($api_url)) { 42 | $this->api_url = $api_url; 43 | } 44 | } 45 | 46 | /** 47 | * We can modify internal settings 48 | * @param $key 49 | * @param $value 50 | */ 51 | function __set($key, $value) 52 | { 53 | $this->{$key} = $value; 54 | } 55 | 56 | /** 57 | * get account details 58 | * 59 | * @return mixed 60 | */ 61 | public function accounts() 62 | { 63 | return $this->call('accounts'); 64 | } 65 | 66 | /** 67 | * @return mixed 68 | */ 69 | public function ping() 70 | { 71 | return $this->accounts(); 72 | } 73 | 74 | /** 75 | * Return all campaigns 76 | * @return mixed 77 | */ 78 | public function getCampaigns() 79 | { 80 | return $this->call('campaigns'); 81 | } 82 | 83 | /** 84 | * get single campaign 85 | * @param string $campaign_id retrieved using API 86 | * @return mixed 87 | */ 88 | public function getCampaign($campaign_id) 89 | { 90 | return $this->call('campaigns/' . $campaign_id); 91 | } 92 | 93 | /** 94 | * adding campaign 95 | * @param $params 96 | * @return mixed 97 | */ 98 | public function createCampaign($params) 99 | { 100 | return $this->call('campaigns', 'POST', $params); 101 | } 102 | 103 | /** 104 | * list all RSS newsletters 105 | * @return mixed 106 | */ 107 | public function getRSSNewsletters() 108 | { 109 | $this->call('rss-newsletters', 'GET', null); 110 | } 111 | 112 | /** 113 | * send one newsletter 114 | * 115 | * @param $params 116 | * @return mixed 117 | */ 118 | public function sendNewsletter($params) 119 | { 120 | return $this->call('newsletters', 'POST', $params); 121 | } 122 | 123 | /** 124 | * @param $params 125 | * @return mixed 126 | */ 127 | public function sendDraftNewsletter($params) 128 | { 129 | return $this->call('newsletters/send-draft', 'POST', $params); 130 | } 131 | 132 | /** 133 | * add single contact into your campaign 134 | * 135 | * @param $params 136 | * @return mixed 137 | */ 138 | public function addContact($params) 139 | { 140 | return $this->call('contacts', 'POST', $params); 141 | } 142 | 143 | /** 144 | * retrieving contact by id 145 | * 146 | * @param string $contact_id - contact id obtained by API 147 | * @return mixed 148 | */ 149 | public function getContact($contact_id) 150 | { 151 | return $this->call('contacts/' . $contact_id); 152 | } 153 | 154 | 155 | /** 156 | * search contacts 157 | * 158 | * @param $params 159 | * @return mixed 160 | */ 161 | public function searchContacts($params = null) 162 | { 163 | return $this->call('search-contacts?' . $this->setParams($params)); 164 | } 165 | 166 | /** 167 | * retrieve segment 168 | * 169 | * @param $id 170 | * @return mixed 171 | */ 172 | public function getContactsSearch($id) 173 | { 174 | return $this->call('search-contacts/' . $id); 175 | } 176 | 177 | /** 178 | * add contacts search 179 | * 180 | * @param $params 181 | * @return mixed 182 | */ 183 | public function addContactsSearch($params) 184 | { 185 | return $this->call('search-contacts/', 'POST', $params); 186 | } 187 | 188 | /** 189 | * add contacts search 190 | * 191 | * @param $id 192 | * @return mixed 193 | */ 194 | public function deleteContactsSearch($id) 195 | { 196 | return $this->call('search-contacts/' . $id, 'DELETE'); 197 | } 198 | 199 | /** 200 | * get contact activities 201 | * @param $contact_id 202 | * @return mixed 203 | */ 204 | public function getContactActivities($contact_id) 205 | { 206 | return $this->call('contacts/' . $contact_id . '/activities'); 207 | } 208 | 209 | /** 210 | * retrieving contact by params 211 | * @param array $params 212 | * 213 | * @return mixed 214 | */ 215 | public function getContacts($params = array()) 216 | { 217 | return $this->call('contacts?' . $this->setParams($params)); 218 | } 219 | 220 | /** 221 | * updating any fields of your subscriber (without email of course) 222 | * @param $contact_id 223 | * @param array $params 224 | * 225 | * @return mixed 226 | */ 227 | public function updateContact($contact_id, $params = array()) 228 | { 229 | return $this->call('contacts/' . $contact_id, 'POST', $params); 230 | } 231 | 232 | /** 233 | * drop single user by ID 234 | * 235 | * @param string $contact_id - obtained by API 236 | * @return mixed 237 | */ 238 | public function deleteContact($contact_id) 239 | { 240 | return $this->call('contacts/' . $contact_id, 'DELETE'); 241 | } 242 | 243 | /** 244 | * retrieve account custom fields 245 | * @param array $params 246 | * 247 | * @return mixed 248 | */ 249 | public function getCustomFields($params = array()) 250 | { 251 | return $this->call('custom-fields?' . $this->setParams($params)); 252 | } 253 | 254 | /** 255 | * add custom field 256 | * 257 | * @param $params 258 | * @return mixed 259 | */ 260 | public function setCustomField($params) 261 | { 262 | return $this->call('custom-fields', 'POST', $params); 263 | } 264 | 265 | /** 266 | * retrieve single custom field 267 | * 268 | * @param string $cs_id obtained by API 269 | * @return mixed 270 | */ 271 | public function getCustomField($custom_id) 272 | { 273 | return $this->call('custom-fields/' . $custom_id, 'GET'); 274 | } 275 | 276 | /** 277 | * retrieving billing information 278 | * 279 | * @return mixed 280 | */ 281 | public function getBillingInfo() 282 | { 283 | return $this->call('accounts/billing'); 284 | } 285 | 286 | /** 287 | * get single web form 288 | * 289 | * @param int $w_id 290 | * @return mixed 291 | */ 292 | public function getWebForm($w_id) 293 | { 294 | return $this->call('webforms/' . $w_id); 295 | } 296 | 297 | /** 298 | * retrieve all webforms 299 | * @param array $params 300 | * 301 | * @return mixed 302 | */ 303 | public function getWebForms($params = array()) 304 | { 305 | return $this->call('webforms?' . $this->setParams($params)); 306 | } 307 | 308 | /** 309 | * get single form 310 | * 311 | * @param int $form_id 312 | * @return mixed 313 | */ 314 | public function getForm($form_id) 315 | { 316 | return $this->call('forms/' . $form_id); 317 | } 318 | 319 | /** 320 | * retrieve all forms 321 | * @param array $params 322 | * 323 | * @return mixed 324 | */ 325 | public function getForms($params = array()) 326 | { 327 | return $this->call('forms?' . $this->setParams($params)); 328 | } 329 | 330 | /** 331 | * Curl run request 332 | * 333 | * @param null $api_method 334 | * @param string $http_method 335 | * @param array $params 336 | * @return mixed 337 | * @throws Exception 338 | */ 339 | private function call($api_method = null, $http_method = 'GET', $params = array()) 340 | { 341 | if (empty($api_method)) { 342 | return (object)array( 343 | 'httpStatus' => '400', 344 | 'code' => '1010', 345 | 'codeDescription' => 'Error in external resources', 346 | 'message' => 'Invalid api method' 347 | ); 348 | } 349 | 350 | $params = json_encode($params); 351 | $url = $this->api_url . '/' . $api_method; 352 | 353 | $options = array( 354 | CURLOPT_URL => $url, 355 | CURLOPT_ENCODING => 'gzip,deflate', 356 | CURLOPT_FRESH_CONNECT => 1, 357 | CURLOPT_RETURNTRANSFER => 1, 358 | CURLOPT_TIMEOUT => $this->timeout, 359 | CURLOPT_HEADER => false, 360 | CURLOPT_USERAGENT => 'PHP GetResponse client 0.0.2', 361 | CURLOPT_HTTPHEADER => array('X-Auth-Token: api-key ' . $this->api_key, 'Content-Type: application/json') 362 | ); 363 | 364 | if (!empty($this->enterprise_domain)) { 365 | $options[CURLOPT_HTTPHEADER][] = 'X-Domain: ' . $this->enterprise_domain; 366 | } 367 | 368 | if (!empty($this->app_id)) { 369 | $options[CURLOPT_HTTPHEADER][] = 'X-APP-ID: ' . $this->app_id; 370 | } 371 | 372 | if ($http_method == 'POST') { 373 | $options[CURLOPT_POST] = 1; 374 | $options[CURLOPT_POSTFIELDS] = $params; 375 | } else if ($http_method == 'DELETE') { 376 | $options[CURLOPT_CUSTOMREQUEST] = 'DELETE'; 377 | } 378 | 379 | $curl = curl_init(); 380 | curl_setopt_array($curl, $options); 381 | 382 | $response = json_decode(curl_exec($curl)); 383 | 384 | $this->http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE); 385 | 386 | curl_close($curl); 387 | return (object)$response; 388 | } 389 | 390 | /** 391 | * @param array $params 392 | * 393 | * @return string 394 | */ 395 | private function setParams($params = array()) 396 | { 397 | $result = array(); 398 | if (is_array($params)) { 399 | foreach ($params as $key => $value) { 400 | $result[$key] = $value; 401 | } 402 | } 403 | return http_build_query($result); 404 | } 405 | 406 | } --------------------------------------------------------------------------------