├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── composer.lock
├── config
└── sendy.php
├── phpunit.xml
├── src
├── Facades
│ └── Sendy.php
├── Sendy.php
└── SendyServiceProvider.php
└── tests
└── SendyTest.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .DS_Store
3 | vendor/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Jozsef Hocza
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # Sendy Laravel
3 | A service provider for Sendy API in Laravel 5
4 |
5 |
[](https://packagist.org/packages/hocza/sendy) [](https://packagist.org/packages/hocza/sendy) [](https://packagist.org/packages/hocza/sendy) [](https://packagist.org/packages/hocza/sendy)
6 |
7 | ## Installation
8 | ```shell
9 | composer require hocza/sendy:1.*
10 | ```
11 |
12 | or append your composer.json with:
13 |
14 | ```json
15 | {
16 | "require" : {
17 | "hocza/sendy": "1.*"
18 | }
19 | }
20 | ```
21 | Add the following settings to the config/app.php
22 |
23 | Service provider:
24 |
25 | ```php
26 | 'providers' => [
27 | // ...
28 | 'Hocza\Sendy\SendyServiceProvider',
29 | ]
30 | ```
31 |
32 | For the `Sendy::` facade
33 |
34 | ```php
35 | 'aliases' => [
36 | // ...
37 | 'Sendy' => 'Hocza\Sendy\Facades\Sendy',
38 | ]
39 | ```
40 |
41 | ## Configuration
42 | ```shell
43 | php artisan vendor:publish --provider="Hocza\Sendy\SendyServiceProvider"
44 | ```
45 |
46 | It will create sendy.php within the config directory.
47 |
48 | ```php
49 | '',
54 | 'installationUrl' => '',
55 | 'apiKey' => '',
56 |
57 | ];
58 | ```
59 |
60 | ## Usage
61 | ### Subscribe:
62 |
63 | ```php
64 | $data = [
65 | 'email' => 'johndoe@example.com',
66 | 'name' => 'John Doe',
67 | 'any_custom_column' => 'value',
68 | ];
69 |
70 | Sendy::subscribe($data);
71 | ```
72 |
73 | **RESPONSE** *(array)*
74 |
75 | In case of success:
76 |
77 | ```php
78 | ['status' => true, 'message' => 'Subscribed']
79 | ['status' => true, 'message' => 'Already subscribed']
80 | ```
81 | In case of error:
82 |
83 | ```php
84 | ['status' => false, 'message' => 'The error message']
85 | ```
86 |
87 | ### Unsubscribe:
88 |
89 | ```php
90 | $email = 'johndoe@example.com';
91 | Sendy::unsubscribe($email);
92 | ```
93 |
94 | **RESPONSE** *(array)*
95 |
96 | In case of success:
97 |
98 | ```php
99 | ['status' => true, 'message' => 'Unsubscribed']
100 | ```
101 | In case of error:
102 |
103 | ```php
104 | ['status' => false, 'message' => 'The error message']
105 | ```
106 |
107 | ### Subscription status
108 |
109 | ```php
110 | $email = 'johndoe@example.com';
111 | Sendy::status($email);
112 | ```
113 |
114 | **RESPONSE** *(Plain text)*
115 |
116 | Success:
117 |
118 | - `Subscribed`
119 | - `Unsubscribed`
120 | - `Unconfirmed`
121 | - `Bounced`
122 | - `Soft bounced`
123 | - `Complained`
124 |
125 | Error:
126 |
127 | - `No data passed`
128 | - `API key not passed`
129 | - `Invalid API key`
130 | - `Email not passed`
131 | - `List ID not passed`
132 | - `Email does not exist in list`
133 |
134 | ### Active subscriber count
135 |
136 | ```php
137 | Sendy::count();
138 | #To check other list:
139 | Sendy::setListId($list_id)->count();
140 | ```
141 |
142 | **RESPONSE** *(Plain text)*
143 |
144 | Success:
145 |
146 | - `You'll get an integer of the active subscriber count`
147 |
148 | Error:
149 |
150 | - `No data passed`
151 | - `API key not passed`
152 | - `Invalid API key`
153 | - `List ID not passed`
154 | - `List does not exist`
155 |
156 |
157 | ### Create campaign
158 |
159 | ```php
160 | 'My Name',
164 | 'from_email' => 'test@mail.com',
165 | 'reply_to' => 'test@mail.com',
166 | 'title' => 'My Campaign',
167 | 'subject' => 'My Subject',
168 | 'list_ids' => '1,2,3', // comma-separated, optional
169 | 'brand_id' => 1,
170 | 'query_string' => 'utm_source=sendy&utm_medium=email&utm_content=email%20newsletter&utm_campaign=email%20newsletter',
171 | ];
172 | $campaignContent = [
173 | 'plain_text' => 'My Campaign',
174 | 'html_text' => View::make('mail.my-campaign'),
175 | ];
176 | $send = false;
177 |
178 | Sendy::createCampaign($campaignOptions, $campaignContent, $send);
179 | ```
180 |
181 | **RESPONSE** *(Plain text)*
182 |
183 | Success:
184 |
185 | - `Campaign created`
186 | - `Campaign created and now sending`
187 |
188 | Error:
189 |
190 | - `No data passed`
191 | - `API key not passed`
192 | - `Invalid API key`
193 | - `From name not passed`
194 | - `From email not passed`
195 | - `Reply to email not passed`
196 | - `Subject not passed`
197 | - `HTML not passed`
198 | - `List ID(s) not passed`
199 | - `One or more list IDs are invalid`
200 | - `List IDs does not belong to a single brand`
201 | - `Brand ID not passed`
202 | - `Unable to create campaign`
203 | - `Unable to create and send campaign`
204 |
205 | ### Change list ID
206 |
207 | To change the default list ID simply prepend with setListId($list_id)
208 | **Examples:**
209 |
210 | ```php
211 | Sendy::setListId($list_id)->subscribe($data);
212 | Sendy::setListId($list_id)->unsubscribe($email);
213 | Sendy::setListId($list_id)->status($email);
214 | Sendy::setListId($list_id)->count();
215 | ```
216 |
217 | ## Todo
218 |
219 | * Implementing the rest of the API. :)
220 | * better documentation - in progress as you can see :)
221 |
222 | ## Buy me a coffee :)
223 |
224 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "hocza/sendy",
3 | "description": "Sendy API implementation for Laravel",
4 | "keywords": ["laravel", "sendy", "email", "newsletter", "API"],
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "Jozsef Hocza",
9 | "email": "jozsef@hocza.com"
10 | }
11 | ],
12 | "require": {
13 | "php": ">=5.3.0"
14 | },
15 | "require-dev": {
16 | "phpunit/phpunit": "^4.8"
17 | },
18 | "autoload": {
19 | "psr-4": {
20 | "Hocza\\Sendy\\": "src/",
21 | "Hocza\\Tests\\Sendy\\": "tests/"
22 | }
23 | },
24 | "extra": {
25 | "laravel": {
26 | "providers": [
27 | "Hocza\\Sendy\\SendyServiceProvider"
28 | ],
29 | "aliases": {
30 | "Sendy": "Hocza\\Sendy\\Facades\\Sendy"
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5 | "This file is @generated automatically"
6 | ],
7 | "hash": "182ab0cc44191f6af5d4990a0f895a0d",
8 | "content-hash": "01e05fa818b57060cd7124310ac7a8a4",
9 | "packages": [],
10 | "packages-dev": [
11 | {
12 | "name": "doctrine/instantiator",
13 | "version": "1.0.5",
14 | "source": {
15 | "type": "git",
16 | "url": "https://github.com/doctrine/instantiator.git",
17 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
18 | },
19 | "dist": {
20 | "type": "zip",
21 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
22 | "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
23 | "shasum": ""
24 | },
25 | "require": {
26 | "php": ">=5.3,<8.0-DEV"
27 | },
28 | "require-dev": {
29 | "athletic/athletic": "~0.1.8",
30 | "ext-pdo": "*",
31 | "ext-phar": "*",
32 | "phpunit/phpunit": "~4.0",
33 | "squizlabs/php_codesniffer": "~2.0"
34 | },
35 | "type": "library",
36 | "extra": {
37 | "branch-alias": {
38 | "dev-master": "1.0.x-dev"
39 | }
40 | },
41 | "autoload": {
42 | "psr-4": {
43 | "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
44 | }
45 | },
46 | "notification-url": "https://packagist.org/downloads/",
47 | "license": [
48 | "MIT"
49 | ],
50 | "authors": [
51 | {
52 | "name": "Marco Pivetta",
53 | "email": "ocramius@gmail.com",
54 | "homepage": "http://ocramius.github.com/"
55 | }
56 | ],
57 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
58 | "homepage": "https://github.com/doctrine/instantiator",
59 | "keywords": [
60 | "constructor",
61 | "instantiate"
62 | ],
63 | "time": "2015-06-14 21:17:01"
64 | },
65 | {
66 | "name": "hamcrest/hamcrest-php",
67 | "version": "v1.2.2",
68 | "source": {
69 | "type": "git",
70 | "url": "https://github.com/hamcrest/hamcrest-php.git",
71 | "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c"
72 | },
73 | "dist": {
74 | "type": "zip",
75 | "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c",
76 | "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c",
77 | "shasum": ""
78 | },
79 | "require": {
80 | "php": ">=5.3.2"
81 | },
82 | "replace": {
83 | "cordoval/hamcrest-php": "*",
84 | "davedevelopment/hamcrest-php": "*",
85 | "kodova/hamcrest-php": "*"
86 | },
87 | "require-dev": {
88 | "phpunit/php-file-iterator": "1.3.3",
89 | "satooshi/php-coveralls": "dev-master"
90 | },
91 | "type": "library",
92 | "autoload": {
93 | "classmap": [
94 | "hamcrest"
95 | ],
96 | "files": [
97 | "hamcrest/Hamcrest.php"
98 | ]
99 | },
100 | "notification-url": "https://packagist.org/downloads/",
101 | "license": [
102 | "BSD"
103 | ],
104 | "description": "This is the PHP port of Hamcrest Matchers",
105 | "keywords": [
106 | "test"
107 | ],
108 | "time": "2015-05-11 14:41:42"
109 | },
110 | {
111 | "name": "mockery/mockery",
112 | "version": "0.9.4",
113 | "source": {
114 | "type": "git",
115 | "url": "https://github.com/padraic/mockery.git",
116 | "reference": "70bba85e4aabc9449626651f48b9018ede04f86b"
117 | },
118 | "dist": {
119 | "type": "zip",
120 | "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b",
121 | "reference": "70bba85e4aabc9449626651f48b9018ede04f86b",
122 | "shasum": ""
123 | },
124 | "require": {
125 | "hamcrest/hamcrest-php": "~1.1",
126 | "lib-pcre": ">=7.0",
127 | "php": ">=5.3.2"
128 | },
129 | "require-dev": {
130 | "phpunit/phpunit": "~4.0"
131 | },
132 | "type": "library",
133 | "extra": {
134 | "branch-alias": {
135 | "dev-master": "0.9.x-dev"
136 | }
137 | },
138 | "autoload": {
139 | "psr-0": {
140 | "Mockery": "library/"
141 | }
142 | },
143 | "notification-url": "https://packagist.org/downloads/",
144 | "license": [
145 | "BSD-3-Clause"
146 | ],
147 | "authors": [
148 | {
149 | "name": "Pádraic Brady",
150 | "email": "padraic.brady@gmail.com",
151 | "homepage": "http://blog.astrumfutura.com"
152 | },
153 | {
154 | "name": "Dave Marshall",
155 | "email": "dave.marshall@atstsolutions.co.uk",
156 | "homepage": "http://davedevelopment.co.uk"
157 | }
158 | ],
159 | "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.",
160 | "homepage": "http://github.com/padraic/mockery",
161 | "keywords": [
162 | "BDD",
163 | "TDD",
164 | "library",
165 | "mock",
166 | "mock objects",
167 | "mockery",
168 | "stub",
169 | "test",
170 | "test double",
171 | "testing"
172 | ],
173 | "time": "2015-04-02 19:54:00"
174 | },
175 | {
176 | "name": "phpdocumentor/reflection-docblock",
177 | "version": "2.0.4",
178 | "source": {
179 | "type": "git",
180 | "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
181 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8"
182 | },
183 | "dist": {
184 | "type": "zip",
185 | "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8",
186 | "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8",
187 | "shasum": ""
188 | },
189 | "require": {
190 | "php": ">=5.3.3"
191 | },
192 | "require-dev": {
193 | "phpunit/phpunit": "~4.0"
194 | },
195 | "suggest": {
196 | "dflydev/markdown": "~1.0",
197 | "erusev/parsedown": "~1.0"
198 | },
199 | "type": "library",
200 | "extra": {
201 | "branch-alias": {
202 | "dev-master": "2.0.x-dev"
203 | }
204 | },
205 | "autoload": {
206 | "psr-0": {
207 | "phpDocumentor": [
208 | "src/"
209 | ]
210 | }
211 | },
212 | "notification-url": "https://packagist.org/downloads/",
213 | "license": [
214 | "MIT"
215 | ],
216 | "authors": [
217 | {
218 | "name": "Mike van Riel",
219 | "email": "mike.vanriel@naenius.com"
220 | }
221 | ],
222 | "time": "2015-02-03 12:10:50"
223 | },
224 | {
225 | "name": "phpspec/prophecy",
226 | "version": "v1.5.0",
227 | "source": {
228 | "type": "git",
229 | "url": "https://github.com/phpspec/prophecy.git",
230 | "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7"
231 | },
232 | "dist": {
233 | "type": "zip",
234 | "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7",
235 | "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7",
236 | "shasum": ""
237 | },
238 | "require": {
239 | "doctrine/instantiator": "^1.0.2",
240 | "phpdocumentor/reflection-docblock": "~2.0",
241 | "sebastian/comparator": "~1.1"
242 | },
243 | "require-dev": {
244 | "phpspec/phpspec": "~2.0"
245 | },
246 | "type": "library",
247 | "extra": {
248 | "branch-alias": {
249 | "dev-master": "1.4.x-dev"
250 | }
251 | },
252 | "autoload": {
253 | "psr-0": {
254 | "Prophecy\\": "src/"
255 | }
256 | },
257 | "notification-url": "https://packagist.org/downloads/",
258 | "license": [
259 | "MIT"
260 | ],
261 | "authors": [
262 | {
263 | "name": "Konstantin Kudryashov",
264 | "email": "ever.zet@gmail.com",
265 | "homepage": "http://everzet.com"
266 | },
267 | {
268 | "name": "Marcello Duarte",
269 | "email": "marcello.duarte@gmail.com"
270 | }
271 | ],
272 | "description": "Highly opinionated mocking framework for PHP 5.3+",
273 | "homepage": "https://github.com/phpspec/prophecy",
274 | "keywords": [
275 | "Double",
276 | "Dummy",
277 | "fake",
278 | "mock",
279 | "spy",
280 | "stub"
281 | ],
282 | "time": "2015-08-13 10:07:40"
283 | },
284 | {
285 | "name": "phpunit/php-code-coverage",
286 | "version": "2.2.4",
287 | "source": {
288 | "type": "git",
289 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
290 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979"
291 | },
292 | "dist": {
293 | "type": "zip",
294 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979",
295 | "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979",
296 | "shasum": ""
297 | },
298 | "require": {
299 | "php": ">=5.3.3",
300 | "phpunit/php-file-iterator": "~1.3",
301 | "phpunit/php-text-template": "~1.2",
302 | "phpunit/php-token-stream": "~1.3",
303 | "sebastian/environment": "^1.3.2",
304 | "sebastian/version": "~1.0"
305 | },
306 | "require-dev": {
307 | "ext-xdebug": ">=2.1.4",
308 | "phpunit/phpunit": "~4"
309 | },
310 | "suggest": {
311 | "ext-dom": "*",
312 | "ext-xdebug": ">=2.2.1",
313 | "ext-xmlwriter": "*"
314 | },
315 | "type": "library",
316 | "extra": {
317 | "branch-alias": {
318 | "dev-master": "2.2.x-dev"
319 | }
320 | },
321 | "autoload": {
322 | "classmap": [
323 | "src/"
324 | ]
325 | },
326 | "notification-url": "https://packagist.org/downloads/",
327 | "license": [
328 | "BSD-3-Clause"
329 | ],
330 | "authors": [
331 | {
332 | "name": "Sebastian Bergmann",
333 | "email": "sb@sebastian-bergmann.de",
334 | "role": "lead"
335 | }
336 | ],
337 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
338 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
339 | "keywords": [
340 | "coverage",
341 | "testing",
342 | "xunit"
343 | ],
344 | "time": "2015-10-06 15:47:00"
345 | },
346 | {
347 | "name": "phpunit/php-file-iterator",
348 | "version": "1.4.1",
349 | "source": {
350 | "type": "git",
351 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
352 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0"
353 | },
354 | "dist": {
355 | "type": "zip",
356 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
357 | "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0",
358 | "shasum": ""
359 | },
360 | "require": {
361 | "php": ">=5.3.3"
362 | },
363 | "type": "library",
364 | "extra": {
365 | "branch-alias": {
366 | "dev-master": "1.4.x-dev"
367 | }
368 | },
369 | "autoload": {
370 | "classmap": [
371 | "src/"
372 | ]
373 | },
374 | "notification-url": "https://packagist.org/downloads/",
375 | "license": [
376 | "BSD-3-Clause"
377 | ],
378 | "authors": [
379 | {
380 | "name": "Sebastian Bergmann",
381 | "email": "sb@sebastian-bergmann.de",
382 | "role": "lead"
383 | }
384 | ],
385 | "description": "FilterIterator implementation that filters files based on a list of suffixes.",
386 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
387 | "keywords": [
388 | "filesystem",
389 | "iterator"
390 | ],
391 | "time": "2015-06-21 13:08:43"
392 | },
393 | {
394 | "name": "phpunit/php-text-template",
395 | "version": "1.2.1",
396 | "source": {
397 | "type": "git",
398 | "url": "https://github.com/sebastianbergmann/php-text-template.git",
399 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
400 | },
401 | "dist": {
402 | "type": "zip",
403 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
404 | "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
405 | "shasum": ""
406 | },
407 | "require": {
408 | "php": ">=5.3.3"
409 | },
410 | "type": "library",
411 | "autoload": {
412 | "classmap": [
413 | "src/"
414 | ]
415 | },
416 | "notification-url": "https://packagist.org/downloads/",
417 | "license": [
418 | "BSD-3-Clause"
419 | ],
420 | "authors": [
421 | {
422 | "name": "Sebastian Bergmann",
423 | "email": "sebastian@phpunit.de",
424 | "role": "lead"
425 | }
426 | ],
427 | "description": "Simple template engine.",
428 | "homepage": "https://github.com/sebastianbergmann/php-text-template/",
429 | "keywords": [
430 | "template"
431 | ],
432 | "time": "2015-06-21 13:50:34"
433 | },
434 | {
435 | "name": "phpunit/php-timer",
436 | "version": "1.0.7",
437 | "source": {
438 | "type": "git",
439 | "url": "https://github.com/sebastianbergmann/php-timer.git",
440 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b"
441 | },
442 | "dist": {
443 | "type": "zip",
444 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
445 | "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
446 | "shasum": ""
447 | },
448 | "require": {
449 | "php": ">=5.3.3"
450 | },
451 | "type": "library",
452 | "autoload": {
453 | "classmap": [
454 | "src/"
455 | ]
456 | },
457 | "notification-url": "https://packagist.org/downloads/",
458 | "license": [
459 | "BSD-3-Clause"
460 | ],
461 | "authors": [
462 | {
463 | "name": "Sebastian Bergmann",
464 | "email": "sb@sebastian-bergmann.de",
465 | "role": "lead"
466 | }
467 | ],
468 | "description": "Utility class for timing",
469 | "homepage": "https://github.com/sebastianbergmann/php-timer/",
470 | "keywords": [
471 | "timer"
472 | ],
473 | "time": "2015-06-21 08:01:12"
474 | },
475 | {
476 | "name": "phpunit/php-token-stream",
477 | "version": "1.4.8",
478 | "source": {
479 | "type": "git",
480 | "url": "https://github.com/sebastianbergmann/php-token-stream.git",
481 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da"
482 | },
483 | "dist": {
484 | "type": "zip",
485 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
486 | "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da",
487 | "shasum": ""
488 | },
489 | "require": {
490 | "ext-tokenizer": "*",
491 | "php": ">=5.3.3"
492 | },
493 | "require-dev": {
494 | "phpunit/phpunit": "~4.2"
495 | },
496 | "type": "library",
497 | "extra": {
498 | "branch-alias": {
499 | "dev-master": "1.4-dev"
500 | }
501 | },
502 | "autoload": {
503 | "classmap": [
504 | "src/"
505 | ]
506 | },
507 | "notification-url": "https://packagist.org/downloads/",
508 | "license": [
509 | "BSD-3-Clause"
510 | ],
511 | "authors": [
512 | {
513 | "name": "Sebastian Bergmann",
514 | "email": "sebastian@phpunit.de"
515 | }
516 | ],
517 | "description": "Wrapper around PHP's tokenizer extension.",
518 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
519 | "keywords": [
520 | "tokenizer"
521 | ],
522 | "time": "2015-09-15 10:49:45"
523 | },
524 | {
525 | "name": "phpunit/phpunit",
526 | "version": "4.8.19",
527 | "source": {
528 | "type": "git",
529 | "url": "https://github.com/sebastianbergmann/phpunit.git",
530 | "reference": "b2caaf8947aba5e002d42126723e9d69795f32b4"
531 | },
532 | "dist": {
533 | "type": "zip",
534 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b2caaf8947aba5e002d42126723e9d69795f32b4",
535 | "reference": "b2caaf8947aba5e002d42126723e9d69795f32b4",
536 | "shasum": ""
537 | },
538 | "require": {
539 | "ext-dom": "*",
540 | "ext-json": "*",
541 | "ext-pcre": "*",
542 | "ext-reflection": "*",
543 | "ext-spl": "*",
544 | "php": ">=5.3.3",
545 | "phpspec/prophecy": "^1.3.1",
546 | "phpunit/php-code-coverage": "~2.1",
547 | "phpunit/php-file-iterator": "~1.4",
548 | "phpunit/php-text-template": "~1.2",
549 | "phpunit/php-timer": ">=1.0.6",
550 | "phpunit/phpunit-mock-objects": "~2.3",
551 | "sebastian/comparator": "~1.1",
552 | "sebastian/diff": "~1.2",
553 | "sebastian/environment": "~1.3",
554 | "sebastian/exporter": "~1.2",
555 | "sebastian/global-state": "~1.0",
556 | "sebastian/version": "~1.0",
557 | "symfony/yaml": "~2.1|~3.0"
558 | },
559 | "suggest": {
560 | "phpunit/php-invoker": "~1.1"
561 | },
562 | "bin": [
563 | "phpunit"
564 | ],
565 | "type": "library",
566 | "extra": {
567 | "branch-alias": {
568 | "dev-master": "4.8.x-dev"
569 | }
570 | },
571 | "autoload": {
572 | "classmap": [
573 | "src/"
574 | ]
575 | },
576 | "notification-url": "https://packagist.org/downloads/",
577 | "license": [
578 | "BSD-3-Clause"
579 | ],
580 | "authors": [
581 | {
582 | "name": "Sebastian Bergmann",
583 | "email": "sebastian@phpunit.de",
584 | "role": "lead"
585 | }
586 | ],
587 | "description": "The PHP Unit Testing framework.",
588 | "homepage": "https://phpunit.de/",
589 | "keywords": [
590 | "phpunit",
591 | "testing",
592 | "xunit"
593 | ],
594 | "time": "2015-11-30 08:18:59"
595 | },
596 | {
597 | "name": "phpunit/phpunit-mock-objects",
598 | "version": "2.3.8",
599 | "source": {
600 | "type": "git",
601 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
602 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983"
603 | },
604 | "dist": {
605 | "type": "zip",
606 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983",
607 | "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983",
608 | "shasum": ""
609 | },
610 | "require": {
611 | "doctrine/instantiator": "^1.0.2",
612 | "php": ">=5.3.3",
613 | "phpunit/php-text-template": "~1.2",
614 | "sebastian/exporter": "~1.2"
615 | },
616 | "require-dev": {
617 | "phpunit/phpunit": "~4.4"
618 | },
619 | "suggest": {
620 | "ext-soap": "*"
621 | },
622 | "type": "library",
623 | "extra": {
624 | "branch-alias": {
625 | "dev-master": "2.3.x-dev"
626 | }
627 | },
628 | "autoload": {
629 | "classmap": [
630 | "src/"
631 | ]
632 | },
633 | "notification-url": "https://packagist.org/downloads/",
634 | "license": [
635 | "BSD-3-Clause"
636 | ],
637 | "authors": [
638 | {
639 | "name": "Sebastian Bergmann",
640 | "email": "sb@sebastian-bergmann.de",
641 | "role": "lead"
642 | }
643 | ],
644 | "description": "Mock Object library for PHPUnit",
645 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
646 | "keywords": [
647 | "mock",
648 | "xunit"
649 | ],
650 | "time": "2015-10-02 06:51:40"
651 | },
652 | {
653 | "name": "sebastian/comparator",
654 | "version": "1.2.0",
655 | "source": {
656 | "type": "git",
657 | "url": "https://github.com/sebastianbergmann/comparator.git",
658 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
659 | },
660 | "dist": {
661 | "type": "zip",
662 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
663 | "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
664 | "shasum": ""
665 | },
666 | "require": {
667 | "php": ">=5.3.3",
668 | "sebastian/diff": "~1.2",
669 | "sebastian/exporter": "~1.2"
670 | },
671 | "require-dev": {
672 | "phpunit/phpunit": "~4.4"
673 | },
674 | "type": "library",
675 | "extra": {
676 | "branch-alias": {
677 | "dev-master": "1.2.x-dev"
678 | }
679 | },
680 | "autoload": {
681 | "classmap": [
682 | "src/"
683 | ]
684 | },
685 | "notification-url": "https://packagist.org/downloads/",
686 | "license": [
687 | "BSD-3-Clause"
688 | ],
689 | "authors": [
690 | {
691 | "name": "Jeff Welch",
692 | "email": "whatthejeff@gmail.com"
693 | },
694 | {
695 | "name": "Volker Dusch",
696 | "email": "github@wallbash.com"
697 | },
698 | {
699 | "name": "Bernhard Schussek",
700 | "email": "bschussek@2bepublished.at"
701 | },
702 | {
703 | "name": "Sebastian Bergmann",
704 | "email": "sebastian@phpunit.de"
705 | }
706 | ],
707 | "description": "Provides the functionality to compare PHP values for equality",
708 | "homepage": "http://www.github.com/sebastianbergmann/comparator",
709 | "keywords": [
710 | "comparator",
711 | "compare",
712 | "equality"
713 | ],
714 | "time": "2015-07-26 15:48:44"
715 | },
716 | {
717 | "name": "sebastian/diff",
718 | "version": "1.3.0",
719 | "source": {
720 | "type": "git",
721 | "url": "https://github.com/sebastianbergmann/diff.git",
722 | "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
723 | },
724 | "dist": {
725 | "type": "zip",
726 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
727 | "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
728 | "shasum": ""
729 | },
730 | "require": {
731 | "php": ">=5.3.3"
732 | },
733 | "require-dev": {
734 | "phpunit/phpunit": "~4.2"
735 | },
736 | "type": "library",
737 | "extra": {
738 | "branch-alias": {
739 | "dev-master": "1.3-dev"
740 | }
741 | },
742 | "autoload": {
743 | "classmap": [
744 | "src/"
745 | ]
746 | },
747 | "notification-url": "https://packagist.org/downloads/",
748 | "license": [
749 | "BSD-3-Clause"
750 | ],
751 | "authors": [
752 | {
753 | "name": "Kore Nordmann",
754 | "email": "mail@kore-nordmann.de"
755 | },
756 | {
757 | "name": "Sebastian Bergmann",
758 | "email": "sebastian@phpunit.de"
759 | }
760 | ],
761 | "description": "Diff implementation",
762 | "homepage": "http://www.github.com/sebastianbergmann/diff",
763 | "keywords": [
764 | "diff"
765 | ],
766 | "time": "2015-02-22 15:13:53"
767 | },
768 | {
769 | "name": "sebastian/environment",
770 | "version": "1.3.3",
771 | "source": {
772 | "type": "git",
773 | "url": "https://github.com/sebastianbergmann/environment.git",
774 | "reference": "6e7133793a8e5a5714a551a8324337374be209df"
775 | },
776 | "dist": {
777 | "type": "zip",
778 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6e7133793a8e5a5714a551a8324337374be209df",
779 | "reference": "6e7133793a8e5a5714a551a8324337374be209df",
780 | "shasum": ""
781 | },
782 | "require": {
783 | "php": ">=5.3.3"
784 | },
785 | "require-dev": {
786 | "phpunit/phpunit": "~4.4"
787 | },
788 | "type": "library",
789 | "extra": {
790 | "branch-alias": {
791 | "dev-master": "1.3.x-dev"
792 | }
793 | },
794 | "autoload": {
795 | "classmap": [
796 | "src/"
797 | ]
798 | },
799 | "notification-url": "https://packagist.org/downloads/",
800 | "license": [
801 | "BSD-3-Clause"
802 | ],
803 | "authors": [
804 | {
805 | "name": "Sebastian Bergmann",
806 | "email": "sebastian@phpunit.de"
807 | }
808 | ],
809 | "description": "Provides functionality to handle HHVM/PHP environments",
810 | "homepage": "http://www.github.com/sebastianbergmann/environment",
811 | "keywords": [
812 | "Xdebug",
813 | "environment",
814 | "hhvm"
815 | ],
816 | "time": "2015-12-02 08:37:27"
817 | },
818 | {
819 | "name": "sebastian/exporter",
820 | "version": "1.2.1",
821 | "source": {
822 | "type": "git",
823 | "url": "https://github.com/sebastianbergmann/exporter.git",
824 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e"
825 | },
826 | "dist": {
827 | "type": "zip",
828 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
829 | "reference": "7ae5513327cb536431847bcc0c10edba2701064e",
830 | "shasum": ""
831 | },
832 | "require": {
833 | "php": ">=5.3.3",
834 | "sebastian/recursion-context": "~1.0"
835 | },
836 | "require-dev": {
837 | "phpunit/phpunit": "~4.4"
838 | },
839 | "type": "library",
840 | "extra": {
841 | "branch-alias": {
842 | "dev-master": "1.2.x-dev"
843 | }
844 | },
845 | "autoload": {
846 | "classmap": [
847 | "src/"
848 | ]
849 | },
850 | "notification-url": "https://packagist.org/downloads/",
851 | "license": [
852 | "BSD-3-Clause"
853 | ],
854 | "authors": [
855 | {
856 | "name": "Jeff Welch",
857 | "email": "whatthejeff@gmail.com"
858 | },
859 | {
860 | "name": "Volker Dusch",
861 | "email": "github@wallbash.com"
862 | },
863 | {
864 | "name": "Bernhard Schussek",
865 | "email": "bschussek@2bepublished.at"
866 | },
867 | {
868 | "name": "Sebastian Bergmann",
869 | "email": "sebastian@phpunit.de"
870 | },
871 | {
872 | "name": "Adam Harvey",
873 | "email": "aharvey@php.net"
874 | }
875 | ],
876 | "description": "Provides the functionality to export PHP variables for visualization",
877 | "homepage": "http://www.github.com/sebastianbergmann/exporter",
878 | "keywords": [
879 | "export",
880 | "exporter"
881 | ],
882 | "time": "2015-06-21 07:55:53"
883 | },
884 | {
885 | "name": "sebastian/global-state",
886 | "version": "1.1.1",
887 | "source": {
888 | "type": "git",
889 | "url": "https://github.com/sebastianbergmann/global-state.git",
890 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
891 | },
892 | "dist": {
893 | "type": "zip",
894 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
895 | "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
896 | "shasum": ""
897 | },
898 | "require": {
899 | "php": ">=5.3.3"
900 | },
901 | "require-dev": {
902 | "phpunit/phpunit": "~4.2"
903 | },
904 | "suggest": {
905 | "ext-uopz": "*"
906 | },
907 | "type": "library",
908 | "extra": {
909 | "branch-alias": {
910 | "dev-master": "1.0-dev"
911 | }
912 | },
913 | "autoload": {
914 | "classmap": [
915 | "src/"
916 | ]
917 | },
918 | "notification-url": "https://packagist.org/downloads/",
919 | "license": [
920 | "BSD-3-Clause"
921 | ],
922 | "authors": [
923 | {
924 | "name": "Sebastian Bergmann",
925 | "email": "sebastian@phpunit.de"
926 | }
927 | ],
928 | "description": "Snapshotting of global state",
929 | "homepage": "http://www.github.com/sebastianbergmann/global-state",
930 | "keywords": [
931 | "global state"
932 | ],
933 | "time": "2015-10-12 03:26:01"
934 | },
935 | {
936 | "name": "sebastian/recursion-context",
937 | "version": "1.0.1",
938 | "source": {
939 | "type": "git",
940 | "url": "https://github.com/sebastianbergmann/recursion-context.git",
941 | "reference": "994d4a811bafe801fb06dccbee797863ba2792ba"
942 | },
943 | "dist": {
944 | "type": "zip",
945 | "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba",
946 | "reference": "994d4a811bafe801fb06dccbee797863ba2792ba",
947 | "shasum": ""
948 | },
949 | "require": {
950 | "php": ">=5.3.3"
951 | },
952 | "require-dev": {
953 | "phpunit/phpunit": "~4.4"
954 | },
955 | "type": "library",
956 | "extra": {
957 | "branch-alias": {
958 | "dev-master": "1.0.x-dev"
959 | }
960 | },
961 | "autoload": {
962 | "classmap": [
963 | "src/"
964 | ]
965 | },
966 | "notification-url": "https://packagist.org/downloads/",
967 | "license": [
968 | "BSD-3-Clause"
969 | ],
970 | "authors": [
971 | {
972 | "name": "Jeff Welch",
973 | "email": "whatthejeff@gmail.com"
974 | },
975 | {
976 | "name": "Sebastian Bergmann",
977 | "email": "sebastian@phpunit.de"
978 | },
979 | {
980 | "name": "Adam Harvey",
981 | "email": "aharvey@php.net"
982 | }
983 | ],
984 | "description": "Provides functionality to recursively process PHP variables",
985 | "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
986 | "time": "2015-06-21 08:04:50"
987 | },
988 | {
989 | "name": "sebastian/version",
990 | "version": "1.0.6",
991 | "source": {
992 | "type": "git",
993 | "url": "https://github.com/sebastianbergmann/version.git",
994 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
995 | },
996 | "dist": {
997 | "type": "zip",
998 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
999 | "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
1000 | "shasum": ""
1001 | },
1002 | "type": "library",
1003 | "autoload": {
1004 | "classmap": [
1005 | "src/"
1006 | ]
1007 | },
1008 | "notification-url": "https://packagist.org/downloads/",
1009 | "license": [
1010 | "BSD-3-Clause"
1011 | ],
1012 | "authors": [
1013 | {
1014 | "name": "Sebastian Bergmann",
1015 | "email": "sebastian@phpunit.de",
1016 | "role": "lead"
1017 | }
1018 | ],
1019 | "description": "Library that helps with managing the version number of Git-hosted PHP projects",
1020 | "homepage": "https://github.com/sebastianbergmann/version",
1021 | "time": "2015-06-21 13:59:46"
1022 | },
1023 | {
1024 | "name": "symfony/yaml",
1025 | "version": "v3.0.0",
1026 | "source": {
1027 | "type": "git",
1028 | "url": "https://github.com/symfony/yaml.git",
1029 | "reference": "177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002"
1030 | },
1031 | "dist": {
1032 | "type": "zip",
1033 | "url": "https://api.github.com/repos/symfony/yaml/zipball/177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002",
1034 | "reference": "177a015cb0e19ff4a49e0e2e2c5fc1c1bee07002",
1035 | "shasum": ""
1036 | },
1037 | "require": {
1038 | "php": ">=5.5.9"
1039 | },
1040 | "type": "library",
1041 | "extra": {
1042 | "branch-alias": {
1043 | "dev-master": "3.0-dev"
1044 | }
1045 | },
1046 | "autoload": {
1047 | "psr-4": {
1048 | "Symfony\\Component\\Yaml\\": ""
1049 | },
1050 | "exclude-from-classmap": [
1051 | "/Tests/"
1052 | ]
1053 | },
1054 | "notification-url": "https://packagist.org/downloads/",
1055 | "license": [
1056 | "MIT"
1057 | ],
1058 | "authors": [
1059 | {
1060 | "name": "Fabien Potencier",
1061 | "email": "fabien@symfony.com"
1062 | },
1063 | {
1064 | "name": "Symfony Community",
1065 | "homepage": "https://symfony.com/contributors"
1066 | }
1067 | ],
1068 | "description": "Symfony Yaml Component",
1069 | "homepage": "https://symfony.com",
1070 | "time": "2015-11-30 12:36:17"
1071 | }
1072 | ],
1073 | "aliases": [],
1074 | "minimum-stability": "stable",
1075 | "stability-flags": [],
1076 | "prefer-stable": false,
1077 | "prefer-lowest": false,
1078 | "platform": {
1079 | "php": ">=5.3.0"
1080 | },
1081 | "platform-dev": []
1082 | }
1083 |
--------------------------------------------------------------------------------
/config/sendy.php:
--------------------------------------------------------------------------------
1 | '',
6 |
7 | // Default list id
8 | 'listId' => '',
9 |
10 | // The Sendy API Key
11 | 'apiKey' => '',
12 | ];
13 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/Facades/Sendy.php:
--------------------------------------------------------------------------------
1 | setListId($config['listId']);
28 | $this->setInstallationUrl($config['installationUrl']);
29 | $this->setApiKey($config['apiKey']);
30 |
31 | $this->checkProperties();
32 | }
33 |
34 | /**
35 | * @param mixed $installationUrl
36 | */
37 | public function setInstallationUrl($installationUrl)
38 | {
39 | $this->installationUrl = $installationUrl;
40 | }
41 |
42 | /**
43 | * @param mixed $apiKey
44 | */
45 | public function setApiKey($apiKey)
46 | {
47 | $this->apiKey = $apiKey;
48 | }
49 |
50 | /**
51 | * @param $listId
52 | *
53 | * @return $this
54 | */
55 | public function setListId($listId)
56 | {
57 | $this->listId = $listId;
58 |
59 | return $this;
60 | }
61 |
62 | /**
63 | * Method to add a new subscriber to a list
64 | *
65 | * @param array $values
66 | *
67 | * @return array
68 | */
69 | public function subscribe(array $values)
70 | {
71 | $result = $this->buildAndSend('subscribe', $values);
72 |
73 | /**
74 | * Prepare the array to return
75 | */
76 | $notice = [
77 | 'status' => true,
78 | 'message' => '',
79 | ];
80 |
81 | /**
82 | * Handle results
83 | */
84 | switch (strval($result)) {
85 | case '1':
86 | $notice['message'] = 'Subscribed.';
87 |
88 | break;
89 | case 'Already subscribed.':
90 | $notice['message'] = $result;
91 |
92 | break;
93 | default:
94 | $notice = [
95 | 'status' => false,
96 | 'message' => $result
97 | ];
98 |
99 | break;
100 | }
101 |
102 | return $notice;
103 | }
104 |
105 | /**
106 | * Updating a subscriber using the email like a reference/key
107 | * If the email doesn't exists in the current list, this will create a new subscriber
108 | *
109 | * @param $email
110 | * @param array $values
111 | *
112 | * @return array
113 | */
114 | public function update($email, array $values)
115 | {
116 | $values = array_merge([
117 | 'email' => $email
118 | ], $values);
119 |
120 | return $this->subscribe($values);
121 | }
122 |
123 | /**
124 | * Method to unsubscribe a user from a list
125 | *
126 | * @param $email
127 | *
128 | * @return array
129 | */
130 | public function unsubscribe($email)
131 | {
132 | $result = $this->buildAndSend('unsubscribe', ['email' => $email]);
133 |
134 | /**
135 | * Prepare the array to return
136 | */
137 | $notice = [
138 | 'status' => true,
139 | 'message' => '',
140 | ];
141 |
142 | /**
143 | * Handle results
144 | */
145 | switch (strval($result)) {
146 | case '1':
147 | $notice['message'] = 'Unsubscribed';
148 |
149 | break;
150 | default:
151 | $notice = [
152 | 'status' => false,
153 | 'message' => $result
154 | ];
155 |
156 | break;
157 | }
158 |
159 | return $notice;
160 | }
161 |
162 | /**
163 | * Method to delete a user from a list
164 | *
165 | * @param $email
166 | *
167 | * @return array
168 | */
169 | public function delete($email)
170 | {
171 | $result = $this->buildAndSend('/api/subscribers/delete.php', ['email' => $email]);
172 |
173 | /**
174 | * Prepare the array to return
175 | */
176 | $notice = [
177 | 'status' => true,
178 | 'message' => '',
179 | ];
180 |
181 | /**
182 | * Handle results
183 | */
184 | switch (strval($result)) {
185 | case '1':
186 | $notice['message'] = 'Deleted';
187 |
188 | break;
189 | default:
190 | $notice = [
191 | 'status' => false,
192 | 'message' => $result
193 | ];
194 |
195 | break;
196 | }
197 |
198 | return $notice;
199 | }
200 |
201 |
202 | /**
203 | * Method to get the current status of a subscriber.
204 | * Success: Subscribed, Unsubscribed, Unconfirmed, Bounced, Soft bounced, Complained
205 | * Error: No data passed, Email does not exist in list, etc.
206 | *
207 | * @param $email
208 | *
209 | * @return string
210 | */
211 | public function status($email)
212 | {
213 | $url = 'api/subscribers/subscription-status.php';
214 |
215 | return $this->buildAndSend($url, ['email' => $email]);
216 | }
217 |
218 | /**
219 | * Gets the total active subscriber count
220 | *
221 | * @return string
222 | */
223 | public function count()
224 | {
225 | $url = 'api/subscribers/active-subscriber-count.php';
226 |
227 | return $this->buildAndSend($url, []);
228 | }
229 |
230 | /**
231 | * Create a campaign based on the input params. See API (https://sendy.co/api#4) for parameters.
232 | * Bug: The API doesn't save the listIds passed to Sendy.
233 | *
234 | * @param $options
235 | * @param $content
236 | * @param bool $send : Set this to true to send the campaign
237 | *
238 | * @return string
239 | * @throws \Exception
240 | */
241 | public function createCampaign($options, $content, $send = false)
242 | {
243 | $url = '/api/campaigns/create.php';
244 |
245 | if (empty($options['from_name'])) {
246 | throw new \Exception('From Name is not set', 1);
247 | }
248 |
249 | if (empty($options['from_email'])) {
250 | throw new \Exception('From Email is not set', 1);
251 | }
252 |
253 | if (empty($options['reply_to'])) {
254 | throw new \Exception('Reply To address is not set', 1);
255 | }
256 |
257 | if (empty($options['subject'])) {
258 | throw new \Exception('Subject is not set', 1);
259 | }
260 |
261 | // 'plain_text' field can be included, but optional
262 | if (empty($content['html_text'])) {
263 | throw new \Exception('Campaign Content (HTML) is not set', 1);
264 | }
265 |
266 | if ($send) {
267 | if (empty($options['brand_id'])) {
268 | throw new \Exception('Brand ID should be set for Draft campaigns', 1);
269 | }
270 | }
271 |
272 | // list IDs can be single or comma separated values
273 | if (empty($options['list_ids'])) {
274 | $options['list_ids'] = $this->listId;
275 | }
276 |
277 | // should we send the campaign (1) or save as Draft (0)
278 | $options['send_campaign'] = ($send) ? 1 : 0;
279 |
280 | return $this->buildAndSend($url, array_merge($options, $content));
281 | }
282 |
283 | /**
284 | * @param $url
285 | * @param array $values
286 | *
287 | * @return string
288 | */
289 | private function buildAndSend($url, array $values)
290 | {
291 | /**
292 | * Merge the passed in values with the options for return
293 | * Passing listId too, because old API calls use list, new ones use listId
294 | */
295 | $content = array_merge($values, [
296 | 'list' => $this->listId,
297 | 'list_id' => $this->listId, # ¯\_(ツ)_/¯
298 | 'api_key' => $this->apiKey,
299 | 'boolean' => 'true',
300 | ]);
301 |
302 | /**
303 | * Build a query using the $content
304 | */
305 | $post_data = http_build_query($content);
306 | $ch = curl_init($this->installationUrl . '/' . $url);
307 |
308 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
309 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
310 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
311 | curl_setopt($ch, CURLOPT_POST, 1);
312 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
313 |
314 | $result = curl_exec($ch);
315 | curl_close($ch);
316 |
317 | return $result;
318 | }
319 |
320 | /**
321 | * Checks the properties
322 | *
323 | * @throws \Exception
324 | */
325 | private function checkProperties()
326 | {
327 | if (!isset($this->listId)) {
328 | throw new \Exception('[listId] is not set', 1);
329 | }
330 |
331 | if (!isset($this->installationUrl)) {
332 | throw new \Exception('[installationUrl] is not set', 1);
333 | }
334 |
335 | if (!isset($this->apiKey)) {
336 | throw new \Exception('[apiKey] is not set', 1);
337 | }
338 | }
339 | }
340 |
--------------------------------------------------------------------------------
/src/SendyServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
30 | __DIR__ . '/../config/sendy.php' => config_path('sendy.php')
31 | ]);
32 | }
33 |
34 | /**
35 | * Register the application services.
36 | *
37 | * @return void
38 | */
39 | public function register()
40 | {
41 | $this->app->singleton('Hocza\Sendy\Sendy', function ($app) {
42 | return new Sendy($app['config']['sendy']);
43 | });
44 | }
45 |
46 | /**
47 | * Get the services provided by the provider.
48 | *
49 | * @return array
50 | */
51 | public function provides()
52 | {
53 | return ['sendy'];
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/tests/SendyTest.php:
--------------------------------------------------------------------------------
1 | 'YOUR_LIST_ID',
10 | 'installationUrl' => 'YOUR_URL',
11 | 'apiKey' => 'API_KEY_HERE',
12 | ];
13 |
14 | public function testSimpleSubscribe()
15 | {
16 | $subscriber = new Sendy($this->config);
17 |
18 | $subscriber = $subscriber->subscribe([
19 | 'name' => 'Alison',
20 | 'email' => 'alison@gmail.com',
21 | ]);
22 |
23 | $this->assertEquals(true, $subscriber['status']);
24 | $this->assertEquals('Subscribed.', $subscriber['message']);
25 | }
26 |
27 | public function testSubscribeASubscriberThatAlreadyExists()
28 | {
29 | $subscriber = new Sendy($this->config);
30 |
31 | $subscriber->subscribe([
32 | 'name' => 'Alison',
33 | 'email' => 'alison2@gmail.com',
34 | ]);
35 |
36 | $subscriber = $subscriber->subscribe([
37 | 'name' => 'Alison',
38 | 'email' => 'alison2@gmail.com',
39 | ]);
40 |
41 | $this->assertEquals(true, $subscriber['status']);
42 | $this->assertEquals('Already subscribed.', $subscriber['message']);
43 | }
44 |
45 | public function testSimpleUnsubscribe()
46 | {
47 | $subscriber = new Sendy($this->config);
48 |
49 | $subscriber = $subscriber->unsubscribe('alison2@gmail.com');
50 | $this->assertEquals(true, $subscriber['status']);
51 | $this->assertEquals('Unsubscribed', $subscriber['message']);
52 | }
53 |
54 | public function testUnsubscribeASubscriberThatNotExists()
55 | {
56 | $subscriber = new Sendy($this->config);
57 |
58 | $subscriber = $subscriber->unsubscribe('zzzz@gmail.com');
59 |
60 | // The API doesn't provide this type of error
61 | $this->assertEquals(true, $subscriber['status']);
62 | $this->assertEquals('Unsubscribed', $subscriber['message']);
63 | }
64 |
65 | public function testCheckStatus()
66 | {
67 | $subscriber = new Sendy($this->config);
68 |
69 | $subscriber1 = $subscriber->status('zzzz@gmail.com');
70 | $this->assertEquals('Email does not exist in list', $subscriber1);
71 |
72 | $subscriber2 = $subscriber->status('alison2@gmail.com');
73 | $this->assertEquals('Unsubscribed', $subscriber2);
74 |
75 | $subscriber3 = $subscriber->status('alison@gmail.com');
76 | $this->assertEquals('Subscribed', $subscriber3);
77 | }
78 |
79 | public function testUpdate()
80 | {
81 | $subscriber = new Sendy($this->config);
82 | $subscriber = $subscriber->update('alison@gmail.com', [
83 | 'name' => 'Alison 2',
84 | ]);
85 |
86 | // This method use `subscribe` method to update data
87 | $this->assertEquals(true, $subscriber['status']);
88 | $this->assertEquals('Already subscribed.', $subscriber['message']);
89 | }
90 |
91 | public function testDelete()
92 | {
93 | $subscriber = new Sendy($this->config);
94 | $subscriber->subscribe([
95 | 'name' => 'Mark',
96 | 'email' => 'mark@gmail.com',
97 | ]);
98 | $currentStatus = $subscriber->status('mark@gmail.com');
99 | $this->assertEquals('Subscribed', $currentStatus);
100 |
101 | $deleteResult = $subscriber->delete('mark@gmail.com');
102 | $this->assertEquals(true, $deleteResult['status']);
103 |
104 | $currentStatus = $subscriber->status('mark@gmail.com');
105 | $this->assertEquals('Email does not exist in list', $currentStatus);
106 |
107 | }
108 | }
--------------------------------------------------------------------------------