Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Add curlOptions to override hardcoded defaults #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require_once("vendor/autoload.php");
Download the `Omnisend.php` file and include it manually:

```php
require_once('Omnisend.php');
require_once('Omnisend.php');
```
**Note:** check and correct if needed "Omnisend.php" path.

Expand All @@ -43,7 +43,8 @@ Available methods & options
```php
$options = array(
'timeout' => 30,
'verifySSL' => false
'verifySSL' => false,
'curlOptions' => array()
);
$omnisend = new Omnisend('API-KEY', $options);
```
Expand All @@ -54,6 +55,7 @@ Available options:
|---|---|---|
|timeout|int|Timeout. If not passed - will be calculated depending on PHP max_execution_time
|verifySSL|bool|Default - true. Enable (true) or disable (false) SSL verification.
|curlOptions|array|array of CURLOPT_* of options passed to `curl_setopt_array()`

**Available methods**

Expand Down Expand Up @@ -131,10 +133,10 @@ $omnisend = new Omnisend('your-api-key');
$contacts = $omnisend->post(
'contacts',
array(
"email" => "[email protected]",
"firstName" => "Vanessa",
"lastName" => "Kensington",
"status" => "subscribed",
"email" => "[email protected]",
"firstName" => "Vanessa",
"lastName" => "Kensington",
"status" => "subscribed",
"statusDate" => "2018-12-11T10:29:43+00:00"
)
);
Expand All @@ -146,7 +148,7 @@ if ($contacts) {
//request was successful

//print response
print_r($contacts);
print_r($contacts);
//get contactID from response
$contactID = $contacts['contactID'];
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/Omnisend.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Omnisend
private $verifySSL = true;
private $lastError = array();
private $useCurl = true;
private $curlOptions = array();
private $version = "1.2";

public function __construct($apiKey, $options = array())
Expand All @@ -44,6 +45,10 @@ public function __construct($apiKey, $options = array())
if (array_key_exists("timeout", $options) && is_int($options['timeout'])) {
$this->timeout = $options['timeout'];
}

if (array_key_exists("curlOptions", $options) && is_array($options['curlOptions'])) {
$this->curlOptions = $options['curlOptions'];
}
}
}

Expand Down Expand Up @@ -225,6 +230,11 @@ private function omnisendApi($endpoint, $method = "POST", $fields = array(), $qu
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifySSL);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

if (!empty($this->curlOptions)) {
curl_setopt_array($ch, $this->curlOptions);
}

switch ($method) {
case "POST":
curl_setopt($ch, CURLOPT_POST, true);
Expand Down