├── .gitignore ├── MailWizzApi ├── Autoloader.php ├── Base.php ├── Cache │ ├── Abstract.php │ ├── Apc.php │ ├── Database.php │ ├── Dummy.php │ ├── File.php │ ├── Xcache.php │ └── data │ │ ├── cache │ │ └── .gitignore │ │ ├── db │ │ └── .gitignore │ │ └── index.html ├── Config.php ├── Endpoint │ ├── CampaignBounces.php │ ├── CampaignUnsubscribes.php │ ├── Campaigns.php │ ├── CampaignsTracking.php │ ├── Countries.php │ ├── Customers.php │ ├── ListFields.php │ ├── ListSegments.php │ ├── ListSubscribers.php │ ├── Lists.php │ ├── Templates.php │ └── TransactionalEmails.php ├── Http │ ├── Client.php │ ├── Request.php │ └── Response.php ├── Params.php ├── ParamsIterator.php ├── Test │ ├── Base.php │ └── Endpoint │ │ └── ListsTest.php ├── autoload.php └── license │ ├── mailwizz-php-sdk.txt │ └── yiiframework.txt ├── README.md ├── composer.json ├── examples ├── ajax_subscribe.php ├── campaign_bounces.php ├── campaigns.php ├── campaigns_tracking.php ├── countries.php ├── customers.php ├── list_fields.php ├── list_segments.php ├── list_subscribers.php ├── lists.php ├── lists_create.php ├── lists_update.php ├── setup.php ├── template-example.html ├── template-example.zip ├── templates.php └── transactional_emails.php ├── php_cs.dist ├── phpstan.neon └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .php_cs.cache 4 | vendor 5 | composer.lock -------------------------------------------------------------------------------- /MailWizzApi/Autoloader.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * The MailWizzApi Autoloader class. 13 | * 14 | * From within a Yii Application, you would load this as: 15 | * 16 | *
17 |  * require_once(Yii::getPathOfAlias('application.vendors.MailWizzApi.Autoloader').'.php');
18 |  * Yii::registerAutoloader(array('MailWizzApi_Autoloader', 'autoloader'), true);
19 |  * 
20 | * 21 | * Alternatively you can: 22 | *
23 |  * require_once('Path/To/MailWizzApi/Autoloader.php');
24 |  * MailWizzApi_Autoloader::register();
25 |  * 
26 | * 27 | * @author Serban George Cristian 28 | * @package MailWizzApi 29 | * @since 1.0 30 | */ 31 | class MailWizzApi_Autoloader 32 | { 33 | /** 34 | * The registrable autoloader 35 | * 36 | * @param string $class 37 | * @return void 38 | */ 39 | public static function autoloader($class) 40 | { 41 | if (strpos($class, 'MailWizzApi') === 0) { 42 | $className = str_replace('_', '/', $class); 43 | $className = substr($className, 12); 44 | 45 | if (is_file($classFile = dirname(__FILE__) . '/'. $className.'.php')) { 46 | require_once($classFile); 47 | } 48 | } 49 | } 50 | 51 | /** 52 | * Registers the MailWizzApi_Autoloader::autoloader() 53 | * 54 | * @return void 55 | */ 56 | public static function register() 57 | { 58 | spl_autoload_register('MailWizzApi_Autoloader::autoloader'); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /MailWizzApi/Base.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Base is the base class for all the other classes used in the sdk. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @since 1.0 17 | */ 18 | class MailWizzApi_Base 19 | { 20 | /** 21 | * Marker for before send request event 22 | */ 23 | const EVENT_BEFORE_SEND_REQUEST = 'beforeSendRequest'; 24 | 25 | /** 26 | * Marker for after send request event 27 | */ 28 | const EVENT_AFTER_SEND_REQUEST = 'afterSendRequest'; 29 | 30 | /** 31 | * @var MailWizzApi_Config the configuration object injected into the application at runtime 32 | */ 33 | private static $_config; 34 | 35 | /** 36 | * @var MailWizzApi_Params the package registry that will hold various components 37 | */ 38 | private static $_registry; 39 | 40 | /** 41 | * @var MailWizzApi_Params the registered event handlers 42 | */ 43 | private static $_eventHandlers; 44 | 45 | /** 46 | * Inject the configuration into the sdk 47 | * 48 | * @param MailWizzApi_Config $config 49 | * @return void 50 | */ 51 | public static function setConfig(MailWizzApi_Config $config) 52 | { 53 | self::$_config = $config; 54 | } 55 | 56 | /** 57 | * Returns the configuration object 58 | * 59 | * @return MailWizzApi_Config 60 | */ 61 | public static function getConfig() 62 | { 63 | return self::$_config; 64 | } 65 | 66 | /** 67 | * Add a new component to the registry 68 | * 69 | * @param string $key 70 | * @param mixed $value 71 | * 72 | * @return MailWizzApi_Base 73 | * @throws Exception 74 | */ 75 | public function addToRegistry($key, $value) 76 | { 77 | $this->getRegistry()->add($key, $value); 78 | return $this; 79 | } 80 | 81 | /** 82 | * Get the current registry object 83 | * 84 | * @return MailWizzApi_Params 85 | * @throws Exception 86 | */ 87 | public function getRegistry() 88 | { 89 | if (!(self::$_registry instanceof MailWizzApi_Params)) { 90 | self::$_registry = new MailWizzApi_Params(is_array(self::$_registry) ? self::$_registry : array()); 91 | } 92 | return self::$_registry; 93 | } 94 | 95 | /** 96 | * Set the components used throughout the application lifecyle. 97 | * 98 | * Each component config array needs to have a `class` key containing a class name that can be autoloaded. 99 | * For example, adding a cache component would be done like : 100 | * 101 | *
102 |      * $components = array(
103 |      *     'cache'=>array(
104 |      *         'class'             => 'MailWizzApi_Cache_Sqlite',
105 |      *         'connectionString'  => 'sqlite:/absolute/path/to/your/sqlite.db',
106 |      *     ),
107 |      * );
108 |      * $context->setComponents($components);
109 |      * 
110 | * 111 | * Please note, if a named component exists, and you assign one with the same name, 112 | * it will get overriden by the second one. 113 | * 114 | * @param array $components 115 | * 116 | * @return MailWizzApi_Base 117 | * @throws Exception 118 | */ 119 | public function setComponents(array $components) 120 | { 121 | foreach ($components as $componentName => $config) { 122 | $this->setComponent($componentName, $config); 123 | } 124 | return $this; 125 | } 126 | 127 | /** 128 | * Set a single component used throughout the application lifecyle. 129 | * 130 | * The component config array needs to have a `class` key containing a class name that can be autoloaded. 131 | * For example, adding a cache component would be done like : 132 | * 133 | *
134 |      * $context->setComponent('cache', array(
135 |      *    'class'             => 'MailWizzApi_Cache_Sqlite',
136 |      *    'connectionString'  => 'sqlite:/absolute/path/to/your/sqlite.db',
137 |      * ));
138 |      * 
139 | * 140 | * Please note, if a named component exists, and you assign one with the same name, 141 | * it will get overriden by the second one. 142 | * 143 | * @param string $componentName the name of the component accessed later via $context->componentName 144 | * @param array $config the component configuration array 145 | * 146 | * @return MailWizzApi_Base 147 | * @throws ReflectionException 148 | * @throws Exception 149 | */ 150 | public function setComponent($componentName, array $config) 151 | { 152 | if (empty($config['class'])) { 153 | throw new Exception('Please set the class property for "'.htmlspecialchars($componentName, ENT_QUOTES, 'utf-8').'" component.'); 154 | } 155 | $component = new $config['class']; 156 | if ($component instanceof MailWizzApi_Base) { 157 | $component->populateFromArray($config); 158 | } else { 159 | unset($config['class']); 160 | foreach ($config as $property => $value) { 161 | if (property_exists($component, $property)) { 162 | $reflection = new ReflectionProperty($component, $property); 163 | if ($reflection->isPublic()) { 164 | $component->$property = $value; 165 | } 166 | } 167 | } 168 | } 169 | $this->addToRegistry($componentName, $component); 170 | return $this; 171 | } 172 | 173 | /** 174 | * Register one or more callbacks/event handlers for the given event(s) 175 | * 176 | * A valid registration would be: 177 | * 178 | *
179 |      * $eventHandlers = array(
180 |      *     'eventName1' => array($object, 'method'),
181 |      *     'eventName2' => array(
182 |      *         array($object, 'method'),
183 |      *         array($object, 'otherMethod'),
184 |      *     )
185 |      * );
186 |      * 
187 | * 188 | * @param array $eventHandlers 189 | * 190 | * @return MailWizzApi_Base 191 | * @throws Exception 192 | */ 193 | public function setEventHandlers(array $eventHandlers) 194 | { 195 | foreach ($eventHandlers as $eventName => $callback) { 196 | if (empty($callback) || !is_array($callback)) { 197 | continue; 198 | } 199 | if (!is_array($callback[0]) && is_callable($callback)) { 200 | $this->getEventHandlers($eventName)->add(null, $callback); 201 | continue; 202 | } 203 | if (is_array($callback[0])) { 204 | foreach ($callback as $cb) { 205 | if (is_callable($cb)) { 206 | $this->getEventHandlers($eventName)->add(null, $cb); 207 | } 208 | } 209 | } 210 | } 211 | return $this; 212 | } 213 | 214 | /** 215 | * Return a list of callbacks/event handlers for the given event 216 | * 217 | * @param string $eventName 218 | * 219 | * @return MailWizzApi_Params 220 | * @throws Exception 221 | */ 222 | public function getEventHandlers($eventName) 223 | { 224 | if (!(self::$_eventHandlers instanceof MailWizzApi_Params)) { 225 | self::$_eventHandlers = new MailWizzApi_Params(self::$_eventHandlers); 226 | } 227 | 228 | if (!self::$_eventHandlers->contains($eventName) || !(self::$_eventHandlers->itemAt($eventName) instanceof MailWizzApi_Params)) { 229 | self::$_eventHandlers->add($eventName, new MailWizzApi_Params()); 230 | } 231 | 232 | return self::$_eventHandlers->itemAt($eventName); 233 | } 234 | 235 | /** 236 | * Remove all the event handlers bound to the event name 237 | * 238 | * @param string $eventName 239 | * 240 | * @return MailWizzApi_Base 241 | * @throws Exception 242 | */ 243 | public function removeEventHandlers($eventName) 244 | { 245 | self::$_eventHandlers->remove($eventName); 246 | return $this; 247 | } 248 | 249 | /** 250 | * Called from within a child class, will populate 251 | * all the setters matching the array keys with the array values 252 | * 253 | * @param array $params 254 | * 255 | * @return MailWizzApi_Base 256 | * @throws ReflectionException 257 | */ 258 | protected function populateFromArray(array $params = array()) 259 | { 260 | foreach ($params as $name => $value) { 261 | $found = false; 262 | 263 | if (property_exists($this, $name)) { 264 | $param = (string)$name; 265 | } else { 266 | $asSetterName = str_replace('_', ' ', $name); 267 | $asSetterName = ucwords($asSetterName); 268 | $asSetterName = str_replace(' ', '', $asSetterName); 269 | $asSetterName[0] = strtolower($asSetterName[0]); 270 | $param = (string)(property_exists($this, $asSetterName) ? $asSetterName : ''); 271 | } 272 | 273 | if ($param) { 274 | $reflection = new ReflectionProperty($this, $param); 275 | if ($reflection->isPublic()) { 276 | $this->$param = $value; 277 | $found = true; 278 | } 279 | } 280 | 281 | if (!$found) { 282 | $methodName = str_replace('_', ' ', $name); 283 | $methodName = ucwords($methodName); 284 | $methodName = str_replace(' ', '', $methodName); 285 | $methodName = 'set'.$methodName; 286 | 287 | if (method_exists($this, $methodName)) { 288 | $reflection = new ReflectionMethod($this, $methodName); 289 | if ($reflection->isPublic()) { 290 | $this->$methodName($value); 291 | } 292 | } 293 | } 294 | } 295 | 296 | return $this; 297 | } 298 | 299 | /** 300 | * Magic setter 301 | * 302 | * This method should never be called directly from outside of the class. 303 | * 304 | * @param string $name 305 | * @param mixed $value 306 | * 307 | * @return void 308 | * @throws ReflectionException 309 | * @throws Exception 310 | */ 311 | public function __set($name, $value) 312 | { 313 | $methodName = 'set'.ucfirst($name); 314 | if (!method_exists($this, $methodName)) { 315 | $this->addToRegistry($name, $value); 316 | } else { 317 | $method = new ReflectionMethod($this, $methodName); 318 | if ($method->isPublic()) { 319 | $this->$methodName($value); 320 | } 321 | } 322 | } 323 | 324 | /** 325 | * Magic getter 326 | * 327 | * This method should never be called directly from outside of the class. 328 | * 329 | * @param string $name 330 | * 331 | * @return mixed 332 | * @throws ReflectionException 333 | * @throws Exception 334 | */ 335 | public function __get($name) 336 | { 337 | $methodName = 'get'.ucfirst($name); 338 | if (!method_exists($this, $methodName) && $this->getRegistry()->contains($name)) { 339 | return $this->getRegistry()->itemAt($name); 340 | } elseif (method_exists($this, $methodName)) { 341 | $method = new ReflectionMethod($this, $methodName); 342 | if ($method->isPublic()) { 343 | return $this->$methodName(); 344 | } 345 | } 346 | } 347 | } 348 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/Abstract.php: -------------------------------------------------------------------------------- 1 | 8 | * @link https://www.mailwizz.com/ 9 | * @copyright 2013-2020 https://www.mailwizz.com/ 10 | */ 11 | 12 | 13 | /** 14 | * MailWizzApi_Cache_Abstract is the base class that all the caching classes should extend. 15 | * 16 | * @author Serban George Cristian 17 | * @package MailWizzApi 18 | * @subpackage Cache 19 | * @since 1.0 20 | */ 21 | abstract class MailWizzApi_Cache_Abstract extends MailWizzApi_Base 22 | { 23 | /** 24 | * @var array keeps a history of loaded keys for easier and faster reference 25 | */ 26 | protected $_loaded = array(); 27 | 28 | /** 29 | * Set data into the cache 30 | * 31 | * @param string $key 32 | * @param mixed $value 33 | * @return bool 34 | */ 35 | abstract public function set($key, $value); 36 | 37 | /** 38 | * Get data from the cache 39 | * 40 | * @param string $key 41 | * @return mixed 42 | */ 43 | abstract public function get($key); 44 | 45 | /** 46 | * Delete data from cache 47 | * 48 | * @param string $key 49 | * @return bool 50 | */ 51 | abstract public function delete($key); 52 | 53 | /** 54 | * Delete all data from cache 55 | * 56 | * @return bool 57 | */ 58 | abstract public function flush(); 59 | } 60 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/Apc.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Cache_Apc makes use of the APC extension in order to cache data in memory. 13 | * 14 | * As all the data will stay in memory, it is recommeded that will be used only if 15 | * the system has enough memory, or for development/small servers. 16 | * 17 | * @author Serban George Cristian 18 | * @package MailWizzApi 19 | * @subpackage Cache 20 | * @since 1.0 21 | */ 22 | class MailWizzApi_Cache_Apc extends MailWizzApi_Cache_Abstract 23 | { 24 | /** 25 | * Cache data by given key. 26 | * 27 | * For consistency, the key will go through sha1() before it is saved. 28 | * 29 | * This method implements {@link MailWizzApi_Cache_Abstract::set()}. 30 | * 31 | * @param string $key 32 | * @param mixed $value 33 | * @return bool 34 | */ 35 | public function set($key, $value) 36 | { 37 | return apc_store(sha1($key), $value, 0); 38 | } 39 | 40 | /** 41 | * Get cached data by given key. 42 | * 43 | * For consistency, the key will go through sha1() 44 | * before it will be used to retrieve the cached data. 45 | * 46 | * This method implements {@link MailWizzApi_Cache_Abstract::get()}. 47 | * 48 | * @param string $key 49 | * @return mixed 50 | */ 51 | public function get($key) 52 | { 53 | return apc_fetch(sha1($key)); 54 | } 55 | 56 | /** 57 | * Delete cached data by given key. 58 | * 59 | * For consistency, the key will go through sha1() 60 | * before it will be used to delete the cached data. 61 | * 62 | * This method implements {@link MailWizzApi_Cache_Abstract::delete()}. 63 | * 64 | * @param string $key 65 | * @return bool 66 | */ 67 | public function delete($key) 68 | { 69 | return apc_delete(sha1($key)); 70 | } 71 | 72 | /** 73 | * Delete all cached data. 74 | * 75 | * This method implements {@link MailWizzApi_Cache_Abstract::flush()}. 76 | * 77 | * @return bool 78 | */ 79 | public function flush() 80 | { 81 | return apc_clear_cache('user'); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/Database.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Cache_Database makes use of the PHP's {@link PDO} extension in order to cache data into a database. 13 | * 14 | * For now it only supports Mysql and SQlite. 15 | * 16 | * @author Serban George Cristian 17 | * @package MailWizzApi 18 | * @subpackage Cache 19 | * @since 1.0 20 | */ 21 | class MailWizzApi_Cache_Database extends MailWizzApi_Cache_Abstract 22 | { 23 | /** 24 | * @var PDO the PDO instance that should be imported. 25 | * 26 | * This is useful when the SDK is integrated with another application and you 27 | * have access to the database object. 28 | */ 29 | private $_importConnection; 30 | 31 | /** 32 | * @var string the PDO connection string. 33 | */ 34 | private $_connectionString; 35 | 36 | /** 37 | * @var string the username required to connect to the database. 38 | */ 39 | private $_username; 40 | 41 | /** 42 | * @var string the password required to connect to the database. 43 | */ 44 | private $_password; 45 | 46 | /** 47 | * @var PDO the newly created PDO instance used for all queries. 48 | */ 49 | private $_connection; 50 | 51 | /** 52 | * @var bool whether to create or not the database table. 53 | * 54 | * Set this to true for the first call, then after the database is created, 55 | * set it back to false. 56 | */ 57 | private $_createTable = false; 58 | 59 | /** 60 | * @var string the name of the database table. 61 | */ 62 | private $_tableName = 'mwa_cache'; 63 | 64 | /** 65 | * @var string the current driver in use. 66 | * 67 | * This is autodetected based on the connection string. 68 | */ 69 | private $_driver; 70 | 71 | /** 72 | * Cache data by given key. 73 | * 74 | * For consistency, the key will go through sha1() before it is saved. 75 | * 76 | * This method implements {@link MailWizzApi_Cache_Abstract::set()}. 77 | * 78 | * @param string $key 79 | * @param mixed $value 80 | * @return bool 81 | */ 82 | public function set($key, $value) 83 | { 84 | $value = serialize($value); 85 | if ($exists = $this->get($key)) { 86 | if ($value === serialize($exists)) { 87 | return true; 88 | } 89 | $key = sha1($key); 90 | $con = $this->getConnection(); 91 | $sth = $con->prepare('UPDATE `'.$this->getTableName().'` SET `value` = :v WHERE `key` = :k'); 92 | return $sth->execute(array(':v' => $value, ':k' => $key)); 93 | } 94 | $key = sha1($key); 95 | $con = $this->getConnection(); 96 | $sth = $con->prepare('INSERT INTO `'.$this->getTableName().'`(`key`, `value`) VALUES(:k, :v)'); 97 | return $sth->execute(array(':k' => $key, ':v' => $value)); 98 | } 99 | 100 | /** 101 | * Get cached data by given key. 102 | * 103 | * For consistency, the key will go through sha1() 104 | * before it will be used to retrieve the cached data. 105 | * 106 | * This method implements {@link MailWizzApi_Cache_Abstract::get()}. 107 | * 108 | * @param string $key 109 | * @return mixed 110 | */ 111 | public function get($key) 112 | { 113 | $key = sha1($key); 114 | 115 | if (isset($this->_loaded[$key])) { 116 | return $this->_loaded[$key]; 117 | } 118 | 119 | $con = $this->getConnection(); 120 | $sth = $con->prepare('SELECT `value` FROM `'.$this->getTableName().'` WHERE `key` = :k LIMIT 1'); 121 | $sth->execute(array(':k' => $key)); 122 | $row = $sth->fetch(PDO::FETCH_ASSOC); 123 | $sth->closeCursor(); 124 | return $this->_loaded[$key] = !empty($row['value']) ? unserialize($row['value']) : null; 125 | } 126 | 127 | /** 128 | * Delete cached data by given key. 129 | * 130 | * For consistency, the key will go through sha1() 131 | * before it will be used to delete the cached data. 132 | * 133 | * This method implements {@link MailWizzApi_Cache_Abstract::delete()}. 134 | * 135 | * @param string $key 136 | * @return bool 137 | */ 138 | public function delete($key) 139 | { 140 | $key = sha1($key); 141 | 142 | if (isset($this->_loaded[$key])) { 143 | unset($this->_loaded[$key]); 144 | } 145 | 146 | $con = $this->getConnection(); 147 | $sth = $con->prepare('DELETE FROM `'.$this->getTableName().'` WHERE `key` = :k'); 148 | return $sth->execute(array(':k' => $key)); 149 | } 150 | 151 | /** 152 | * Delete all cached data. 153 | * 154 | * This method implements {@link MailWizzApi_Cache_Abstract::flush()}. 155 | * 156 | * @return bool 157 | */ 158 | public function flush() 159 | { 160 | $this->_loaded = array(); 161 | $con = $this->getConnection(); 162 | $sth = $con->prepare('DELETE FROM `'.$this->getTableName().'` WHERE 1'); 163 | return $sth->execute(); 164 | } 165 | 166 | /** 167 | * Import a {@link PDO} connection to be reused instead of creating a new one. 168 | * 169 | * This is useful when the sdk is used inside another application that is already connected 170 | * to the database using {@link PDO} and same driver. 171 | * 172 | * In that case importing and reusing the connection makes more sense. 173 | * 174 | * @param PDO $connection 175 | * @return MailWizzApi_Cache_Database 176 | */ 177 | public function setImportConnection(PDO $connection) 178 | { 179 | $this->_importConnection = $connection; 180 | return $this; 181 | } 182 | 183 | /** 184 | * Get the imported connection, if any. 185 | * 186 | * @return mixed 187 | */ 188 | public function getImportConnection() 189 | { 190 | return $this->_importConnection; 191 | } 192 | 193 | /** 194 | * Set the database access username. 195 | * 196 | * @param string $username 197 | * @return MailWizzApi_Cache_Database 198 | */ 199 | public function setUsername($username) 200 | { 201 | $this->_username = $username; 202 | return $this; 203 | } 204 | 205 | /** 206 | * Get the database access username. 207 | * 208 | * @return string 209 | */ 210 | public function getUsername() 211 | { 212 | return $this->_username; 213 | } 214 | 215 | /** 216 | * Set the database access password. 217 | * 218 | * @param string $password 219 | * @return MailWizzApi_Cache_Database 220 | */ 221 | public function setPassword($password) 222 | { 223 | $this->_password = $password; 224 | return $this; 225 | } 226 | 227 | /** 228 | * Get the database access password. 229 | * 230 | * @return string 231 | */ 232 | public function getPassword() 233 | { 234 | return $this->_password; 235 | } 236 | 237 | /** 238 | * Set the name of the database table. 239 | * 240 | * @param string $name 241 | * @return MailWizzApi_Cache_Database 242 | */ 243 | public function setTableName($name) 244 | { 245 | $this->_tableName = htmlspecialchars($name, ENT_QUOTES, 'utf-8'); 246 | return $this; 247 | } 248 | 249 | /** 250 | * Get the name of the database table name. 251 | * 252 | * @return string 253 | */ 254 | public function getTableName() 255 | { 256 | return $this->_tableName; 257 | } 258 | 259 | /** 260 | * Set whether the database table should be created or not. 261 | * 262 | * @param bool $bool 263 | * @return MailWizzApi_Cache_Database 264 | */ 265 | public function setCreateTable($bool) 266 | { 267 | $this->_createTable = (bool)$bool; 268 | return $this; 269 | } 270 | 271 | /** 272 | * Get whether the database table should be created or not. 273 | * 274 | * @return bool 275 | */ 276 | public function getCreateTable() 277 | { 278 | return $this->_createTable; 279 | } 280 | 281 | /** 282 | * Set the database connection string. 283 | * 284 | * Please note, this needs to be a valid DSN, see: 285 | * http://php.net/manual/en/ref.pdo-mysql.connection.php 286 | * 287 | * @param string $string 288 | * @return MailWizzApi_Cache_Database 289 | */ 290 | public function setConnectionString($string) 291 | { 292 | $this->_connectionString = $string; 293 | return $this; 294 | } 295 | 296 | /** 297 | * Get the database connection string. 298 | * 299 | * @return string 300 | */ 301 | public function getConnectionString() 302 | { 303 | return $this->_connectionString; 304 | } 305 | 306 | /** 307 | * Create the database table if it doesn't exists. 308 | * 309 | * Please make sure you disable the table creation after the table has been created 310 | * otherwise it will cause unnecessary overhead. 311 | * 312 | * @return void 313 | * @throws Exception 314 | */ 315 | protected function createTable() 316 | { 317 | if ($this->_driver === 'sqlite') { 318 | $sql = ' 319 | BEGIN; 320 | CREATE TABLE IF NOT EXISTS `'.$this->getTableName().'` ( 321 | `id` INTEGER PRIMARY KEY AUTOINCREMENT, 322 | `key` CHAR(40) NOT NULL, 323 | `value` BLOB NOT NULL 324 | ); 325 | CREATE INDEX `key` ON `'.$this->getTableName().'` (`key`); 326 | COMMIT; 327 | '; 328 | } elseif ($this->_driver === 'mysql') { 329 | $sql = ' 330 | CREATE TABLE IF NOT EXISTS `'.$this->getTableName().'` ( 331 | `id` INT(11) NOT NULL AUTO_INCREMENT, 332 | `key` CHAR(40) NOT NULL, 333 | `value` LONGBLOB NOT NULL, 334 | PRIMARY KEY (`id`), 335 | KEY `key` (`key`) 336 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; 337 | '; 338 | } else { 339 | throw new Exception('The "'.$this->_driver.'" driver is not implemented.'); 340 | } 341 | 342 | $this->_connection->exec($sql); 343 | } 344 | 345 | /** 346 | * Get the PDO connection. 347 | * 348 | * @return PDO 349 | * @throws Exception 350 | */ 351 | public function getConnection() 352 | { 353 | if ($this->_connection === null && $this->getImportConnection() instanceof PDO) { 354 | $this->_connection = $this->getImportConnection(); 355 | } 356 | 357 | $connectionParts = explode(':', $this->getConnectionString()); 358 | $this->_driver = (string)array_shift($connectionParts); 359 | 360 | if ($this->getCreateTable() && $this->_driver === 'sqlite') { 361 | $dbPath = (string)array_shift($connectionParts); 362 | $dir = dirname($dbPath); 363 | if (!is_dir($dir)) { 364 | throw new Exception('The database storage directory: "'.$dir.'" does not exists.'); 365 | } 366 | if (!is_writable($dir)) { 367 | throw new Exception('The database storage path: "'.$dir.'" is not writable.'); 368 | } 369 | if (!is_file($dbPath)) { 370 | touch($dbPath); 371 | } 372 | } 373 | 374 | $this->_connection = new PDO($this->getConnectionString(), $this->getUsername(), $this->getPassword()); 375 | $this->_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 376 | 377 | if ($this->getCreateTable()) { 378 | $this->createTable(); 379 | } 380 | 381 | return $this->_connection; 382 | } 383 | 384 | /** 385 | * Close the database connection. 386 | * 387 | * This will only work if the connection is not imported. 388 | * 389 | * @return MailWizzApi_Cache_Database 390 | */ 391 | public function closeConnection() 392 | { 393 | if (!empty($this->_importConnection)) { 394 | return $this; 395 | } 396 | unset($this->_connection); 397 | return $this; 398 | } 399 | } 400 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/Dummy.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Cache_Dummy is used for testing purposes, when you use the sdk with cache but don't want to 13 | * really cache anything. 14 | * 15 | * @author Serban George Cristian 16 | * @package MailWizzApi 17 | * @subpackage Cache 18 | * @since 1.0 19 | */ 20 | class MailWizzApi_Cache_Dummy extends MailWizzApi_Cache_Abstract 21 | { 22 | /** 23 | * Cache data by given key. 24 | * 25 | * This method implements {@link MailWizzApi_Cache_Abstract::set()}. 26 | * 27 | * @param string $key 28 | * @param mixed $value 29 | * @return bool 30 | */ 31 | public function set($key, $value) 32 | { 33 | return true; 34 | } 35 | 36 | /** 37 | * Get cached data by given key. 38 | * 39 | * This method implements {@link MailWizzApi_Cache_Abstract::get()}. 40 | * 41 | * @param string $key 42 | * @return mixed 43 | */ 44 | public function get($key) 45 | { 46 | return null; 47 | } 48 | 49 | /** 50 | * Delete cached data by given key. 51 | * 52 | * This method implements {@link MailWizzApi_Cache_Abstract::delete()}. 53 | * 54 | * @param string $key 55 | * @return bool 56 | */ 57 | public function delete($key) 58 | { 59 | return true; 60 | } 61 | 62 | /** 63 | * Delete all cached data. 64 | * 65 | * This method implements {@link MailWizzApi_Cache_Abstract::flush()}. 66 | * 67 | * @return bool 68 | */ 69 | public function flush() 70 | { 71 | return true; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/File.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Cache_File makes use of the file system in order to cache data. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Cache 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Cache_File extends MailWizzApi_Cache_Abstract 20 | { 21 | /** 22 | * @var string the path to the directory where the cache files will be stored. 23 | * 24 | * Please note, the cache directory needs to be writable by the web server (chmod 0777). 25 | * 26 | * Defaults to data/cache under same directory. 27 | */ 28 | private $_filesPath; 29 | 30 | /** 31 | * Cache data by given key. 32 | * 33 | * For consistency, the key will go through sha1() before it is saved. 34 | * 35 | * This method implements {@link MailWizzApi_Cache_Abstract::set()}. 36 | * 37 | * @param string $key 38 | * @param mixed $value 39 | * @return bool 40 | */ 41 | public function set($key, $value) 42 | { 43 | $value = serialize($value); 44 | if ($exists = $this->get($key)) { 45 | if ($value === serialize($exists)) { 46 | return true; 47 | } 48 | } 49 | $key = sha1($key); 50 | return (bool)@file_put_contents($this->getFilesPath() . '/' . $key.'.bin', $value); 51 | } 52 | 53 | /** 54 | * Get cached data by given key. 55 | * 56 | * For consistency, the key will go through sha1() 57 | * before it will be used to retrieve the cached data. 58 | * 59 | * This method implements {@link MailWizzApi_Cache_Abstract::get()}. 60 | * 61 | * @param string $key 62 | * @return mixed 63 | */ 64 | public function get($key) 65 | { 66 | $key = sha1($key); 67 | 68 | if (isset($this->_loaded[$key])) { 69 | return $this->_loaded[$key]; 70 | } 71 | 72 | if (!is_file($file = $this->getFilesPath() . '/' . $key.'.bin')) { 73 | return $this->_loaded[$key] = null; 74 | } 75 | 76 | $fileContents = (string)file_get_contents($file); 77 | return $this->_loaded[$key] = unserialize($fileContents); 78 | } 79 | 80 | /** 81 | * Delete cached data by given key. 82 | * 83 | * For consistency, the key will go through sha1() 84 | * before it will be used to delete the cached data. 85 | * 86 | * This method implements {@link MailWizzApi_Cache_Abstract::delete()}. 87 | * 88 | * @param string $key 89 | * @return bool 90 | */ 91 | public function delete($key) 92 | { 93 | $key = sha1($key); 94 | 95 | if (isset($this->_loaded[$key])) { 96 | unset($this->_loaded[$key]); 97 | } 98 | 99 | if (is_file($file = $this->getFilesPath() . '/' . $key.'.bin')) { 100 | @unlink($file); 101 | return true; 102 | } 103 | 104 | return false; 105 | } 106 | 107 | /** 108 | * Delete all cached data. 109 | * 110 | * This method implements {@link MailWizzApi_Cache_Abstract::flush()}. 111 | * 112 | * @return bool 113 | */ 114 | public function flush() 115 | { 116 | $this->_loaded = array(); 117 | return $this->doFlush($this->getFilesPath()); 118 | } 119 | 120 | /** 121 | * Set the cache path. 122 | * 123 | * @param string $path the path to the directory that will store the files 124 | * @return MailWizzApi_Cache_File 125 | */ 126 | public function setFilesPath($path) 127 | { 128 | if (file_exists($path) && is_dir($path)) { 129 | $this->_filesPath = $path; 130 | } 131 | return $this; 132 | } 133 | 134 | /** 135 | * Get the cache path. 136 | * 137 | * It defaults to "data/cache" under the same directory. 138 | * 139 | * Please make sure the given directoy is writable by the webserver(chmod 0777). 140 | * 141 | * @return string 142 | */ 143 | public function getFilesPath() 144 | { 145 | if (empty($this->_filesPath)) { 146 | $this->_filesPath = dirname(__FILE__) . '/data/cache'; 147 | } 148 | return $this->_filesPath; 149 | } 150 | 151 | /** 152 | * Helper method to clear the cache directory contents 153 | * 154 | * @param string $path 155 | * @return bool 156 | */ 157 | protected function doFlush($path) 158 | { 159 | if (!file_exists($path) || !is_dir($path)) { 160 | return false; 161 | } 162 | 163 | if (($handle = opendir($path)) === false) { 164 | return false; 165 | } 166 | 167 | while (($file = readdir($handle)) !== false) { 168 | if ($file[0] === '.') { 169 | continue; 170 | } 171 | 172 | $fullPath=$path.DIRECTORY_SEPARATOR.$file; 173 | 174 | if (is_dir($fullPath)) { 175 | $this->doFlush($fullPath); 176 | } else { 177 | @unlink($fullPath); 178 | } 179 | } 180 | 181 | closedir($handle); 182 | return true; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/Xcache.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Cache_Xcache makes use of the xcache extension in order to cache data in memory. 13 | * 14 | * As all the data will stay in memory, it is recommeded that will be used only if 15 | * the system has enough memory, or for development/small servers. 16 | * 17 | * @author Serban George Cristian 18 | * @package MailWizzApi 19 | * @subpackage Cache 20 | * @since 1.0 21 | */ 22 | class MailWizzApi_Cache_Xcache extends MailWizzApi_Cache_Abstract 23 | { 24 | /** 25 | * Cache data by given key. 26 | * 27 | * For consistency, the key will go through sha1() before it is saved. 28 | * 29 | * This method implements {@link MailWizzApi_Cache_Abstract::set()}. 30 | * 31 | * @param string $key 32 | * @param mixed $value 33 | * @return bool 34 | */ 35 | public function set($key, $value) 36 | { 37 | return xcache_set(sha1($key), $value, 0); 38 | } 39 | 40 | /** 41 | * Get cached data by given key. 42 | * 43 | * For consistency, the key will go through sha1() 44 | * before it will be used to retrieve the cached data. 45 | * 46 | * This method implements {@link MailWizzApi_Cache_Abstract::get()}. 47 | * 48 | * @param string $key 49 | * @return mixed 50 | */ 51 | public function get($key) 52 | { 53 | return xcache_isset(sha1($key)) ? xcache_get(sha1($key)) : null; 54 | } 55 | 56 | /** 57 | * Delete cached data by given key. 58 | * 59 | * For consistency, the key will go through sha1() 60 | * before it will be used to delete the cached data. 61 | * 62 | * This method implements {@link MailWizzApi_Cache_Abstract::delete()}. 63 | * 64 | * @param string $key 65 | * @return bool 66 | */ 67 | public function delete($key) 68 | { 69 | return xcache_unset(sha1($key)); 70 | } 71 | 72 | /** 73 | * Delete all cached data. 74 | * 75 | * This method implements {@link MailWizzApi_Cache_Abstract::flush()}. 76 | * 77 | * @return bool 78 | */ 79 | public function flush() 80 | { 81 | if (!defined('XC_TYPE_VAR')) { 82 | return false; 83 | } 84 | for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) { 85 | xcache_clear_cache(XC_TYPE_VAR, $i); 86 | } 87 | return true; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /MailWizzApi/Cache/data/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /MailWizzApi/Cache/data/db/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /MailWizzApi/Cache/data/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /MailWizzApi/Config.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Config contains the configuration class that is injected at runtime into the main application. 13 | * 14 | * It's only purpose is to set the needed data so that the API calls will run without problems. 15 | * 16 | * @author Serban George Cristian 17 | * @package MailWizzApi 18 | * @since 1.0 19 | */ 20 | class MailWizzApi_Config extends MailWizzApi_Base 21 | { 22 | /** 23 | * @var string the api public key 24 | */ 25 | public $publicKey; 26 | 27 | /** 28 | * @var string the api private key. 29 | */ 30 | public $privateKey; 31 | 32 | /** 33 | * @var string the preffered charset. 34 | */ 35 | public $charset = 'utf-8'; 36 | 37 | /** 38 | * @var string the API url. 39 | */ 40 | private $_apiUrl; 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param array $config the config array that will populate the class properties. 46 | * 47 | * @throws ReflectionException 48 | */ 49 | public function __construct(array $config = array()) 50 | { 51 | $this->populateFromArray($config); 52 | } 53 | 54 | /** 55 | * Setter for the API url. 56 | * 57 | * Please note, this url should NOT contain any endpoint, 58 | * just the base url to the API. 59 | * 60 | * Also, a basic url check is done, but you need to make sure the url is valid. 61 | * 62 | * @param mixed $url 63 | * 64 | * @return MailWizzApi_Config 65 | * @throws Exception 66 | */ 67 | public function setApiUrl($url) 68 | { 69 | if (!parse_url($url, PHP_URL_HOST)) { 70 | throw new Exception('Please set a valid api base url.'); 71 | } 72 | 73 | $this->_apiUrl = trim($url, '/') . '/'; 74 | return $this; 75 | } 76 | 77 | /** 78 | * Getter for the API url. 79 | * 80 | * Also, you can use the $endpoint param to point the request to a certain endpoint. 81 | * 82 | * @param string $endpoint 83 | * 84 | * @return string 85 | * @throws Exception 86 | */ 87 | public function getApiUrl($endpoint = null) 88 | { 89 | if ($this->_apiUrl === null) { 90 | throw new Exception('Please set the api base url.'); 91 | } 92 | 93 | return $this->_apiUrl . $endpoint; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/CampaignBounces.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_CampaignBounces handles all the API calls for campaign bounces. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_CampaignBounces extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get bounces from a certain campaign 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param string $campaignUid 27 | * @param integer $page 28 | * @param integer $perPage 29 | * 30 | * @return MailWizzApi_Http_Response 31 | * @throws ReflectionException 32 | */ 33 | public function getBounces($campaignUid, $page = 1, $perPage = 10) 34 | { 35 | $client = new MailWizzApi_Http_Client(array( 36 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 37 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/bounces', $campaignUid)), 38 | 'paramsGet' => array( 39 | 'page' => (int)$page, 40 | 'per_page' => (int)$perPage, 41 | ), 42 | 'enableCache' => true, 43 | )); 44 | 45 | return $response = $client->request(); 46 | } 47 | 48 | /** 49 | * Create a new bounce in the given campaign 50 | * 51 | * @param string $campaignUid 52 | * @param array $data 53 | * 54 | * @return MailWizzApi_Http_Response 55 | * @throws ReflectionException 56 | */ 57 | public function create($campaignUid, array $data) 58 | { 59 | $client = new MailWizzApi_Http_Client(array( 60 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 61 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/bounces', (string)$campaignUid)), 62 | 'paramsPost' => $data, 63 | )); 64 | 65 | return $response = $client->request(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/CampaignUnsubscribes.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_CampaignUnsubscribes handles all the API calls for campaign unsubscribes. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_CampaignUnsubscribes extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get unsubscribes from a certain campaign 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param string $campaignUid 27 | * @param integer $page 28 | * @param integer $perPage 29 | * 30 | * @return MailWizzApi_Http_Response 31 | * @throws ReflectionException 32 | */ 33 | public function getUnsubscribes($campaignUid, $page = 1, $perPage = 10) 34 | { 35 | $client = new MailWizzApi_Http_Client(array( 36 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 37 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/unsubscribes', $campaignUid)), 38 | 'paramsGet' => array( 39 | 'page' => (int)$page, 40 | 'per_page' => (int)$perPage, 41 | ), 42 | 'enableCache' => true, 43 | )); 44 | 45 | return $response = $client->request(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/Campaigns.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_Campaigns handles all the API calls for campaigns. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_Campaigns extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get all the campaigns of the current customer 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param integer $page 27 | * @param integer $perPage 28 | * 29 | * @return MailWizzApi_Http_Response 30 | * @throws ReflectionException 31 | */ 32 | public function getCampaigns($page = 1, $perPage = 10) 33 | { 34 | $client = new MailWizzApi_Http_Client(array( 35 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 36 | 'url' => $this->getConfig()->getApiUrl('campaigns'), 37 | 'paramsGet' => array( 38 | 'page' => (int)$page, 39 | 'per_page' => (int)$perPage 40 | ), 41 | 'enableCache' => true, 42 | )); 43 | 44 | return $response = $client->request(); 45 | } 46 | 47 | /** 48 | * Get one campaign 49 | * 50 | * Note, the results returned by this endpoint can be cached. 51 | * 52 | * @param string $campaignUid 53 | * 54 | * @return MailWizzApi_Http_Response 55 | * @throws ReflectionException 56 | */ 57 | public function getCampaign($campaignUid) 58 | { 59 | $client = new MailWizzApi_Http_Client(array( 60 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 61 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s', (string)$campaignUid)), 62 | 'paramsGet' => array(), 63 | 'enableCache' => true, 64 | )); 65 | 66 | return $response = $client->request(); 67 | } 68 | 69 | /** 70 | * Create a new campaign 71 | * 72 | * @param array $data 73 | * 74 | * @return MailWizzApi_Http_Response 75 | * @throws ReflectionException 76 | */ 77 | public function create(array $data) 78 | { 79 | if (isset($data['template']['content'])) { 80 | $data['template']['content'] = base64_encode($data['template']['content']); 81 | } 82 | 83 | if (isset($data['template']['archive'])) { 84 | $data['template']['archive'] = base64_encode($data['template']['archive']); 85 | } 86 | 87 | if (isset($data['template']['plain_text'])) { 88 | $data['template']['plain_text'] = base64_encode($data['template']['plain_text']); 89 | } 90 | 91 | $client = new MailWizzApi_Http_Client(array( 92 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 93 | 'url' => $this->getConfig()->getApiUrl('campaigns'), 94 | 'paramsPost' => array( 95 | 'campaign' => $data 96 | ), 97 | )); 98 | 99 | return $response = $client->request(); 100 | } 101 | 102 | /** 103 | * Update existing campaign for the customer 104 | * 105 | * @param string $campaignUid 106 | * @param array $data 107 | * 108 | * @return MailWizzApi_Http_Response 109 | * @throws ReflectionException 110 | */ 111 | public function update($campaignUid, array $data) 112 | { 113 | if (isset($data['template']['content'])) { 114 | $data['template']['content'] = base64_encode($data['template']['content']); 115 | } 116 | 117 | if (isset($data['template']['archive'])) { 118 | $data['template']['archive'] = base64_encode($data['template']['archive']); 119 | } 120 | 121 | if (isset($data['template']['plain_text'])) { 122 | $data['template']['plain_text'] = base64_encode($data['template']['plain_text']); 123 | } 124 | 125 | $client = new MailWizzApi_Http_Client(array( 126 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 127 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s', $campaignUid)), 128 | 'paramsPut' => array( 129 | 'campaign' => $data 130 | ), 131 | )); 132 | 133 | return $response = $client->request(); 134 | } 135 | 136 | /** 137 | * Copy existing campaign for the customer 138 | * 139 | * @param string $campaignUid 140 | * 141 | * @return MailWizzApi_Http_Response 142 | * @throws ReflectionException 143 | */ 144 | public function copy($campaignUid) 145 | { 146 | $client = new MailWizzApi_Http_Client(array( 147 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 148 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/copy', $campaignUid)), 149 | )); 150 | 151 | return $response = $client->request(); 152 | } 153 | 154 | /** 155 | * Pause/Unpause existing campaign 156 | * 157 | * @param string $campaignUid 158 | * 159 | * @return MailWizzApi_Http_Response 160 | * @throws ReflectionException 161 | */ 162 | public function pauseUnpause($campaignUid) 163 | { 164 | $client = new MailWizzApi_Http_Client(array( 165 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 166 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/pause-unpause', $campaignUid)), 167 | )); 168 | 169 | return $response = $client->request(); 170 | } 171 | 172 | /** 173 | * Mark existing campaign as sent 174 | * 175 | * @param string $campaignUid 176 | * 177 | * @return MailWizzApi_Http_Response 178 | * @throws ReflectionException 179 | */ 180 | public function markSent($campaignUid) 181 | { 182 | $client = new MailWizzApi_Http_Client(array( 183 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 184 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/mark-sent', $campaignUid)), 185 | )); 186 | 187 | return $response = $client->request(); 188 | } 189 | 190 | /** 191 | * Delete existing campaign for the customer 192 | * 193 | * @param string $campaignUid 194 | * 195 | * @return MailWizzApi_Http_Response 196 | * @throws ReflectionException 197 | */ 198 | public function delete($campaignUid) 199 | { 200 | $client = new MailWizzApi_Http_Client(array( 201 | 'method' => MailWizzApi_Http_Client::METHOD_DELETE, 202 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s', $campaignUid)), 203 | )); 204 | 205 | return $response = $client->request(); 206 | } 207 | 208 | /** 209 | * Get the stats for an existing campaign for the customer 210 | * 211 | * @param string $campaignUid 212 | * 213 | * @return MailWizzApi_Http_Response 214 | * @throws ReflectionException 215 | */ 216 | public function getStats($campaignUid) 217 | { 218 | $client = new MailWizzApi_Http_Client(array( 219 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 220 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/stats', $campaignUid)), 221 | )); 222 | 223 | return $response = $client->request(); 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/CampaignsTracking.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_CampaignsTracking handles all the API calls for campaigns. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_CampaignsTracking extends MailWizzApi_Base 20 | { 21 | /** 22 | * Track campaign url click for certain subscriber 23 | * 24 | * @param string $campaignUid 25 | * @param string $subscriberUid 26 | * @param string $hash 27 | * 28 | * @return MailWizzApi_Http_Response 29 | * @throws ReflectionException 30 | */ 31 | public function trackUrl($campaignUid, $subscriberUid, $hash) 32 | { 33 | $client = new MailWizzApi_Http_Client(array( 34 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 35 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/track-url/%s/%s', (string)$campaignUid, (string)$subscriberUid, (string)$hash)), 36 | 'paramsGet' => array(), 37 | )); 38 | 39 | return $response = $client->request(); 40 | } 41 | 42 | /** 43 | * Track campaign open for certain subscriber 44 | * 45 | * @param string $campaignUid 46 | * @param string $subscriberUid 47 | * 48 | * @return MailWizzApi_Http_Response 49 | * @throws ReflectionException 50 | */ 51 | public function trackOpening($campaignUid, $subscriberUid) 52 | { 53 | $client = new MailWizzApi_Http_Client(array( 54 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 55 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/track-opening/%s', (string)$campaignUid, (string)$subscriberUid)), 56 | 'paramsGet' => array(), 57 | )); 58 | 59 | return $response = $client->request(); 60 | } 61 | 62 | /** 63 | * Track campaign unsubscribe for certain subscriber 64 | * 65 | * @param string $campaignUid 66 | * @param string $subscriberUid 67 | * @param array $data 68 | * 69 | * @return MailWizzApi_Http_Response 70 | * @throws ReflectionException 71 | */ 72 | public function trackUnsubscribe($campaignUid, $subscriberUid, array $data = array()) 73 | { 74 | $client = new MailWizzApi_Http_Client(array( 75 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 76 | 'url' => $this->getConfig()->getApiUrl(sprintf('campaigns/%s/track-unsubscribe/%s', (string)$campaignUid, (string)$subscriberUid)), 77 | 'paramsPost' => $data, 78 | )); 79 | 80 | return $response = $client->request(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/Countries.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_Countries handles all the API calls for handling the countries and their zones. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_Countries extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get all available countries 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param integer $page 27 | * @param integer $perPage 28 | * 29 | * @return MailWizzApi_Http_Response 30 | * @throws ReflectionException 31 | */ 32 | public function getCountries($page = 1, $perPage = 10) 33 | { 34 | $client = new MailWizzApi_Http_Client(array( 35 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 36 | 'url' => $this->getConfig()->getApiUrl('countries'), 37 | 'paramsGet' => array( 38 | 'page' => (int)$page, 39 | 'per_page' => (int)$perPage 40 | ), 41 | 'enableCache' => true, 42 | )); 43 | 44 | return $response = $client->request(); 45 | } 46 | 47 | /** 48 | * Get all available country zones 49 | * 50 | * Note, the results returned by this endpoint can be cached. 51 | * 52 | * @param integer $countryId 53 | * @param integer $page 54 | * @param integer $perPage 55 | * 56 | * @return MailWizzApi_Http_Response 57 | * @throws ReflectionException 58 | */ 59 | public function getZones($countryId, $page = 1, $perPage = 10) 60 | { 61 | $client = new MailWizzApi_Http_Client(array( 62 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 63 | 'url' => $this->getConfig()->getApiUrl(sprintf('countries/%d/zones', $countryId)), 64 | 'paramsGet' => array( 65 | 'page' => (int)$page, 66 | 'per_page' => (int)$perPage 67 | ), 68 | 'enableCache' => true, 69 | )); 70 | 71 | return $response = $client->request(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/Customers.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_Customers handles all the API calls for customers. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_Customers extends MailWizzApi_Base 20 | { 21 | /** 22 | * Create a new mail list for the customer 23 | * 24 | * The $data param must contain following indexed arrays: 25 | * -> customer 26 | * -> company 27 | * 28 | * @param array $data 29 | * 30 | * @return MailWizzApi_Http_Response 31 | * @throws ReflectionException 32 | */ 33 | public function create(array $data) 34 | { 35 | if (isset($data['customer']['password'])) { 36 | $data['customer']['confirm_password'] = $data['customer']['password']; 37 | } 38 | 39 | if (isset($data['customer']['email'])) { 40 | $data['customer']['confirm_email'] = $data['customer']['email']; 41 | } 42 | 43 | if (empty($data['customer']['timezone'])) { 44 | $data['customer']['timezone'] = 'UTC'; 45 | } 46 | 47 | $client = new MailWizzApi_Http_Client(array( 48 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 49 | 'url' => $this->getConfig()->getApiUrl('customers'), 50 | 'paramsPost' => $data, 51 | )); 52 | 53 | return $response = $client->request(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/ListFields.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_ListFields handles all the API calls for handling the list custom fields. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_ListFields extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get fields from a certain mail list 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param string $listUid 27 | * 28 | * @return MailWizzApi_Http_Response 29 | * @throws ReflectionException 30 | */ 31 | public function getFields($listUid) 32 | { 33 | $client = new MailWizzApi_Http_Client(array( 34 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 35 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/fields', $listUid)), 36 | 'paramsGet' => array(), 37 | 'enableCache' => true, 38 | )); 39 | 40 | return $response = $client->request(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/ListSegments.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_ListSegments handles all the API calls for handling the list segments. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_ListSegments extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get segments from a certain mail list 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param string $listUid 27 | * @param integer $page 28 | * @param integer $perPage 29 | * 30 | * @return MailWizzApi_Http_Response 31 | * @throws ReflectionException 32 | */ 33 | public function getSegments($listUid, $page = 1, $perPage = 10) 34 | { 35 | $client = new MailWizzApi_Http_Client(array( 36 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 37 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/segments', $listUid)), 38 | 'paramsGet' => array( 39 | 'page' => (int)$page, 40 | 'per_page' => (int)$perPage 41 | ), 42 | 'enableCache' => true, 43 | )); 44 | 45 | return $response = $client->request(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/ListSubscribers.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_ListSubscribers handles all the API calls for lists subscribers. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_ListSubscribers extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get subscribers from a certain mail list 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param string $listUid 27 | * @param integer $page 28 | * @param integer $perPage 29 | * 30 | * @return MailWizzApi_Http_Response 31 | * @throws Exception 32 | */ 33 | public function getSubscribers($listUid, $page = 1, $perPage = 10) 34 | { 35 | $client = new MailWizzApi_Http_Client(array( 36 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 37 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers', $listUid)), 38 | 'paramsGet' => array( 39 | 'page' => (int)$page, 40 | 'per_page' => (int)$perPage, 41 | ), 42 | 'enableCache' => true, 43 | )); 44 | 45 | return $response = $client->request(); 46 | } 47 | 48 | /** 49 | * Get one subscriber from a certain mail list 50 | * 51 | * Note, the results returned by this endpoint can be cached. 52 | * 53 | * @param string $listUid 54 | * @param string $subscriberUid 55 | * @return MailWizzApi_Http_Response 56 | * @throws Exception 57 | */ 58 | public function getSubscriber($listUid, $subscriberUid) 59 | { 60 | $client = new MailWizzApi_Http_Client(array( 61 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 62 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/%s', (string)$listUid, (string)$subscriberUid)), 63 | 'paramsGet' => array(), 64 | 'enableCache' => true, 65 | )); 66 | 67 | return $response = $client->request(); 68 | } 69 | 70 | /** 71 | * Create a new subscriber in the given list 72 | * 73 | * @param string $listUid 74 | * @param array $data 75 | * @return MailWizzApi_Http_Response 76 | * @throws Exception 77 | */ 78 | public function create($listUid, array $data) 79 | { 80 | $client = new MailWizzApi_Http_Client(array( 81 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 82 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers', (string)$listUid)), 83 | 'paramsPost' => $data, 84 | )); 85 | 86 | return $response = $client->request(); 87 | } 88 | 89 | /** 90 | * Create subscribers in bulk in the given list 91 | * This feature is available since MailWizz 1.8.1 92 | * 93 | * @param string $listUid 94 | * @param array $data 95 | * @return MailWizzApi_Http_Response 96 | * @throws Exception 97 | */ 98 | public function createBulk($listUid, array $data) 99 | { 100 | $client = new MailWizzApi_Http_Client(array( 101 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 102 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/bulk', (string)$listUid)), 103 | 'paramsPost' => array('subscribers' => $data), 104 | )); 105 | 106 | return $response = $client->request(); 107 | } 108 | 109 | /** 110 | * Update existing subscriber in given list 111 | * 112 | * @param string $listUid 113 | * @param string $subscriberUid 114 | * @param array $data 115 | * @return MailWizzApi_Http_Response 116 | * @throws Exception 117 | */ 118 | public function update($listUid, $subscriberUid, array $data) 119 | { 120 | $client = new MailWizzApi_Http_Client(array( 121 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 122 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/%s', (string)$listUid, (string)$subscriberUid)), 123 | 'paramsPut' => $data, 124 | )); 125 | 126 | return $response = $client->request(); 127 | } 128 | 129 | /** 130 | * Update existing subscriber by email address 131 | * 132 | * @param string $listUid 133 | * @param string $emailAddress 134 | * @param array $data 135 | * @return MailWizzApi_Http_Response 136 | * @throws Exception 137 | */ 138 | public function updateByEmail($listUid, $emailAddress, array $data) 139 | { 140 | $response = $this->emailSearch($listUid, $emailAddress); 141 | 142 | // the request failed. 143 | if ($response->getIsCurlError()) { 144 | return $response; 145 | } 146 | 147 | $bodyData = $response->body->itemAt('data'); 148 | 149 | // subscriber not found. 150 | if ($response->getIsError() && $response->getHttpCode() == 404) { 151 | return $response; 152 | } 153 | 154 | if (empty($bodyData['subscriber_uid'])) { 155 | return $response; 156 | } 157 | 158 | return $this->update($listUid, $bodyData['subscriber_uid'], $data); 159 | } 160 | 161 | /** 162 | * Unsubscribe existing subscriber from given list 163 | * 164 | * @param string $listUid 165 | * @param string $subscriberUid 166 | * @return MailWizzApi_Http_Response 167 | * @throws Exception 168 | */ 169 | public function unsubscribe($listUid, $subscriberUid) 170 | { 171 | $client = new MailWizzApi_Http_Client(array( 172 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 173 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/%s/unsubscribe', (string)$listUid, (string)$subscriberUid)), 174 | 'paramsPut' => array(), 175 | )); 176 | 177 | return $response = $client->request(); 178 | } 179 | 180 | /** 181 | * Unsubscribe existing subscriber by email address 182 | * 183 | * @param string $listUid 184 | * @param string $emailAddress 185 | * @return MailWizzApi_Http_Response 186 | * @throws Exception 187 | */ 188 | public function unsubscribeByEmail($listUid, $emailAddress) 189 | { 190 | $response = $this->emailSearch($listUid, $emailAddress); 191 | 192 | // the request failed. 193 | if ($response->getIsCurlError()) { 194 | return $response; 195 | } 196 | 197 | $bodyData = $response->body->itemAt('data'); 198 | 199 | // subscriber not found. 200 | if ($response->getIsError() && $response->getHttpCode() == 404) { 201 | return $response; 202 | } 203 | 204 | if (empty($bodyData['subscriber_uid'])) { 205 | return $response; 206 | } 207 | 208 | return $this->unsubscribe($listUid, $bodyData['subscriber_uid']); 209 | } 210 | 211 | /** 212 | * Unsubscribe existing subscriber by email address from all lists 213 | * 214 | * @param string $emailAddress 215 | * @return MailWizzApi_Http_Response 216 | * @throws Exception 217 | */ 218 | public function unsubscribeByEmailFromAllLists($emailAddress) 219 | { 220 | $client = new MailWizzApi_Http_Client(array( 221 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 222 | 'url' => $this->getConfig()->getApiUrl('lists/subscribers/unsubscribe-by-email-from-all-lists'), 223 | 'paramsPut' => array( 224 | 'EMAIL' => $emailAddress, 225 | ), 226 | )); 227 | 228 | return $response = $client->request(); 229 | } 230 | 231 | 232 | /** 233 | * Delete existing subscriber in given list 234 | * 235 | * @param string $listUid 236 | * @param string $subscriberUid 237 | * @return MailWizzApi_Http_Response 238 | * @throws Exception 239 | */ 240 | public function delete($listUid, $subscriberUid) 241 | { 242 | $client = new MailWizzApi_Http_Client(array( 243 | 'method' => MailWizzApi_Http_Client::METHOD_DELETE, 244 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/%s', (string)$listUid, (string)$subscriberUid)), 245 | 'paramsDelete' => array(), 246 | )); 247 | 248 | return $response = $client->request(); 249 | } 250 | 251 | /** 252 | * Delete existing subscriber by email address 253 | * 254 | * @param string $listUid 255 | * @param string $emailAddress 256 | * @return MailWizzApi_Http_Response 257 | * @throws Exception 258 | */ 259 | public function deleteByEmail($listUid, $emailAddress) 260 | { 261 | $response = $this->emailSearch($listUid, $emailAddress); 262 | $bodyData = $response->body->itemAt('data'); 263 | 264 | if ($response->getIsError() || empty($bodyData['subscriber_uid'])) { 265 | return $response; 266 | } 267 | 268 | return $this->delete($listUid, $bodyData['subscriber_uid']); 269 | } 270 | 271 | /** 272 | * Search in a list for given subscriber by email address 273 | * 274 | * @param string $listUid 275 | * @param string $emailAddress 276 | * @return MailWizzApi_Http_Response 277 | * @throws Exception 278 | */ 279 | public function emailSearch($listUid, $emailAddress) 280 | { 281 | $client = new MailWizzApi_Http_Client(array( 282 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 283 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/search-by-email', (string)$listUid)), 284 | 'paramsGet' => array('EMAIL' => (string)$emailAddress), 285 | )); 286 | 287 | return $response = $client->request(); 288 | } 289 | 290 | /** 291 | * Search in a all lists for given subscriber by email address 292 | * Please note that this is available only for mailwizz >= 1.3.6.2 293 | * 294 | * @param string $emailAddress 295 | * @return MailWizzApi_Http_Response 296 | * @throws Exception 297 | */ 298 | public function emailSearchAllLists($emailAddress) 299 | { 300 | $client = new MailWizzApi_Http_Client(array( 301 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 302 | 'url' => $this->getConfig()->getApiUrl('lists/subscribers/search-by-email-in-all-lists'), 303 | 'paramsGet' => array('EMAIL' => (string)$emailAddress), 304 | )); 305 | 306 | return $response = $client->request(); 307 | } 308 | 309 | /** 310 | * Search in a list by custom fields 311 | * 312 | * @param string $listUid 313 | * @param array $fields 314 | * @param int $page 315 | * @param int $perPage 316 | * 317 | * @return MailWizzApi_Http_Response 318 | * @throws Exception 319 | */ 320 | public function searchByCustomFields($listUid, array $fields = array(), $page = 1, $perPage = 10) 321 | { 322 | $paramsGet = $fields; 323 | $paramsGet['page'] = (int)$page; 324 | $paramsGet['per_page'] = (int)$perPage; 325 | 326 | $client = new MailWizzApi_Http_Client(array( 327 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 328 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers/search-by-custom-fields', (string)$listUid)), 329 | 'paramsGet' => $paramsGet, 330 | )); 331 | 332 | return $response = $client->request(); 333 | } 334 | 335 | /** 336 | * Search in a list for given subscribers by status 337 | * 338 | * @param string $listUid 339 | * @param string $status 340 | * @param int $page 341 | * @param int $perPage 342 | * 343 | * @return MailWizzApi_Http_Response 344 | * @throws ReflectionException 345 | */ 346 | public function searchByStatus($listUid, $status, $page = 1, $perPage = 10) 347 | { 348 | $client = new MailWizzApi_Http_Client(array( 349 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 350 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/subscribers', $listUid)), 351 | 'paramsGet' => array( 352 | 'page' => (int)$page, 353 | 'per_page' => (int)$perPage, 354 | 'status' => $status, 355 | ), 356 | 'enableCache' => true, 357 | )); 358 | 359 | return $response = $client->request(); 360 | } 361 | 362 | /** 363 | * Get only the confirmed subscribers 364 | * 365 | * @param string $listUid 366 | * @param int $page 367 | * @param int $perPage 368 | * 369 | * @return MailWizzApi_Http_Response 370 | * @throws ReflectionException 371 | */ 372 | public function getConfirmedSubscribers($listUid, $page = 1, $perPage = 10) 373 | { 374 | return $this->searchByStatus($listUid, 'confirmed', $page, $perPage); 375 | } 376 | 377 | /** 378 | * Get only the unconfirmed subscribers 379 | * 380 | * @param string $listUid 381 | * @param int $page 382 | * @param int $perPage 383 | * 384 | * @return MailWizzApi_Http_Response 385 | * @throws ReflectionException 386 | */ 387 | public function getUnconfirmedSubscribers($listUid, $page = 1, $perPage = 10) 388 | { 389 | return $this->searchByStatus($listUid, 'unconfirmed', $page, $perPage); 390 | } 391 | 392 | /** 393 | * Get only the unsubscribed subscribers 394 | * 395 | * @param string $listUid 396 | * @param int $page 397 | * @param int $perPage 398 | * 399 | * @return MailWizzApi_Http_Response 400 | * @throws ReflectionException 401 | */ 402 | public function getUnsubscribedSubscribers($listUid, $page = 1, $perPage = 10) 403 | { 404 | return $this->searchByStatus($listUid, 'unsubscribed', $page, $perPage); 405 | } 406 | 407 | /** 408 | * Create or update a subscriber in given list 409 | * 410 | * @param string $listUid 411 | * @param array $data 412 | * @return MailWizzApi_Http_Response 413 | * @throws Exception 414 | */ 415 | public function createUpdate($listUid, $data) 416 | { 417 | $emailAddress = !empty($data['EMAIL']) ? $data['EMAIL'] : null; 418 | $response = $this->emailSearch($listUid, $emailAddress); 419 | 420 | // the request failed. 421 | if ($response->getIsCurlError()) { 422 | return $response; 423 | } 424 | 425 | $bodyData = $response->body->itemAt('data'); 426 | 427 | // subscriber not found. 428 | if ($response->getIsError() && $response->getHttpCode() == 404) { 429 | return $this->create($listUid, $data); 430 | } 431 | 432 | if (empty($bodyData['subscriber_uid'])) { 433 | return $response; 434 | } 435 | 436 | return $this->update($listUid, $bodyData['subscriber_uid'], $data); 437 | } 438 | } 439 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/Lists.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_Lists handles all the API calls for lists. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_Lists extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get all the mail list of the current customer 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param integer $page 27 | * @param integer $perPage 28 | * 29 | * @return MailWizzApi_Http_Response 30 | * @throws ReflectionException 31 | */ 32 | public function getLists($page = 1, $perPage = 10) 33 | { 34 | $client = new MailWizzApi_Http_Client(array( 35 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 36 | 'url' => $this->getConfig()->getApiUrl('lists'), 37 | 'paramsGet' => array( 38 | 'page' => (int)$page, 39 | 'per_page' => (int)$perPage 40 | ), 41 | 'enableCache' => true, 42 | )); 43 | 44 | return $response = $client->request(); 45 | } 46 | 47 | /** 48 | * Get one list 49 | * 50 | * Note, the results returned by this endpoint can be cached. 51 | * 52 | * @param string $listUid 53 | * 54 | * @return MailWizzApi_Http_Response 55 | * @throws ReflectionException 56 | */ 57 | public function getList($listUid) 58 | { 59 | $client = new MailWizzApi_Http_Client(array( 60 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 61 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s', (string)$listUid)), 62 | 'paramsGet' => array(), 63 | 'enableCache' => true, 64 | )); 65 | 66 | return $response = $client->request(); 67 | } 68 | 69 | /** 70 | * Create a new mail list for the customer 71 | * 72 | * The $data param must contain following indexed arrays: 73 | * -> general 74 | * -> defaults 75 | * -> notifications 76 | * -> company 77 | * 78 | * @param array $data 79 | * 80 | * @return MailWizzApi_Http_Response 81 | * @throws ReflectionException 82 | */ 83 | public function create(array $data) 84 | { 85 | $client = new MailWizzApi_Http_Client(array( 86 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 87 | 'url' => $this->getConfig()->getApiUrl('lists'), 88 | 'paramsPost' => $data, 89 | )); 90 | 91 | return $response = $client->request(); 92 | } 93 | 94 | /** 95 | * Update existing mail list for the customer 96 | * 97 | * The $data param must contain following indexed arrays: 98 | * -> general 99 | * -> defaults 100 | * -> notifications 101 | * -> company 102 | * 103 | * @param string $listUid 104 | * @param array $data 105 | * 106 | * @return MailWizzApi_Http_Response 107 | * @throws ReflectionException 108 | */ 109 | public function update($listUid, array $data) 110 | { 111 | $client = new MailWizzApi_Http_Client(array( 112 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 113 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s', $listUid)), 114 | 'paramsPut' => $data, 115 | )); 116 | 117 | return $response = $client->request(); 118 | } 119 | 120 | /** 121 | * Copy existing mail list for the customer 122 | * 123 | * @param string $listUid 124 | * 125 | * @return MailWizzApi_Http_Response 126 | * @throws ReflectionException 127 | */ 128 | public function copy($listUid) 129 | { 130 | $client = new MailWizzApi_Http_Client(array( 131 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 132 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s/copy', $listUid)), 133 | )); 134 | 135 | return $response = $client->request(); 136 | } 137 | 138 | /** 139 | * Delete existing mail list for the customer 140 | * 141 | * @param string $listUid 142 | * 143 | * @return MailWizzApi_Http_Response 144 | * @throws ReflectionException 145 | */ 146 | public function delete($listUid) 147 | { 148 | $client = new MailWizzApi_Http_Client(array( 149 | 'method' => MailWizzApi_Http_Client::METHOD_DELETE, 150 | 'url' => $this->getConfig()->getApiUrl(sprintf('lists/%s', $listUid)), 151 | )); 152 | 153 | return $response = $client->request(); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/Templates.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_Templates handles all the API calls for email templates. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_Templates extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get all the email templates of the current customer 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param integer $page 27 | * @param integer $perPage 28 | * 29 | * @return MailWizzApi_Http_Response 30 | * @throws ReflectionException 31 | */ 32 | public function getTemplates($page = 1, $perPage = 10) 33 | { 34 | $client = new MailWizzApi_Http_Client(array( 35 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 36 | 'url' => $this->getConfig()->getApiUrl('templates'), 37 | 'paramsGet' => array( 38 | 'page' => (int)$page, 39 | 'per_page' => (int)$perPage 40 | ), 41 | 'enableCache' => true, 42 | )); 43 | 44 | return $response = $client->request(); 45 | } 46 | 47 | /** 48 | * Search through all the email templates of the current customer 49 | * 50 | * Note, the results returned by this endpoint can be cached. 51 | * 52 | * @param integer $page 53 | * @param integer $perPage 54 | * @param array $filter 55 | * 56 | * @return MailWizzApi_Http_Response 57 | * @throws ReflectionException 58 | * @since MailWizz 1.4.4 59 | */ 60 | public function searchTemplates($page = 1, $perPage = 10, array $filter = array()) 61 | { 62 | $client = new MailWizzApi_Http_Client(array( 63 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 64 | 'url' => $this->getConfig()->getApiUrl('templates'), 65 | 'paramsGet' => array( 66 | 'page' => (int)$page, 67 | 'per_page' => (int)$perPage, 68 | 'filter' => $filter, 69 | ), 70 | 'enableCache' => true, 71 | )); 72 | 73 | return $response = $client->request(); 74 | } 75 | 76 | /** 77 | * Get one template 78 | * 79 | * Note, the results returned by this endpoint can be cached. 80 | * 81 | * @param string $templateUid 82 | * 83 | * @return MailWizzApi_Http_Response 84 | * @throws ReflectionException 85 | */ 86 | public function getTemplate($templateUid) 87 | { 88 | $client = new MailWizzApi_Http_Client(array( 89 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 90 | 'url' => $this->getConfig()->getApiUrl(sprintf('templates/%s', (string)$templateUid)), 91 | 'paramsGet' => array(), 92 | 'enableCache' => true, 93 | )); 94 | 95 | return $response = $client->request(); 96 | } 97 | 98 | /** 99 | * Create a new template 100 | * 101 | * @param array $data 102 | * 103 | * @return MailWizzApi_Http_Response 104 | * @throws ReflectionException 105 | */ 106 | public function create(array $data) 107 | { 108 | if (isset($data['content'])) { 109 | $data['content'] = base64_encode($data['content']); 110 | } 111 | 112 | if (isset($data['archive'])) { 113 | $data['archive'] = base64_encode($data['archive']); 114 | } 115 | 116 | $client = new MailWizzApi_Http_Client(array( 117 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 118 | 'url' => $this->getConfig()->getApiUrl('templates'), 119 | 'paramsPost' => array( 120 | 'template' => $data 121 | ), 122 | )); 123 | 124 | return $response = $client->request(); 125 | } 126 | 127 | /** 128 | * Update existing template for the customer 129 | * 130 | * @param string $templateUid 131 | * @param array $data 132 | * 133 | * @return MailWizzApi_Http_Response 134 | * @throws ReflectionException 135 | */ 136 | public function update($templateUid, array $data) 137 | { 138 | if (isset($data['content'])) { 139 | $data['content'] = base64_encode($data['content']); 140 | } 141 | 142 | if (isset($data['archive'])) { 143 | $data['archive'] = base64_encode($data['archive']); 144 | } 145 | 146 | $client = new MailWizzApi_Http_Client(array( 147 | 'method' => MailWizzApi_Http_Client::METHOD_PUT, 148 | 'url' => $this->getConfig()->getApiUrl(sprintf('templates/%s', $templateUid)), 149 | 'paramsPut' => array( 150 | 'template' => $data 151 | ), 152 | )); 153 | 154 | return $response = $client->request(); 155 | } 156 | 157 | /** 158 | * Delete existing template for the customer 159 | * 160 | * @param string $templateUid 161 | * 162 | * @return MailWizzApi_Http_Response 163 | * @throws ReflectionException 164 | */ 165 | public function delete($templateUid) 166 | { 167 | $client = new MailWizzApi_Http_Client(array( 168 | 'method' => MailWizzApi_Http_Client::METHOD_DELETE, 169 | 'url' => $this->getConfig()->getApiUrl(sprintf('templates/%s', $templateUid)), 170 | )); 171 | 172 | return $response = $client->request(); 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /MailWizzApi/Endpoint/TransactionalEmails.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Endpoint_TransactionalEmails handles all the API calls for transactional emails. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Endpoint 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Endpoint_TransactionalEmails extends MailWizzApi_Base 20 | { 21 | /** 22 | * Get all transactional emails of the current customer 23 | * 24 | * Note, the results returned by this endpoint can be cached. 25 | * 26 | * @param integer $page 27 | * @param integer $perPage 28 | * 29 | * @return MailWizzApi_Http_Response 30 | * @throws Exception 31 | */ 32 | public function getEmails($page = 1, $perPage = 10) 33 | { 34 | $client = new MailWizzApi_Http_Client(array( 35 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 36 | 'url' => $this->getConfig()->getApiUrl('transactional-emails'), 37 | 'paramsGet' => array( 38 | 'page' => (int)$page, 39 | 'per_page' => (int)$perPage 40 | ), 41 | 'enableCache' => true, 42 | )); 43 | 44 | return $response = $client->request(); 45 | } 46 | 47 | /** 48 | * Get one transactional email 49 | * 50 | * Note, the results returned by this endpoint can be cached. 51 | * 52 | * @param string $emailUid 53 | * 54 | * @return MailWizzApi_Http_Response 55 | * @throws Exception 56 | */ 57 | public function getEmail($emailUid) 58 | { 59 | $client = new MailWizzApi_Http_Client(array( 60 | 'method' => MailWizzApi_Http_Client::METHOD_GET, 61 | 'url' => $this->getConfig()->getApiUrl(sprintf('transactional-emails/%s', (string)$emailUid)), 62 | 'paramsGet' => array(), 63 | 'enableCache' => true, 64 | )); 65 | 66 | return $response = $client->request(); 67 | } 68 | 69 | /** 70 | * Create a new transactional email 71 | * 72 | * @param array $data 73 | * 74 | * @return MailWizzApi_Http_Response 75 | * @throws Exception 76 | */ 77 | public function create(array $data) 78 | { 79 | if (!empty($data['body'])) { 80 | $data['body'] = base64_encode($data['body']); 81 | } 82 | 83 | if (!empty($data['plain_text'])) { 84 | $data['plain_text'] = base64_encode($data['plain_text']); 85 | } 86 | 87 | $client = new MailWizzApi_Http_Client(array( 88 | 'method' => MailWizzApi_Http_Client::METHOD_POST, 89 | 'url' => $this->getConfig()->getApiUrl('transactional-emails'), 90 | 'paramsPost' => array( 91 | 'email' => $data 92 | ), 93 | )); 94 | 95 | return $response = $client->request(); 96 | } 97 | 98 | /** 99 | * Delete existing transactional email 100 | * 101 | * @param string $emailUid 102 | * 103 | * @return MailWizzApi_Http_Response 104 | * @throws Exception 105 | */ 106 | public function delete($emailUid) 107 | { 108 | $client = new MailWizzApi_Http_Client(array( 109 | 'method' => MailWizzApi_Http_Client::METHOD_DELETE, 110 | 'url' => $this->getConfig()->getApiUrl(sprintf('transactional-emails/%s', $emailUid)), 111 | )); 112 | 113 | return $response = $client->request(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /MailWizzApi/Http/Client.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Http_Client is the http client interface used to make the remote requests and receive the responses. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Http 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Http_Client extends MailWizzApi_Base 20 | { 21 | /** 22 | * Marker for GET requests. 23 | */ 24 | const METHOD_GET = 'GET'; 25 | 26 | /** 27 | * Marker for POST requests. 28 | */ 29 | const METHOD_POST = 'POST'; 30 | 31 | /** 32 | * Marker for PUT requests. 33 | */ 34 | const METHOD_PUT = 'PUT'; 35 | 36 | /** 37 | * Marker for DELETE requests. 38 | */ 39 | const METHOD_DELETE = 'DELETE'; 40 | 41 | /** 42 | * Marker for the client version. 43 | */ 44 | const CLIENT_VERSION = '1.0'; 45 | 46 | /** 47 | * @var MailWizzApi_Params the GET params sent in the request. 48 | */ 49 | public $paramsGet; 50 | 51 | /** 52 | * @var MailWizzApi_Params the POST params sent in the request. 53 | */ 54 | public $paramsPost; 55 | 56 | /** 57 | * @var MailWizzApi_Params the PUT params sent in the request. 58 | */ 59 | public $paramsPut; 60 | 61 | /** 62 | * @var MailWizzApi_Params the DELETE params sent in the request. 63 | */ 64 | public $paramsDelete; 65 | 66 | /** 67 | * @var MailWizzApi_Params the headers sent in the request. 68 | */ 69 | public $headers; 70 | 71 | /** 72 | * @var string the url where the remote calls will be made. 73 | */ 74 | public $url; 75 | 76 | /** 77 | * @var int the default timeout for request. 78 | */ 79 | public $timeout = 30; 80 | 81 | /** 82 | * @var bool whether to sign the request. 83 | */ 84 | public $signRequest = true; 85 | 86 | /** 87 | * @var bool whether to get the response headers. 88 | */ 89 | public $getResponseHeaders = false; 90 | 91 | /** 92 | * @var bool whether to cache the request response. 93 | */ 94 | public $enableCache = false; 95 | 96 | /** 97 | * @var string the method used in the request. 98 | */ 99 | public $method = self::METHOD_GET; 100 | 101 | /** 102 | * Constructor. 103 | * 104 | * @param array $options 105 | * 106 | * @throws ReflectionException 107 | * @throws Exception 108 | */ 109 | public function __construct(array $options = array()) 110 | { 111 | $this->populateFromArray($options); 112 | 113 | foreach (array('paramsGet', 'paramsPost', 'paramsPut', 'paramsDelete', 'headers') as $param) { 114 | if (!($this->$param instanceof MailWizzApi_Params)) { 115 | $this->$param = new MailWizzApi_Params(!is_array($this->$param) ? array() : $this->$param); 116 | } 117 | } 118 | } 119 | 120 | /** 121 | * Whether the request method is a GET method. 122 | * 123 | * @return bool 124 | */ 125 | public function getIsGetMethod() 126 | { 127 | return strtoupper($this->method) === self::METHOD_GET; 128 | } 129 | 130 | /** 131 | * Whether the request method is a POST method. 132 | * 133 | * @return bool 134 | */ 135 | public function getIsPostMethod() 136 | { 137 | return strtoupper($this->method) === self::METHOD_POST; 138 | } 139 | 140 | /** 141 | * Whether the request method is a PUT method. 142 | * 143 | * @return bool 144 | */ 145 | public function getIsPutMethod() 146 | { 147 | return strtoupper($this->method) === self::METHOD_PUT; 148 | } 149 | 150 | /** 151 | * Whether the request method is a DELETE method. 152 | * 153 | * @return bool 154 | */ 155 | public function getIsDeleteMethod() 156 | { 157 | return strtoupper($this->method) === self::METHOD_DELETE; 158 | } 159 | 160 | /** 161 | * Makes the request to the remote host. 162 | * 163 | * @return MailWizzApi_Http_Response 164 | * @throws Exception 165 | */ 166 | public function request() 167 | { 168 | $request = new MailWizzApi_Http_Request($this); 169 | return $response = $request->send(); 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /MailWizzApi/Http/Request.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Http_Request is the request class used to send the requests to the API endpoints. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Http 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Http_Request extends MailWizzApi_Base 20 | { 21 | /** 22 | * @var MailWizzApi_Http_Client the http client injected. 23 | */ 24 | public $client; 25 | 26 | /** 27 | * @var MailWizzApi_Params the request params. 28 | */ 29 | public $params; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param MailWizzApi_Http_Client $client 35 | */ 36 | public function __construct(MailWizzApi_Http_Client $client) 37 | { 38 | $this->client = $client; 39 | } 40 | 41 | /** 42 | * Send the request to the remote url. 43 | * 44 | * @return MailWizzApi_Http_Response 45 | * @throws Exception 46 | */ 47 | public function send() 48 | { 49 | foreach ($this->getEventHandlers(self::EVENT_BEFORE_SEND_REQUEST) as $callback) { 50 | call_user_func_array($callback, array($this)); 51 | } 52 | 53 | $client = $this->client; 54 | $registry = $this->getRegistry(); 55 | $isCacheable = $registry->contains('cache') && $client->getIsGetMethod() && $client->enableCache; 56 | $requestUrl = rtrim($client->url, '/'); // no trailing slash 57 | $scheme = parse_url($requestUrl, PHP_URL_SCHEME); 58 | 59 | $getParams = (array)$client->paramsGet->toArray(); 60 | if (!empty($getParams)) { 61 | ksort($getParams, SORT_STRING); 62 | $queryString = http_build_query($getParams, '', '&'); 63 | if (!empty($queryString)) { 64 | $requestUrl .= '?'.$queryString; 65 | } 66 | } 67 | 68 | $this->sign($requestUrl); 69 | 70 | $etagCache = ''; 71 | $cacheKey = ''; 72 | 73 | /** @var MailWizzApi_Cache_Abstract $cacheComponent */ 74 | $cacheComponent = null; 75 | 76 | if ($isCacheable) { 77 | $client->getResponseHeaders = true; 78 | 79 | $bodyFromCache = null; 80 | $etagCache = ''; 81 | $params = $getParams; 82 | 83 | foreach (array('X-MW-PUBLIC-KEY', 'X-MW-TIMESTAMP', 'X-MW-REMOTE-ADDR') as $header) { 84 | $params[$header] = $client->headers->itemAt($header); 85 | } 86 | 87 | $cacheKey = $requestUrl; 88 | 89 | /** @var MailWizzApi_Cache_Abstract $cacheComponent */ 90 | $cacheComponent = $registry->itemAt('cache'); 91 | 92 | /** @var array $cache */ 93 | $cache = $cacheComponent->get($cacheKey); 94 | 95 | if (isset($cache['headers']) && is_array($cache['headers'])) { 96 | foreach ($cache['headers'] as $header) { 97 | if (preg_match('/etag:(\s+)?(.*)/ix', $header, $matches)) { 98 | $etagCache = trim($matches[2]); 99 | $client->headers->add('If-None-Match', $etagCache); 100 | $bodyFromCache = $cache['body']; 101 | break; 102 | } 103 | } 104 | } 105 | } 106 | 107 | if ($client->getIsPutMethod() || $client->getIsDeleteMethod()) { 108 | $client->headers->add('X-HTTP-Method-Override', strtoupper($client->method)); 109 | } 110 | 111 | $ch = curl_init($requestUrl); 112 | if ($ch === false) { 113 | throw new Exception('Cannot initialize curl!'); 114 | } 115 | 116 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 117 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $client->timeout); 118 | curl_setopt($ch, CURLOPT_TIMEOUT, $client->timeout); 119 | curl_setopt($ch, CURLOPT_USERAGENT, 'MailWizzApi Client version '. MailWizzApi_Http_Client::CLIENT_VERSION); 120 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); 121 | 122 | if ($client->getResponseHeaders) { 123 | // curl_setopt($ch, CURLOPT_VERBOSE, true); 124 | curl_setopt($ch, CURLOPT_HEADER, true); 125 | } 126 | 127 | if (!ini_get('safe_mode')) { 128 | curl_setopt($ch, CURLOPT_MAXREDIRS, 5); 129 | if (!ini_get('open_basedir')) { 130 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 131 | } 132 | } 133 | 134 | if ($client->headers->count > 0) { 135 | $headers = array(); 136 | foreach ($client->headers as $name => $value) { 137 | $headers[] = $name.': '.$value; 138 | } 139 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 140 | } 141 | 142 | //if ($scheme === 'https') { 143 | // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 144 | // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 145 | //} 146 | 147 | if ($client->getIsPostMethod() || $client->getIsPutMethod() || $client->getIsDeleteMethod()) { 148 | $params = new MailWizzApi_Params($client->paramsPost); 149 | $params->mergeWith($client->paramsPut); 150 | $params->mergeWith($client->paramsDelete); 151 | 152 | if (!$client->getIsPostMethod()) { 153 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($client->method)); 154 | } 155 | 156 | curl_setopt($ch, CURLOPT_POST, $params->count); 157 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params->toArray(), '', '&')); 158 | } 159 | 160 | $body = (string)curl_exec($ch); 161 | $curlCode = (int)curl_errno($ch); 162 | $curlMessage = (string)curl_error($ch); 163 | 164 | $curlInfo = curl_getinfo($ch); 165 | $params = $this->params = new MailWizzApi_Params($curlInfo); 166 | 167 | if ($curlCode === 0 && $client->getResponseHeaders) { 168 | $headersSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 169 | $headers = explode("\n", substr($body, 0, $headersSize)); 170 | foreach ($headers as $index => $header) { 171 | $header = trim($header); 172 | if (empty($header)) { 173 | unset($headers[$index]); 174 | } 175 | } 176 | $body = substr($body, $headersSize); 177 | $params->add('headers', new MailWizzApi_Params($headers)); 178 | } 179 | 180 | $decodedBody = array(); 181 | if ($curlCode === 0 && !empty($body)) { 182 | $decodedBody = json_decode($body, true); 183 | if (!is_array($decodedBody)) { 184 | $decodedBody = array(); 185 | } 186 | } 187 | 188 | // note here 189 | if ((int)$params->itemAt('http_code') === 304 && $isCacheable && !empty($bodyFromCache)) { 190 | $decodedBody = $bodyFromCache; 191 | } 192 | 193 | $params->add('curl_code', $curlCode); 194 | $params->add('curl_message', $curlMessage); 195 | $params->add('body', new MailWizzApi_Params($decodedBody)); 196 | 197 | $response = new MailWizzApi_Http_Response($this); 198 | $body = $response->body; 199 | 200 | if (!$response->getIsSuccess() && $body->itemAt('status') !== 'success' && !$body->contains('error')) { 201 | $response->body->add('status', 'error'); 202 | $response->body->add('error', $response->getMessage()); 203 | } 204 | 205 | curl_close($ch); 206 | 207 | if ($isCacheable && $response->getIsSuccess() && $body->itemAt('status') == 'success') { 208 | $etagNew = null; 209 | foreach ($response->headers as $header) { 210 | if (preg_match('/etag:(\s+)?(.*)/ix', $header, $matches)) { 211 | $etagNew = trim($matches[2]); 212 | break; 213 | } 214 | } 215 | if ($etagNew && $etagNew != $etagCache) { 216 | $cacheComponent->set($cacheKey, array( 217 | 'headers' => $response->headers->toArray(), 218 | 'body' => $response->body->toArray(), 219 | )); 220 | } 221 | } 222 | 223 | foreach ($this->getEventHandlers(self::EVENT_AFTER_SEND_REQUEST) as $callback) { 224 | $response = call_user_func_array($callback, array($this, $response)); 225 | } 226 | 227 | return $response; 228 | } 229 | 230 | /** 231 | * Sign the current request. 232 | * 233 | * @param string $requestUrl 234 | * @return void 235 | * 236 | * @throws Exception 237 | */ 238 | protected function sign($requestUrl) 239 | { 240 | $client = $this->client; 241 | $config = $this->getConfig(); 242 | 243 | $publicKey = $config->publicKey; 244 | $privateKey = $config->privateKey; 245 | $timestamp = time(); 246 | 247 | $specialHeaderParams = array( 248 | 'X-MW-PUBLIC-KEY' => $publicKey, 249 | 'X-MW-TIMESTAMP' => $timestamp, 250 | 'X-MW-REMOTE-ADDR' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 251 | ); 252 | 253 | foreach ($specialHeaderParams as $key => $value) { 254 | $client->headers->add($key, $value); 255 | } 256 | 257 | $params = new MailWizzApi_Params($specialHeaderParams); 258 | $params->mergeWith($client->paramsPost); 259 | $params->mergeWith($client->paramsPut); 260 | $params->mergeWith($client->paramsDelete); 261 | 262 | $params = $params->toArray(); 263 | ksort($params, SORT_STRING); 264 | 265 | $separator = $client->paramsGet->count > 0 && strpos($requestUrl, '?') !== false ? '&' : '?'; 266 | $signatureString = strtoupper($client->method) . ' ' . $requestUrl . $separator . http_build_query($params, '', '&'); 267 | $signature = hash_hmac('sha1', $signatureString, $privateKey, false); 268 | 269 | $client->headers->add('X-MW-SIGNATURE', $signature); 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /MailWizzApi/Http/Response.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | 11 | /** 12 | * MailWizzApi_Http_Response is the class used to get the responses back from the API endpoints. 13 | * 14 | * @author Serban George Cristian 15 | * @package MailWizzApi 16 | * @subpackage Http 17 | * @since 1.0 18 | */ 19 | class MailWizzApi_Http_Response extends MailWizzApi_Base 20 | { 21 | /** 22 | * @var string $url the url from where the response came back. 23 | */ 24 | public $url; 25 | 26 | /** 27 | * @var MailWizzApi_Params $headers the headers that came back in the response. 28 | */ 29 | public $headers; 30 | 31 | /** 32 | * @var string $contentType the content type of the response. 33 | */ 34 | public $contentType; 35 | 36 | /** 37 | * @var string $httpMessage the returned http message. 38 | */ 39 | public $httpMessage; 40 | 41 | /** 42 | * @var int $curlCode the curl response code. 43 | */ 44 | public $curlCode = 0; 45 | 46 | /** 47 | * @var string $curlMessage the curl response message. 48 | */ 49 | public $curlMessage; 50 | 51 | /** 52 | * @var bool $storeCurlInfo whether to store the curl info from the response. 53 | */ 54 | public $storeCurlInfo = false; 55 | 56 | /** 57 | * @var MailWizzApi_Params $curlInfo the curl info returned in the response. 58 | */ 59 | public $curlInfo; 60 | 61 | /** 62 | * @var MailWizzApi_Params $body the body of the response. 63 | */ 64 | public $body; 65 | 66 | /** 67 | * @var array the list of http status codes definitions. 68 | */ 69 | public static $statusTexts = array( 70 | 100 => 'Continue', 71 | 101 => 'Switching Protocols', 72 | 102 => 'Processing', // RFC2518 73 | 200 => 'OK', 74 | 201 => 'Created', 75 | 202 => 'Accepted', 76 | 203 => 'Non-Authoritative Information', 77 | 204 => 'No Content', 78 | 205 => 'Reset Content', 79 | 206 => 'Partial Content', 80 | 207 => 'Multi-Status', // RFC4918 81 | 208 => 'Already Reported', // RFC5842 82 | 226 => 'IM Used', // RFC3229 83 | 300 => 'Multiple Choices', 84 | 301 => 'Moved Permanently', 85 | 302 => 'Found', 86 | 303 => 'See Other', 87 | 304 => 'Not Modified', 88 | 305 => 'Use Proxy', 89 | 306 => 'Reserved', 90 | 307 => 'Temporary Redirect', 91 | 308 => 'Permanent Redirect', // RFC-reschke-http-status-308-07 92 | 400 => 'Bad Request', 93 | 401 => 'Unauthorized', 94 | 402 => 'Payment Required', 95 | 403 => 'Forbidden', 96 | 404 => 'Not Found', 97 | 405 => 'Method Not Allowed', 98 | 406 => 'Not Acceptable', 99 | 407 => 'Proxy Authentication Required', 100 | 408 => 'Request Timeout', 101 | 409 => 'Conflict', 102 | 410 => 'Gone', 103 | 411 => 'Length Required', 104 | 412 => 'Precondition Failed', 105 | 413 => 'Request Entity Too Large', 106 | 414 => 'Request-URI Too Long', 107 | 415 => 'Unsupported Media Type', 108 | 416 => 'Requested Range Not Satisfiable', 109 | 417 => 'Expectation Failed', 110 | 418 => 'I\'m a teapot', // RFC2324 111 | 422 => 'Unprocessable Entity', // RFC4918 112 | 423 => 'Locked', // RFC4918 113 | 424 => 'Failed Dependency', // RFC4918 114 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 115 | 426 => 'Upgrade Required', // RFC2817 116 | 428 => 'Precondition Required', // RFC6585 117 | 429 => 'Too Many Requests', // RFC6585 118 | 431 => 'Request Header Fields Too Large', // RFC6585 119 | 500 => 'Internal Server Error', 120 | 501 => 'Not Implemented', 121 | 502 => 'Bad Gateway', 122 | 503 => 'Service Unavailable', 123 | 504 => 'Gateway Timeout', 124 | 505 => 'HTTP Version Not Supported', 125 | 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 126 | 507 => 'Insufficient Storage', // RFC4918 127 | 508 => 'Loop Detected', // RFC5842 128 | 510 => 'Not Extended', // RFC2774 129 | 511 => 'Network Authentication Required', // RFC6585 130 | ); 131 | 132 | /** 133 | * @var MailWizzApi_Http_Request 134 | */ 135 | public $request; 136 | 137 | /** 138 | * @var int the returned http code. 139 | */ 140 | private $_httpCode; 141 | 142 | /** 143 | * Contructor. 144 | * 145 | * @param MailWizzApi_Http_Request $request 146 | * 147 | * @throws ReflectionException 148 | */ 149 | public function __construct(MailWizzApi_Http_Request $request) 150 | { 151 | // $this->request = $request; 152 | $this->populate($request->params->toArray()); 153 | } 154 | 155 | /** 156 | * Set the http code and http message based on the received response 157 | * 158 | * @param int $code 159 | * @return MailWizzApi_Http_Response 160 | */ 161 | public function setHttpCode($code) 162 | { 163 | $this->_httpCode = $code = (int)$code; 164 | $this->httpMessage = isset(self::$statusTexts[$code]) ? self::$statusTexts[$code] : null; 165 | return $this; 166 | } 167 | 168 | /** 169 | * Get the received http code. 170 | * 171 | * @return int 172 | */ 173 | public function getHttpCode() 174 | { 175 | return $this->_httpCode; 176 | } 177 | 178 | /** 179 | * Whether the response contains a curl error. 180 | * 181 | * @return bool 182 | */ 183 | public function getIsCurlError() 184 | { 185 | return (int)$this->curlCode > 0; 186 | } 187 | 188 | /** 189 | * Whether the response contains a http error. 190 | * 191 | * @return bool 192 | */ 193 | public function getIsHttpError() 194 | { 195 | return (int)$this->_httpCode < 200 || (int)$this->_httpCode >= 300; 196 | } 197 | 198 | /** 199 | * Whether the response is successful. 200 | * 201 | * @return bool 202 | */ 203 | public function getIsSuccess() 204 | { 205 | return $this->getIsCurlError() === false && $this->getIsHttpError() === false; 206 | } 207 | 208 | /** 209 | * Whether the response is not successful 210 | * 211 | * @return bool 212 | */ 213 | public function getIsError() 214 | { 215 | return $this->getIsSuccess() === false; 216 | } 217 | 218 | /** 219 | * If there is a http error or a curl error, retrieve the error message. 220 | * 221 | * @return mixed 222 | */ 223 | public function getMessage() 224 | { 225 | if ($this->getIsCurlError()) { 226 | return $this->curlMessage; 227 | } 228 | 229 | if ($this->getIsHttpError()) { 230 | return $this->httpMessage; 231 | } 232 | 233 | return null; 234 | } 235 | 236 | /** 237 | * If there is a http error or a curl error, retrieve the error code. 238 | * 239 | * @return mixed 240 | */ 241 | public function getCode() 242 | { 243 | if ($this->getIsCurlError()) { 244 | return $this->curlCode; 245 | } 246 | 247 | if ($this->getIsHttpError()) { 248 | return $this->_httpCode; 249 | } 250 | 251 | return false; 252 | } 253 | 254 | /** 255 | * Calls all the setters and populate the class based on the given array. 256 | * 257 | * @param array $params 258 | * 259 | * @return MailWizzApi_Http_Response 260 | * @throws ReflectionException 261 | */ 262 | public function populate(array $params = array()) 263 | { 264 | if ($this->storeCurlInfo) { 265 | $this->curlInfo = new MailWizzApi_Params($params); 266 | } 267 | 268 | $this->populateFromArray($params); 269 | return $this; 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /MailWizzApi/Params.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.yiiframework.com/ 7 | * @copyright 2008-2013 Yii Software LLC 8 | * @license http://www.yiiframework.com/license/ 9 | */ 10 | 11 | /** 12 | * CMap implements a collection that takes key-value pairs. 13 | * 14 | * You can access, add or remove an item with a key by using 15 | * {@link itemAt}, {@link add}, and {@link remove}. 16 | * To get the number of the items in the map, use {@link getCount}. 17 | * CMap can also be used like a regular array as follows, 18 | *
 19 |  * $map[$key]=$value; // add a key-value pair
 20 |  * unset($map[$key]); // remove the value with the specified key
 21 |  * if(isset($map[$key])) // if the map contains the key
 22 |  * foreach($map as $key=>$value) // traverse the items in the map
 23 |  * $n=count($map);  // returns the number of items in the map
 24 |  * 
25 | * 26 | * @property boolean $readOnly Whether this map is read-only or not. Defaults to false. 27 | * @property MailWizzApi_ParamsIterator $iterator An iterator for traversing the items in the list. 28 | * @property integer $count The number of items in the map. 29 | * @property array $keys The key list. 30 | * 31 | * @author Qiang Xue 32 | * @package system.collections 33 | * @since 1.0 34 | */ 35 | 36 | /** 37 | * MailWizzApi_Params implements a collection that takes key-value pairs. 38 | * 39 | * You can access, add or remove an item with a key by using 40 | * {@link itemAt}, {@link add}, and {@link remove}. 41 | * To get the number of the items in the map, use {@link getCount}. 42 | * MailWizzApi_Params can also be used like a regular array as follows, 43 | *
 44 |  * $map[$key]=$value; // add a key-value pair
 45 |  * unset($map[$key]); // remove the value with the specified key
 46 |  * if(isset($map[$key])) // if the map contains the key
 47 |  * foreach($map as $key=>$value) // traverse the items in the map
 48 |  * $n=count($map);  // returns the number of items in the map
 49 |  * 
50 | * 51 | * @property boolean $readOnly Whether this map is read-only or not. Defaults to false. 52 | * @property MailWizzApi_ParamsIterator $iterator An iterator for traversing the items in the list. 53 | * @property integer $count The number of items in the map. 54 | * @property array $keys The key list. 55 | * 56 | * @author Serban George Cristian 57 | * @link http://www.mailwizz.com 58 | * @copyright 2013-2020 https://www.mailwizz.com/ 59 | * @package MailWizzApi 60 | * @since 1.0 61 | * 62 | * Implementation based on CMapIterator class file from the Yii framework. 63 | * Please see /license/yiiframework.txt file for license info. 64 | */ 65 | class MailWizzApi_Params extends MailWizzApi_Base implements IteratorAggregate, ArrayAccess, Countable 66 | { 67 | /** 68 | * @var array internal data storage 69 | */ 70 | private $_data = array(); 71 | 72 | /** 73 | * @var boolean whether this list is read-only 74 | */ 75 | private $_readOnly = false; 76 | 77 | /** 78 | * Constructor. 79 | * Initializes the list with an array or an iterable object. 80 | * @param mixed $data the intial data. Default is null, meaning no initialization. 81 | * @param boolean $readOnly whether the list is read-only 82 | * @throws Exception If data is not null and neither an array nor an iterator. 83 | */ 84 | public function __construct($data = null, $readOnly = false) 85 | { 86 | if ($data !== null) { 87 | $this->copyFrom($data); 88 | } 89 | $this->setReadOnly($readOnly); 90 | } 91 | 92 | /** 93 | * @return boolean whether this map is read-only or not. Defaults to false. 94 | */ 95 | public function getReadOnly() 96 | { 97 | return $this->_readOnly; 98 | } 99 | 100 | /** 101 | * @param boolean $value whether this list is read-only or not 102 | * @return void 103 | */ 104 | protected function setReadOnly($value) 105 | { 106 | $this->_readOnly = $value; 107 | } 108 | 109 | /** 110 | * Returns an iterator for traversing the items in the list. 111 | * This method is required by the interface IteratorAggregate. 112 | * @return MailWizzApi_ParamsIterator an iterator for traversing the items in the list. 113 | */ 114 | public function getIterator() 115 | { 116 | return new MailWizzApi_ParamsIterator($this->_data); 117 | } 118 | 119 | /** 120 | * Returns the number of items in the map. 121 | * This method is required by Countable interface. 122 | * @return integer number of items in the map. 123 | */ 124 | public function count() 125 | { 126 | return $this->getCount(); 127 | } 128 | 129 | /** 130 | * Returns the number of items in the map. 131 | * @return integer the number of items in the map 132 | */ 133 | public function getCount() 134 | { 135 | return count($this->_data); 136 | } 137 | 138 | /** 139 | * @return array the key list 140 | */ 141 | public function getKeys() 142 | { 143 | return array_keys($this->_data); 144 | } 145 | 146 | /** 147 | * Returns the item with the specified key. 148 | * This method is exactly the same as {@link offsetGet}. 149 | * @param mixed $key the key 150 | * @return mixed the element at the offset, null if no element is found at the offset 151 | */ 152 | public function itemAt($key) 153 | { 154 | return isset($this->_data[$key]) ? $this->_data[$key] : null; 155 | } 156 | 157 | /** 158 | * Adds an item into the map. 159 | * Note, if the specified key already exists, the old value will be overwritten. 160 | * @param mixed $key key 161 | * @param mixed $value value 162 | * @throws Exception if the map is read-only 163 | * 164 | * @return void 165 | */ 166 | public function add($key, $value) 167 | { 168 | if (!$this->_readOnly) { 169 | if ($key === null) { 170 | $this->_data[] = $value; 171 | } else { 172 | $this->_data[$key] = $value; 173 | } 174 | } else { 175 | throw new Exception('The params map is read only.'); 176 | } 177 | } 178 | 179 | /** 180 | * Removes an item from the map by its key. 181 | * @param mixed $key the key of the item to be removed 182 | * @return mixed the removed value, null if no such key exists. 183 | * @throws Exception if the map is read-only 184 | * 185 | * @return mixed 186 | */ 187 | public function remove($key) 188 | { 189 | if (!$this->_readOnly) { 190 | if (isset($this->_data[$key])) { 191 | $value = $this->_data[$key]; 192 | unset($this->_data[$key]); 193 | return $value; 194 | } else { 195 | // it is possible the value is null, which is not detected by isset 196 | unset($this->_data[$key]); 197 | return null; 198 | } 199 | } else { 200 | throw new Exception('The params map is read only.'); 201 | } 202 | } 203 | 204 | /** 205 | * Removes all items in the map. 206 | * 207 | * @return void 208 | * @throws Exception 209 | */ 210 | public function clear() 211 | { 212 | foreach (array_keys($this->_data) as $key) { 213 | $this->remove($key); 214 | } 215 | } 216 | 217 | /** 218 | * @param mixed $key the key 219 | * @return boolean whether the map contains an item with the specified key 220 | */ 221 | public function contains($key) 222 | { 223 | return isset($this->_data[$key]) || array_key_exists($key, $this->_data); 224 | } 225 | 226 | /** 227 | * @return array the list of items in array 228 | */ 229 | public function toArray() 230 | { 231 | return $this->_data; 232 | } 233 | 234 | /** 235 | * Copies iterable data into the map. 236 | * Note, existing data in the map will be cleared first. 237 | * @param mixed $data the data to be copied from, must be an array or object implementing Traversable 238 | * @throws Exception If data is neither an array nor an iterator. 239 | * 240 | * @return void 241 | */ 242 | public function copyFrom($data) 243 | { 244 | if (is_array($data) || $data instanceof Traversable) { 245 | if ($this->getCount()>0) { 246 | $this->clear(); 247 | } 248 | if ($data instanceof MailWizzApi_Params) { 249 | $data = $data->_data; 250 | } 251 | foreach ($data as $key => $value) { 252 | $this->add($key, $value); 253 | } 254 | } elseif ($data !== null) { 255 | throw new Exception('Params map data must be an array or an object implementing Traversable.'); 256 | } 257 | } 258 | 259 | /** 260 | * Merges iterable data into the map. 261 | * 262 | * Existing elements in the map will be overwritten if their keys are the same as those in the source. 263 | * If the merge is recursive, the following algorithm is performed: 264 | *
    265 | *
  • the map data is saved as $a, and the source data is saved as $b;
  • 266 | *
  • if $a and $b both have an array indxed at the same string key, the arrays will be merged using this algorithm;
  • 267 | *
  • any integer-indexed elements in $b will be appended to $a and reindexed accordingly;
  • 268 | *
  • any string-indexed elements in $b will overwrite elements in $a with the same index;
  • 269 | *
270 | * 271 | * @param mixed $data the data to be merged with, must be an array or object implementing Traversable 272 | * @param boolean $recursive whether the merging should be recursive. 273 | * 274 | * @throws Exception If data is neither an array nor an iterator. 275 | * 276 | * @return void 277 | */ 278 | public function mergeWith($data, $recursive=true) 279 | { 280 | if (is_array($data) || $data instanceof Traversable) { 281 | if ($data instanceof MailWizzApi_Params) { 282 | $data = $data->_data; 283 | } 284 | if ($recursive) { 285 | if ($data instanceof Traversable) { 286 | $d=array(); 287 | foreach ($data as $key => $value) { 288 | $d[$key] = $value; 289 | } 290 | $this->_data = self::mergeArray($this->_data, $d); 291 | } else { 292 | $this->_data = self::mergeArray($this->_data, $data); 293 | } 294 | } else { 295 | foreach ($data as $key => $value) { 296 | $this->add($key, $value); 297 | } 298 | } 299 | } elseif ($data !== null) { 300 | throw new Exception('Params map data must be an array or an object implementing Traversable.'); 301 | } 302 | } 303 | 304 | /** 305 | * Merges two or more arrays into one recursively. 306 | * If each array has an element with the same string key value, the latter 307 | * will overwrite the former (different from array_merge_recursive). 308 | * Recursive merging will be conducted if both arrays have an element of array 309 | * type and are having the same key. 310 | * For integer-keyed elements, the elements from the latter array will 311 | * be appended to the former array. 312 | * @param array $a array to be merged to 313 | * @param array $b array to be merged from. You can specifiy additional 314 | * arrays via third argument, fourth argument etc. 315 | * @return array the merged array (the original arrays are not changed.) 316 | * @see mergeWith 317 | */ 318 | public static function mergeArray($a, $b) 319 | { 320 | $args = func_get_args(); 321 | $res = array_shift($args); 322 | while (!empty($args)) { 323 | $next = array_shift($args); 324 | foreach ($next as $k => $v) { 325 | if (is_integer($k)) { 326 | isset($res[$k]) ? $res[] = $v : $res[$k] = $v; 327 | } elseif (is_array($v) && isset($res[$k]) && is_array($res[$k])) { 328 | $res[$k] = self::mergeArray($res[$k], $v); 329 | } else { 330 | $res[$k]=$v; 331 | } 332 | } 333 | } 334 | return $res; 335 | } 336 | 337 | /** 338 | * Returns whether there is an element at the specified offset. 339 | * This method is required by the interface ArrayAccess. 340 | * @param mixed $offset the offset to check on 341 | * @return boolean 342 | */ 343 | public function offsetExists($offset) 344 | { 345 | return $this->contains($offset); 346 | } 347 | 348 | /** 349 | * Returns the element at the specified offset. 350 | * This method is required by the interface ArrayAccess. 351 | * @param integer $offset the offset to retrieve element. 352 | * @return mixed the element at the offset, null if no element is found at the offset 353 | */ 354 | public function offsetGet($offset) 355 | { 356 | return $this->itemAt($offset); 357 | } 358 | 359 | /** 360 | * Sets the element at the specified offset. 361 | * This method is required by the interface ArrayAccess. 362 | * 363 | * @param integer $offset the offset to set element 364 | * @param mixed $item the element value 365 | * 366 | * @return void 367 | * @throws Exception 368 | */ 369 | public function offsetSet($offset, $item) 370 | { 371 | $this->add($offset, $item); 372 | } 373 | 374 | /** 375 | * Unsets the element at the specified offset. 376 | * This method is required by the interface ArrayAccess. 377 | * 378 | * @param mixed $offset the offset to unset element 379 | * 380 | * @return void 381 | * @throws Exception 382 | */ 383 | public function offsetUnset($offset) 384 | { 385 | $this->remove($offset); 386 | } 387 | } 388 | -------------------------------------------------------------------------------- /MailWizzApi/ParamsIterator.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.yiiframework.com/ 7 | * @copyright 2008-2013 Yii Software LLC 8 | * @license http://www.yiiframework.com/license/ 9 | */ 10 | 11 | /** 12 | * CMapIterator implements an iterator for {@link CMap}. 13 | * 14 | * It allows CMap to return a new iterator for traversing the items in the map. 15 | * 16 | * @author Qiang Xue 17 | * @package system.collections 18 | * @since 1.0 19 | */ 20 | 21 | /** 22 | * MailWizzApi_ParamsIterator implements an interator for {@link MailWizzApi_Params}. 23 | * 24 | * It allows MailWizzApi_Params to return a new iterator for traversing the items in the map. 25 | * 26 | * @author Serban George Cristian 27 | * @link http://www.mailwizz.com 28 | * @copyright 2013-2020 https://www.mailwizz.com/ 29 | * @package MailWizzApi 30 | * @since 1.0 31 | * 32 | * Implementation based on CMapIterator class file from the Yii framework. 33 | * Please see /license/yiiframework.txt file for license info. 34 | */ 35 | class MailWizzApi_ParamsIterator implements Iterator 36 | { 37 | /** 38 | * @var array the data to be iterated through 39 | */ 40 | private $_data; 41 | 42 | /** 43 | * @var array list of keys in the map 44 | */ 45 | private $_keys; 46 | 47 | /** 48 | * @var mixed current key 49 | */ 50 | private $_key; 51 | 52 | /** 53 | * Constructor. 54 | * @param array $data the data to be iterated through 55 | */ 56 | public function __construct(&$data) 57 | { 58 | $this->_data =& $data; 59 | $this->_keys = array_keys($data); 60 | $this->_key = reset($this->_keys); 61 | } 62 | 63 | /** 64 | * Rewinds internal array pointer. 65 | * This method is required by the interface Iterator. 66 | * 67 | * @return void 68 | */ 69 | public function rewind() 70 | { 71 | $this->_key = reset($this->_keys); 72 | } 73 | 74 | /** 75 | * Returns the key of the current array element. 76 | * This method is required by the interface Iterator. 77 | * @return mixed the key of the current array element 78 | */ 79 | public function key() 80 | { 81 | return $this->_key; 82 | } 83 | 84 | /** 85 | * Returns the current array element. 86 | * This method is required by the interface Iterator. 87 | * @return mixed the current array element 88 | */ 89 | public function current() 90 | { 91 | return $this->_data[$this->_key]; 92 | } 93 | 94 | /** 95 | * Moves the internal pointer to the next array element. 96 | * This method is required by the interface Iterator. 97 | * 98 | * @return void 99 | */ 100 | public function next() 101 | { 102 | $this->_key = next($this->_keys); 103 | } 104 | 105 | /** 106 | * Returns whether there is an element at current position. 107 | * This method is required by the interface Iterator. 108 | * @return boolean 109 | */ 110 | public function valid() 111 | { 112 | return $this->_key !== false; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /MailWizzApi/Test/Base.php: -------------------------------------------------------------------------------- 1 | getenv('MAILWIZZ_API_URL'), 16 | 'publicKey' => getenv('MAILWIZZ_API_PUBLIC_KEY'), 17 | 'privateKey' => getenv('MAILWIZZ_API_PRIVATE_KEY'), 18 | ))); 19 | } catch (ReflectionException $e) { 20 | } 21 | 22 | // start UTC 23 | date_default_timezone_set('UTC'); 24 | 25 | parent::setUp(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /MailWizzApi/Test/Endpoint/ListsTest.php: -------------------------------------------------------------------------------- 1 | getLists(); 13 | $this->assertInstanceOf(MailWizzApi_Http_Response::class, $response); 14 | $this->assertIsArray($response->body->itemAt('data')); 15 | $this->assertArrayHasKey('records', $response->body->itemAt('data')); 16 | } 17 | 18 | final public function testCreateList() 19 | { 20 | /** @var MailWizzApi_Endpoint_Lists $endpoint */ 21 | $endpoint = new MailWizzApi_Endpoint_Lists(); 22 | 23 | /** @var MailWizzApi_Http_Response $response */ 24 | $response = $endpoint->create(array( 25 | // required 26 | 'general' => array( 27 | 'name' => 'My list created from the API for tests', 28 | 'description' => 'My list created from the API for tests', 29 | ), 30 | // required 31 | 'defaults' => array( 32 | 'from_name' => 'John Doe', 33 | 'from_email'=> 'johndoe@doe.com', 34 | 'reply_to' => 'johndoe@doe.com', 35 | 'subject' => 'Hello!', 36 | ), 37 | 'company' => array( 38 | 'name' => 'John Doe INC', 39 | 'country' => 'United States', 40 | 'zone' => 'New York', 41 | 'address_1' => 'Some street address', 42 | 'address_2' => '', 43 | 'zone_name' => '', 44 | 'city' => 'New York City', 45 | 'zip_code' => '10019', 46 | ), 47 | )); 48 | 49 | $this->assertInstanceOf(MailWizzApi_Http_Response::class, $response); 50 | $this->assertTrue($response->getIsSuccess()); 51 | $this->assertArrayHasKey('list_uid', $response->body->toArray()); 52 | 53 | self::$listUID = $response->body->itemAt('list_uid'); 54 | } 55 | 56 | final public function testGetList() 57 | { 58 | /** @var MailWizzApi_Endpoint_Lists $endpoint */ 59 | $endpoint = new MailWizzApi_Endpoint_Lists(); 60 | 61 | $response = $endpoint->getList(self::$listUID); 62 | $this->assertInstanceOf(MailWizzApi_Http_Response::class, $response); 63 | $this->assertTrue($response->getIsSuccess()); 64 | $this->assertIsArray($response->body->itemAt('data')); 65 | 66 | $general = isset($response->body->itemAt('data')['record']['general']) ? $response->body->itemAt('data')['record']['general'] : array(); 67 | $this->assertArrayHasKey('list_uid', $general); 68 | } 69 | 70 | public function testDeleteList() 71 | { 72 | /** @var MailWizzApi_Endpoint_Lists $endpoint */ 73 | $endpoint = new MailWizzApi_Endpoint_Lists(); 74 | 75 | $response = $endpoint->delete(self::$listUID); 76 | $this->assertInstanceOf(MailWizzApi_Http_Response::class, $response); 77 | $this->assertTrue($response->getIsSuccess()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /MailWizzApi/autoload.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the autoloader 11 | require_once dirname(__FILE__) . '/Autoloader.php'; 12 | 13 | // register the autoloader. 14 | MailWizzApi_Autoloader::register(); 15 | -------------------------------------------------------------------------------- /MailWizzApi/license/mailwizz-php-sdk.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Serban George Cristian 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /MailWizzApi/license/yiiframework.txt: -------------------------------------------------------------------------------- 1 | The Yii framework is free software. It is released under the terms of 2 | the following BSD License. 3 | 4 | Copyright (c) 2008-2013 by Yii Software LLC (http://www.yiisoft.com) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Yii Software LLC nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mailwizz PHP SDK 2 | ================ 3 | 4 | This repository contains the PHP SDK for MailWizz EMA. 5 | You'll find proper example on how to manage lists, subscribers, campaigns, templates and more. 6 | 7 | The documentation website at https://api-docs.mailwizz.com/ showcases all the API endpoints. 8 | You can find them in the examples folder as well. 9 | 10 | Implementations using MailWizz PHP SDK: 11 | - https://github.com/thangtx/mailwizzphpapi-wrap - A small rest app that acts as a proxy between mailwizz and any other software. 12 | 13 | Looking for Node.js implementations instead? 14 | - https://www.npmjs.com/package/node-mailwizz 15 | 16 | ### Install 17 | You can either download latest version of the code or you can install it via composer as follows: 18 | `composer require twisted1919/mailwizz-php-sdk` 19 | Then follow the instructions from `examples/setup.php` file. 20 | 21 | ## Test 22 | Following environment variables have to be set, with their proper values: 23 | `MAILWIZZ_API_URL` 24 | `MAILWIZZ_API_PUBLIC_KEY` 25 | `MAILWIZZ_API_PRIVATE_KEY` 26 | 27 | Then you can run the tests: 28 | ```bash 29 | $ composer test 30 | ``` 31 | 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "twisted1919/mailwizz-php-sdk", 3 | "type": "library", 4 | "description": "Mailwizz PHP-SDK", 5 | "keywords": ["mailwizz"], 6 | "homepage": "https://www.mailwizz.com", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "twisted1919", 11 | "email": "support@mailwizz.com" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.2" 16 | }, 17 | "autoload": { 18 | "files": ["MailWizzApi/autoload.php"] 19 | }, 20 | "require-dev": { 21 | "phpstan/phpstan": "^0.12.9", 22 | "phpunit/phpunit": "^7.5", 23 | "friendsofphp/php-cs-fixer": "^2.15" 24 | }, 25 | "scripts": { 26 | "test": "./vendor/bin/phpunit", 27 | "fix-style": "./vendor/bin/php-cs-fixer fix .", 28 | "analyse": "./vendor/bin/phpstan analyse . -c phpstan.neon --level max --memory-limit=-1" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/ajax_subscribe.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // see if the request is made via ajax. 14 | $isAjaxRequest = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; 15 | 16 | // and if it is and we have post values, then we can proceed in sending the subscriber. 17 | if ($isAjaxRequest && !empty($_POST)) { 18 | $listUid = 'LIST-UNIQUE-ID';// you'll take this from your customers area, in list overview from the address bar. 19 | $endpoint = new MailWizzApi_Endpoint_ListSubscribers(); 20 | $response = $endpoint->create($listUid, array( 21 | 'EMAIL' => isset($_POST['EMAIL']) ? $_POST['EMAIL'] : null, 22 | 'FNAME' => isset($_POST['FNAME']) ? $_POST['FNAME'] : null, 23 | 'LNAME' => isset($_POST['LNAME']) ? $_POST['LNAME'] : null, 24 | )); 25 | $response = $response->body; 26 | 27 | // if the returned status is success, we are done. 28 | if ($response->itemAt('status') == 'success') { 29 | exit(json_encode(array( 30 | 'status' => 'success', 31 | 'message' => 'Thank you for joining our email list. Please confirm your email address now!' 32 | ))); 33 | } 34 | 35 | // otherwise, the status is error 36 | exit(json_encode(array( 37 | 'status' => 'error', 38 | 'message' => $response->itemAt('error') 39 | ))); 40 | } 41 | ?> 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Ajax subscribe 55 | 83 | 130 | 131 | 132 | 133 | 134 |
135 | 136 |
137 | 141 |
142 |
143 | 144 |
145 | 146 | 147 |
148 | 149 |
150 | 151 | 152 |
153 | 154 |
155 | 156 | 157 |
158 | 159 |
160 |
161 | 162 |
163 |
164 | 165 |
166 |
167 | 168 |
169 | 170 | 171 | -------------------------------------------------------------------------------- /examples/campaign_bounces.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_CampaignBounces(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getBounces($campaignUid = 'CAMPAIGN-UNIQUE-ID', $pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // CREATE BOUNCE 29 | $response = $endpoint->create('CAMPAIGN-UNIQUE-ID', array( 30 | 'message' => 'The reason why this email bounced', // max 250 chars 31 | 'bounce_type' => 'hard', // hard, soft or internal 32 | 'subscriber_uid' => 'SUBSCRIBER-UNIQUE-ID' // 13 chars unique subscriber identifier 33 | )); 34 | 35 | // DISPLAY RESPONSE 36 | echo '
';
37 | print_r($response->body);
38 | echo '
'; 39 | -------------------------------------------------------------------------------- /examples/campaigns.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_Campaigns(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getCampaigns($pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
 23 | print_r($response->body);
 24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // GET ONE ITEM 29 | $response = $endpoint->getCampaign('CAMPAIGN-UNIQUE-ID'); 30 | 31 | // DISPLAY RESPONSE 32 | echo '
';
 33 | print_r($response->body);
 34 | echo '
'; 35 | 36 | /*===================================================================================*/ 37 | 38 | // CREATE CAMPAIGN 39 | $response = $endpoint->create(array( 40 | 'name' => 'My API Campaign', // required 41 | 'type' => 'regular', // optional: regular or autoresponder 42 | 'from_name' => 'John Doe', // required 43 | 'from_email' => 'john.doe@doe.com', // required 44 | 'subject' => 'Hey, i am testing the campaigns via API', // required 45 | 'reply_to' => 'john.doe@doe.com', // required 46 | 'send_at' => date('Y-m-d H:i:s', strtotime('+10 hours')), // required, this will use the timezone which customer selected 47 | 'list_uid' => 'LIST-UNIQUE-ID', // required 48 | 'segment_uid' => 'SEGMENT-UNIQUE-ID',// optional, only to narrow down 49 | 50 | // optional block, defaults are shown 51 | 'options' => array( 52 | 'url_tracking' => 'no', // yes | no 53 | 'json_feed' => 'no', // yes | no 54 | 'xml_feed' => 'no', // yes | no 55 | 'plain_text_email' => 'yes',// yes | no 56 | 'email_stats' => null, // a valid email address where we should send the stats after campaign done 57 | 58 | // - if autoresponder uncomment bellow: 59 | //'autoresponder_event' => 'AFTER-SUBSCRIBE', // AFTER-SUBSCRIBE or AFTER-CAMPAIGN-OPEN 60 | //'autoresponder_time_unit' => 'hour', // minute, hour, day, week, month, year 61 | //'autoresponder_time_value' => 1, // 1 hour after event 62 | //'autoresponder_open_campaign_id' => 1, // INT id of campaign, only if event is AFTER-CAMPAIGN-OPEN, 63 | 64 | // - if this campaign is advanced recurring, you can set a cron job style frequency. 65 | // - please note that this applies only for regular campaigns. 66 | //'cronjob' => '0 0 * * *', // once a day 67 | //'cronjob_enabled' => 1, // 1 or 0 68 | ), 69 | 70 | // required block, archive or template_uid or content => required. 71 | 'template' => array( 72 | //'archive' => file_get_contents(dirname(__FILE__) . '/template-example.zip'), 73 | //'template_uid' => 'TEMPLATE-UNIQUE-ID', 74 | 'content' => file_get_contents(dirname(__FILE__) . '/template-example.html'), 75 | 'inline_css' => 'no', // yes | no 76 | 'plain_text' => null, // leave empty to auto generate 77 | 'auto_plain_text' => 'yes', // yes | no 78 | ), 79 | )); 80 | 81 | // DISPLAY RESPONSE 82 | echo '
';
 83 | print_r($response->body);
 84 | echo '
'; 85 | 86 | /*===================================================================================*/ 87 | 88 | // UPDATE CAMPAIGN 89 | $response = $endpoint->update('CAMPAIGN-UNIQUE-ID', array( 90 | 'name' => 'My API Campaign UPDATED', // optional at update 91 | 'from_name' => 'John Doe', // optional at update 92 | 'from_email' => 'john.doe@doe.com', // optional at update 93 | 'subject' => 'Hey, i am testing the campaigns via API', // optional at update 94 | 'reply_to' => 'john.doe@doe.com', // optional at update 95 | 'send_at' => date('Y-m-d H:i:s', strtotime('+1 hour')), //optional at update, this will use the timezone which customer selected 96 | 'list_uid' => 'LIST-UNIQUE-ID', // optional at update 97 | 'segment_uid' => 'SEGMENT-UNIQUE-ID',// optional, only to narrow down 98 | 99 | // optional block, defaults are shown 100 | 'options' => array( 101 | 'url_tracking' => 'no', // yes | no 102 | 'json_feed' => 'no', // yes | no 103 | 'xml_feed' => 'no', // yes | no 104 | 'plain_text_email' => 'yes',// yes | no 105 | 'email_stats' => null, // a valid email address where we should send the stats after campaign done 106 | ), 107 | 108 | // optional block at update, archive or template_uid or content => required. 109 | 'template' => array( 110 | //'archive' => file_get_contents(dirname(__FILE__) . '/template-example.zip'), 111 | //'template_uid' => 'TEMPLATE-UNIQUE-ID', 112 | 'content' => file_get_contents(dirname(__FILE__) . '/template-example.html'), 113 | 'inline_css' => 'no', // yes | no 114 | 'plain_text' => null, // leave empty to auto generate 115 | 'auto_plain_text' => 'yes', // yes | no 116 | ), 117 | )); 118 | 119 | // DISPLAY RESPONSE 120 | echo '
';
121 | print_r($response->body);
122 | echo '
'; 123 | 124 | /*===================================================================================*/ 125 | 126 | // Copy CAMPAIGN 127 | $response = $endpoint->copy('CAMPAIGN-UNIQUE-ID'); 128 | 129 | // DISPLAY RESPONSE 130 | echo '
';
131 | print_r($response->body);
132 | echo '
'; 133 | 134 | /*===================================================================================*/ 135 | 136 | // Pause/Unpause CAMPAIGN 137 | $response = $endpoint->pauseUnpause('CAMPAIGN-UNIQUE-ID'); 138 | 139 | // DISPLAY RESPONSE 140 | echo '
';
141 | print_r($response->body);
142 | echo '
'; 143 | 144 | /*===================================================================================*/ 145 | 146 | // Mark CAMPAIGN as sent 147 | $response = $endpoint->markSent('CAMPAIGN-UNIQUE-ID'); 148 | 149 | // DISPLAY RESPONSE 150 | echo '
';
151 | print_r($response->body);
152 | echo '
'; 153 | 154 | /*===================================================================================*/ 155 | 156 | // Delete CAMPAIGN 157 | $response = $endpoint->delete('CAMPAIGN-UNIQUE-ID'); 158 | 159 | // DISPLAY RESPONSE 160 | echo '
';
161 | print_r($response->body);
162 | echo '
'; 163 | -------------------------------------------------------------------------------- /examples/campaigns_tracking.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // PLEASE NOTE THAT THIS ENDPOINT ONLY WORKS WITH MAILWIZZ >= 1.3.7.3 14 | // CREATE THE ENDPOINT 15 | $endpoint = new MailWizzApi_Endpoint_CampaignsTracking(); 16 | 17 | /*===================================================================================*/ 18 | 19 | // Track subscriber click for campaign click 20 | $response = $endpoint->trackUrl('CAMPAIGN-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID', 'URL-HASH'); 21 | 22 | // DISPLAY RESPONSE 23 | echo '
';
24 | print_r($response->body);
25 | echo '
'; 26 | 27 | /*===================================================================================*/ 28 | 29 | // Track subscriber open for campaign 30 | $response = $endpoint->trackOpening('CAMPAIGN-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID'); 31 | 32 | // DISPLAY RESPONSE 33 | echo '
';
34 | print_r($response->body);
35 | echo '
'; 36 | 37 | /*===================================================================================*/ 38 | 39 | // Track subscriber unsubscribe for campaign 40 | $response = $endpoint->trackUnsubscribe('CAMPAIGN-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID', array( 41 | 'ip_address' => '123.123.123.123', 42 | 'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 43 | 'reason' => 'Reason for unsubscribe!', 44 | )); 45 | 46 | // DISPLAY RESPONSE 47 | echo '
';
48 | print_r($response->body);
49 | echo '
'; 50 | -------------------------------------------------------------------------------- /examples/countries.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_Countries(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getCountries($pageNumber = 23, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // get country zones 29 | $response = $endpoint->getZones(223, $pageNumber = 1, $perPage = 10); 30 | 31 | // DISPLAY RESPONSE 32 | echo '
';
33 | print_r($response->body);
34 | echo '
'; 35 | -------------------------------------------------------------------------------- /examples/customers.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_Customers(); 15 | /*===================================================================================*/ 16 | 17 | // CREATE CUSTOMER 18 | $response = $endpoint->create(array( 19 | 'customer' => array( 20 | 'first_name' => 'John', 21 | 'last_name' => 'Doe', 22 | 'email' => 'john.doe@doe.com', 23 | 'password' => 'superDuperPassword', 24 | 'timezone' => 'UTC', 25 | ), 26 | // company is optional, unless required from app settings 27 | 'company' => array( 28 | 'name' => 'John Doe LLC', 29 | 'country' => 'United States', // see the countries endpoint for available countries and their zones 30 | 'zone' => 'New York', // see the countries endpoint for available countries and their zones 31 | 'city' => 'Brooklyn', 32 | 'zip_code' => 11222, 33 | 'address_1'=> 'Some Address', 34 | 'address_2'=> 'Some Other Address', 35 | ), 36 | )); 37 | 38 | // DISPLAY RESPONSE 39 | echo '
';
40 | print_r($response->body);
41 | echo '
'; 42 | -------------------------------------------------------------------------------- /examples/list_fields.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_ListFields(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getFields('LIST-UNIQUE-ID'); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | -------------------------------------------------------------------------------- /examples/list_segments.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_ListSegments(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getSegments('LIST-UNIQUE-ID'); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | -------------------------------------------------------------------------------- /examples/list_subscribers.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_ListSubscribers(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getSubscribers('LIST-UNIQUE-ID', $pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
 23 | print_r($response->body);
 24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // GET ONE ITEM 29 | $response = $endpoint->getSubscriber('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID'); 30 | 31 | // DISPLAY RESPONSE 32 | echo '
';
 33 | print_r($response->body);
 34 | echo '
'; 35 | 36 | /*===================================================================================*/ 37 | 38 | // SEARCH BY EMAIL 39 | $response = $endpoint->emailSearch('LIST-UNIQUE-ID', 'john.doe@doe.com'); 40 | 41 | // DISPLAY RESPONSE 42 | echo '
';
 43 | print_r($response->body);
 44 | echo '
'; 45 | 46 | /*===================================================================================*/ 47 | 48 | // SEARCH BY EMAIL IN ALL LISTS 49 | $response = $endpoint->emailSearchAllLists('john.doe@doe.com'); 50 | 51 | // DISPLAY RESPONSE 52 | echo '
';
 53 | print_r($response->body);
 54 | echo '
'; 55 | 56 | /*===================================================================================*/ 57 | 58 | // SEARCH BY CUSTOM FIELDS IN A LIST 59 | $response = $endpoint->searchByCustomFields('LIST-UNIQUE-ID', array( 60 | 'EMAIL' => 'john.doe@doe.com' 61 | )); 62 | 63 | // DISPLAY RESPONSE 64 | echo '
';
 65 | print_r($response->body);
 66 | echo '
'; 67 | 68 | /*===================================================================================*/ 69 | 70 | // ADD SUBSCRIBER 71 | $response = $endpoint->create('LIST-UNIQUE-ID', array( 72 | 'EMAIL' => 'john.doe@doe.com', // the confirmation email will be sent!!! Use valid email address 73 | 'FNAME' => 'John', 74 | 'LNAME' => 'Doe' 75 | )); 76 | 77 | // DISPLAY RESPONSE 78 | echo '
';
 79 | print_r($response->body);
 80 | echo '
'; 81 | 82 | /*===================================================================================*/ 83 | 84 | // ADD SUBSCRIBERS IN BULK (since MailWizz 1.8.1) 85 | $response = $endpoint->createBulk('LIST-UNIQUE-ID', array( 86 | array( 87 | 'EMAIL' => 'john.doe-1@doe.com', 88 | 'FNAME' => 'John', 89 | 'LNAME' => 'Doe' 90 | ), 91 | array( 92 | 'EMAIL' => 'john.doe-2@doe.com', 93 | 'FNAME' => 'John', 94 | 'LNAME' => 'Doe' 95 | ), 96 | array( 97 | 'EMAIL' => 'john.doe-3@doe.com', 98 | 'FNAME' => 'John', 99 | 'LNAME' => 'Doe' 100 | ) 101 | )); 102 | 103 | // DISPLAY RESPONSE 104 | echo '
';
105 | print_r($response->body);
106 | echo '
'; 107 | 108 | 109 | /*===================================================================================*/ 110 | 111 | // UPDATE EXISTING SUBSCRIBER 112 | $response = $endpoint->update('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID', array( 113 | 'EMAIL' => 'john.doe@doe.com', 114 | 'FNAME' => 'John', 115 | 'LNAME' => 'Doe Updated' 116 | )); 117 | 118 | // DISPLAY RESPONSE 119 | echo '
'; 120 | echo '
';
121 | print_r($response->body);
122 | echo '
'; 123 | 124 | /*===================================================================================*/ 125 | 126 | // UPDATE EXISTING SUBSCRIBER BY EMAIL 127 | $response = $endpoint->updateByEmail('LIST-UNIQUE-ID', 'john@doe.com', array( 128 | 'EMAIL' => 'john.doe@doe.com', 129 | 'FNAME' => 'John', 130 | 'LNAME' => 'Doe Updated' 131 | )); 132 | 133 | // DISPLAY RESPONSE 134 | echo '
'; 135 | echo '
';
136 | print_r($response->body);
137 | echo '
'; 138 | 139 | /*===================================================================================*/ 140 | 141 | // CREATE / UPDATE EXISTING SUBSCRIBER 142 | $response = $endpoint->createUpdate('LIST-UNIQUE-ID', array( 143 | 'EMAIL' => 'john.doe@doe.com', 144 | 'FNAME' => 'John', 145 | 'LNAME' => 'Doe Updated Second time' 146 | )); 147 | 148 | // DISPLAY RESPONSE 149 | echo '
';
150 | print_r($response->body);
151 | echo '
'; 152 | 153 | /*===================================================================================*/ 154 | 155 | // UNSUBSCRIBE existing subscriber, no email is sent, unsubscribe is silent 156 | $response = $endpoint->unsubscribe('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID'); 157 | 158 | // DISPLAY RESPONSE 159 | echo '
';
160 | print_r($response->body);
161 | echo '
'; 162 | 163 | /*===================================================================================*/ 164 | 165 | // UNSUBSCRIBE existing subscriber by email address, no email is sent, unsubscribe is silent 166 | $response = $endpoint->unsubscribeByEmail('LIST-UNIQUE-ID', 'john@doe.com'); 167 | 168 | // DISPLAY RESPONSE 169 | echo '
';
170 | print_r($response->body);
171 | echo '
'; 172 | /*===================================================================================*/ 173 | 174 | 175 | // UNSUBSCRIBE existing subscriber from all lists, no email is sent, unsubscribe is silent 176 | $response = $endpoint->unsubscribeByEmailFromAllLists('john@doe.com'); 177 | 178 | // DISPLAY RESPONSE 179 | echo '
';
180 | print_r($response->body);
181 | echo '
'; 182 | 183 | /*===================================================================================*/ 184 | 185 | // DELETE SUBSCRIBER, no email is sent, delete is silent 186 | $response = $endpoint->delete('LIST-UNIQUE-ID', 'SUBSCRIBER-UNIQUE-ID'); 187 | 188 | // DISPLAY RESPONSE 189 | echo '
';
190 | print_r($response->body);
191 | echo '
'; 192 | /*===================================================================================*/ 193 | 194 | // DELETE SUBSCRIBER by email address, no email is sent, delete is silent 195 | $response = $endpoint->deleteByEmail('LIST-UNIQUE-ID', 'john@doe.com'); 196 | 197 | // DISPLAY RESPONSE 198 | echo '
';
199 | print_r($response->body);
200 | echo '
'; 201 | -------------------------------------------------------------------------------- /examples/lists.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // create the lists endpoint: 14 | $endpoint = new MailWizzApi_Endpoint_Lists(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getLists($pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // get a single list 29 | $response = $endpoint->getList('LIST-UNIQUE-ID'); 30 | 31 | // DISPLAY RESPONSE 32 | echo '
';
33 | print_r($response->body);
34 | echo '
'; 35 | 36 | /*===================================================================================*/ 37 | 38 | // copy a list 39 | $response = $endpoint->copy('LIST-UNIQUE-ID'); 40 | 41 | // DISPLAY RESPONSE 42 | echo '
';
43 | print_r($response->body);
44 | echo '
'; 45 | 46 | /*===================================================================================*/ 47 | 48 | // delete a list 49 | $response = $endpoint->delete('LIST-UNIQUE-ID'); 50 | 51 | // DISPLAY RESPONSE 52 | echo '
';
53 | print_r($response->body);
54 | echo '
'; 55 | -------------------------------------------------------------------------------- /examples/lists_create.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // create the lists endpoint: 14 | $endpoint = new MailWizzApi_Endpoint_Lists(); 15 | 16 | // create a new list 17 | // please see countries.php example file for a list of allowed countries/zones for list company 18 | $response = $endpoint->create(array( 19 | // required 20 | 'general' => array( 21 | 'name' => 'My list created from the API', // required 22 | 'description' => 'This is a test list, created from the API.', // required 23 | ), 24 | // required 25 | 'defaults' => array( 26 | 'from_name' => 'John Doe', // required 27 | 'from_email'=> 'johndoe@doe.com', // required 28 | 'reply_to' => 'johndoe@doe.com', // required 29 | 'subject' => 'Hello!', 30 | ), 31 | // optional 32 | 'notifications' => array( 33 | // notification when new subscriber added 34 | 'subscribe' => 'yes', // yes|no 35 | // notification when subscriber unsubscribes 36 | 'unsubscribe' => 'yes', // yes|no 37 | // where to send the notifications. 38 | 'subscribe_to' => 'johndoe@doe.com', 39 | 'unsubscribe_to' => 'johndoe@doe.com', 40 | ), 41 | // optional, if not set customer company data will be used 42 | 'company' => array( 43 | 'name' => 'John Doe INC', // required 44 | 'country' => 'United States', // required 45 | 'zone' => 'New York', // required 46 | 'address_1' => 'Some street address', // required 47 | 'address_2' => '', 48 | 'zone_name' => '', // when country doesn't have required zone. 49 | 'city' => 'New York City', 50 | 'zip_code' => '10019', 51 | ), 52 | )); 53 | 54 | // and get the response 55 | echo '
';
56 | print_r($response->body);
57 | echo '
'; 58 | -------------------------------------------------------------------------------- /examples/lists_update.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // create the lists endpoint: 14 | $endpoint = new MailWizzApi_Endpoint_Lists(); 15 | 16 | // update list 17 | // please see countries.php example file for a list of allowed countries/zones for list company 18 | $response = $endpoint->update('LIST-UNIQUE-ID', array( 19 | // required 20 | 'general' => array( 21 | 'name' => 'My list created from the API - now updated!', // required 22 | 'description' => 'This is a test list, created from the API.', // required 23 | ), 24 | // required 25 | 'defaults' => array( 26 | 'from_name' => 'John Doe', // required 27 | 'from_email'=> 'johndoe@doe.com', // required 28 | 'reply_to' => 'johndoe@doe.com', // required 29 | 'subject' => 'Hello!', 30 | ), 31 | // optional 32 | 'notifications' => array( 33 | // notification when new subscriber added 34 | 'subscribe' => 'yes', // yes|no 35 | // notification when subscriber unsubscribes 36 | 'unsubscribe' => 'yes', // yes|no 37 | // where to send the notifications. 38 | 'subscribe_to' => 'johndoe@doe.com', 39 | 'unsubscribe_to' => 'johndoe@doe.com', 40 | ), 41 | // optional, if not set customer company data will be used 42 | 'company' => array( 43 | 'name' => 'John Doe INC', // required 44 | 'country' => 'United States', // required 45 | 'zone' => 'New York', // required 46 | 'address_1' => 'Some street address', // required 47 | 'address_2' => '', 48 | 'zone_name' => '', 49 | 'city' => 'New York City', 50 | 'zip_code' => '10019', 51 | ), 52 | )); 53 | 54 | // and get the response 55 | echo '
';
56 | print_r($response->body);
57 | echo '
'; 58 | -------------------------------------------------------------------------------- /examples/setup.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | exit('COMMENT ME TO TEST THE EXAMPLES!'); 11 | 12 | // require the autoloader class if you haven't used composer to install the package 13 | require_once dirname(__FILE__) . '/../MailWizzApi/Autoloader.php'; 14 | 15 | // register the autoloader if you haven't used composer to install the package 16 | MailWizzApi_Autoloader::register(); 17 | 18 | // if using a framework that already uses an autoloading mechanism, like Yii for example, 19 | // you can register the autoloader like: 20 | // Yii::registerAutoloader(array('MailWizzApi_Autoloader', 'autoloader'), true); 21 | 22 | /** 23 | * Notes: 24 | * If SSL present on the webhost, the api can be accessed via SSL as well (https://...). 25 | * A self signed SSL certificate will work just fine. 26 | * If the MailWizz powered website doesn't use clean urls, 27 | * make sure your apiUrl has the index.php part of url included, i.e: 28 | * http://www.mailwizz-powered-website.tld/api/index.php 29 | * 30 | * Configuration components: 31 | * The api for the MailWizz EMA is designed to return proper etags when GET requests are made. 32 | * We can use this to cache the request response in order to decrease loading time therefore improving performance. 33 | * In this case, we will need to use a cache component that will store the responses and a file cache will do it just fine. 34 | * Please see MailWizzApi/Cache for a list of available cache components and their usage. 35 | */ 36 | 37 | // configuration object 38 | $config = new MailWizzApi_Config(array( 39 | 'apiUrl' => 'http://www.mailwizz-powered-website.tld/api', 40 | 'publicKey' => 'PUBLIC-KEY', 41 | 'privateKey' => 'PRIVATE-KEY', 42 | 43 | // components 44 | 'components' => array( 45 | 'cache' => array( 46 | 'class' => 'MailWizzApi_Cache_File', 47 | 'filesPath' => dirname(__FILE__) . '/../MailWizzApi/Cache/data/cache', // make sure it is writable by webserver 48 | ) 49 | ), 50 | )); 51 | 52 | // now inject the configuration and we are ready to make api calls 53 | MailWizzApi_Base::setConfig($config); 54 | 55 | // start UTC 56 | date_default_timezone_set('UTC'); 57 | -------------------------------------------------------------------------------- /examples/template-example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MailWizz 5 | 6 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 30 | 31 | 32 | 49 | 50 | 51 | 55 | 56 | 57 | 60 | 61 | 62 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
MailWizz Email marketing application
29 |
33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | 47 |
 
40 |

Hello world!

41 |
 
48 |
52 | Unsubscribe | 53 | Web version 54 |
58 | [COMPANY_FULL_ADDRESS] 59 |
63 |
64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/template-example.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twisted1919/mailwizz-php-sdk/37444bbfd4cef0ccb496a38f83077505a8b24660/examples/template-example.zip -------------------------------------------------------------------------------- /examples/templates.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_Templates(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getTemplates($pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // Search ALL ITEMS (available from MailWizz 1.4.4) 29 | $response = $endpoint->searchTemplates($pageNumber = 1, $perPage = 10, array( 30 | 'name' => 'my template name' 31 | )); 32 | 33 | // DISPLAY RESPONSE 34 | echo '
';
35 | print_r($response->body);
36 | echo '
'; 37 | 38 | /*===================================================================================*/ 39 | 40 | // GET ONE ITEM 41 | $response = $endpoint->getTemplate('TEMPLATE-UNIQUE-ID'); 42 | 43 | // DISPLAY RESPONSE 44 | echo '
';
45 | print_r($response->body);
46 | echo '
'; 47 | 48 | /*===================================================================================*/ 49 | 50 | // delete template 51 | $response = $endpoint->delete('TEMPLATE-UNIQUE-ID'); 52 | 53 | // DISPLAY RESPONSE 54 | echo '
';
55 | print_r($response->body);
56 | echo '
'; 57 | 58 | /*===================================================================================*/ 59 | 60 | // CREATE A NEW TEMPLATE 61 | $rand = rand(); 62 | $response = $endpoint->create(array( 63 | 'name' => 'My API template ' . $rand, 64 | 'content' => file_get_contents(dirname(__FILE__) . '/template-example.html'), 65 | //'archive' => file_get_contents(dirname(__FILE__) . '/template-example.zip'), 66 | 'inline_css' => 'no',// yes|no 67 | )); 68 | 69 | // DISPLAY RESPONSE 70 | echo '
';
71 | print_r($response->body);
72 | echo '
'; 73 | 74 | /*===================================================================================*/ 75 | 76 | // UPDATE A TEMPLATE 77 | $response = $endpoint->update('TEMPLATE-UNIQUE-ID', array( 78 | 'name' => 'My API template - updated' . $rand, 79 | 'content' => file_get_contents(dirname(__FILE__) . '/template-example.html'), 80 | //'archive' => file_get_contents(dirname(__FILE__) . '/template-example.zip'), 81 | 'inline_css' => 'no',// yes|no 82 | )); 83 | 84 | // DISPLAY RESPONSE 85 | echo '
';
86 | print_r($response->body);
87 | echo '
'; 88 | -------------------------------------------------------------------------------- /examples/transactional_emails.php: -------------------------------------------------------------------------------- 1 | 6 | * @link https://www.mailwizz.com/ 7 | * @copyright 2013-2020 https://www.mailwizz.com/ 8 | */ 9 | 10 | // require the setup which has registered the autoloader 11 | require_once dirname(__FILE__) . '/setup.php'; 12 | 13 | // CREATE THE ENDPOINT 14 | $endpoint = new MailWizzApi_Endpoint_TransactionalEmails(); 15 | 16 | /*===================================================================================*/ 17 | 18 | // GET ALL ITEMS 19 | $response = $endpoint->getEmails($pageNumber = 1, $perPage = 10); 20 | 21 | // DISPLAY RESPONSE 22 | echo '
';
23 | print_r($response->body);
24 | echo '
'; 25 | 26 | /*===================================================================================*/ 27 | 28 | // GET ONE ITEM 29 | $response = $endpoint->getEmail('EMAIL-UNIQUE-ID'); 30 | 31 | // DISPLAY RESPONSE 32 | echo '
';
33 | print_r($response->body);
34 | echo '
'; 35 | 36 | /*===================================================================================*/ 37 | 38 | // delete email 39 | $response = $endpoint->delete('EMAIL-UNIQUE-ID'); 40 | 41 | // DISPLAY RESPONSE 42 | echo '
';
43 | print_r($response->body);
44 | echo '
'; 45 | 46 | /*===================================================================================*/ 47 | 48 | // CREATE A NEW EMAIL 49 | $response = $endpoint->create(array( 50 | 'to_name' => 'John Doe', // required 51 | 'to_email' => 'john@doe.com', // required 52 | 'from_name' => 'Jane Doe', // required 53 | 'from_email' => 'jane@doe.com', // optional 54 | 'reply_to_name' => 'Jane Doe', // optional 55 | 'reply_to_email' => 'jane@doe.com', // optional 56 | 'subject' => 'This is the email subject', // required 57 | 'body' => 'Hello world!', // required 58 | 'plain_text' => 'Hello world!', // optional, will be autogenerated if missing 59 | 'send_at' => date('Y-m-d H:i:s'), // required, UTC date time in same format! 60 | )); 61 | 62 | // DISPLAY RESPONSE 63 | echo '
';
64 | print_r($response->body);
65 | echo '
'; 66 | 67 | /*===================================================================================*/ 68 | -------------------------------------------------------------------------------- /php_cs.dist: -------------------------------------------------------------------------------- 1 | exclude('vendor') 5 | ->in('.') 6 | ; 7 | 8 | return PhpCsFixer\Config::create() 9 | ->setRiskyAllowed(true) 10 | ->setRules([ 11 | '@PSR2' => true, 12 | 'array_syntax' => ['syntax' => 'short'], 13 | 'declare_strict_types' => true, 14 | 'no_short_echo_tag' => true, 15 | 'ternary_to_null_coalescing' => true, 16 | 'not_operator_with_successor_space' => false, 17 | 'return_type_declaration' => true, 18 | 'semicolon_after_instruction' => true, 19 | 'short_scalar_cast' => true, 20 | 'single_line_comment_style' => true, 21 | 'single_quote' => true, 22 | 'single_trait_insert_per_statement' => true, 23 | 'space_after_semicolon' => true, 24 | 'standardize_not_equals' => true, 25 | 'standardize_increment' => true, 26 | 'ternary_operator_spaces' => true, 27 | 'trailing_comma_in_multiline_array' => true, 28 | 'trim_array_spaces' => true, 29 | 'unary_operator_spaces' => true, 30 | 'whitespace_after_comma_in_array' => true, 31 | 'combine_consecutive_issets' => true, 32 | 'combine_consecutive_unsets' => true, 33 | 'compact_nullable_typehint' => true, 34 | 'concat_space' => ['spacing' => 'one'], 35 | 'fully_qualified_strict_types' => true, 36 | 'function_typehint_space' => true, 37 | 'include' => true, 38 | 'lowercase_cast' => true, 39 | 'lowercase_constants' => true, 40 | 'lowercase_keywords' => true, 41 | 'lowercase_static_reference' => true, 42 | 'magic_method_casing' => true, 43 | 'method_chaining_indentation' => true, 44 | 'native_function_casing' => true, 45 | 'native_function_type_declaration_casing' => true, 46 | 'new_with_braces' => true, 47 | 'no_empty_statement' => true, 48 | 'no_leading_import_slash' => true, 49 | 'no_mixed_echo_print' => ['use' => 'echo'], 50 | 'no_multiline_whitespace_around_double_arrow' => true, 51 | 'no_null_property_initialization' => true, 52 | 'no_singleline_whitespace_before_semicolons' => true, 53 | 'no_spaces_after_function_name' => true, 54 | 'no_spaces_around_offset' => true, 55 | 'no_spaces_inside_parenthesis' => true, 56 | 'no_superfluous_elseif' => true, 57 | 'no_trailing_comma_in_list_call' => true, 58 | 'no_trailing_comma_in_singleline_array' => true, 59 | 'no_trailing_whitespace' => true, 60 | 'no_unneeded_control_parentheses' => true, 61 | 'no_unneeded_curly_braces' => true, 62 | 'no_unneeded_final_method' => true, 63 | 'no_unset_cast' => true, 64 | 'no_unused_imports' => true, 65 | 'no_useless_else' => true, 66 | 'no_useless_return' => true, 67 | 'no_whitespace_before_comma_in_array' => true, 68 | 'no_whitespace_in_blank_line' => true, 69 | 'normalize_index_brace' => true, 70 | 'object_operator_without_whitespace' => true, 71 | 'ordered_class_elements' => true, 72 | 'ordered_imports' => true, 73 | ]) 74 | ->setFinder($finder) 75 | ; -------------------------------------------------------------------------------- /phpstan.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | checkMissingIterableValueType: false 3 | checkGenericClassInNonGenericObjectType: false 4 | excludes_analyse: 5 | - examples/* 6 | - vendor/* 7 | - MailWizzApi/Test/* -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ./MailWizzApi/Test 21 | 22 | 23 | --------------------------------------------------------------------------------