|
1 |
| -### WIP |
2 |
| -This package is __WIP__, please do not use it in a production project yet. |
| 1 | +# Laravel Sendy is a simple and clean wrapper for the Sendy API |
| 2 | + |
| 3 | +[](https://packagist.org/packages/coderflexx/laravel-sendy) |
| 4 | +[](https://github.com/coderflexx/laravel-sendy/actions?query=workflow%3Arun-tests+branch%3Amain) |
| 5 | +[](https://github.com/coderflexx/laravel-sendy/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) |
| 6 | +[](https://packagist.org/packages/coderflexx/laravel-sendy) |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +Laravel Sendy is a simple and clean wrapper for the Sendy API, making it easy to manage subscribers, lists, and campaigns directly from your Laravel application. |
| 11 | + |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +You can install the package via composer: |
| 16 | + |
| 17 | +```bash |
| 18 | +composer require coderflexx/laravel-sendy |
| 19 | +``` |
| 20 | + |
| 21 | +You can publish the config file with: |
| 22 | + |
| 23 | +```bash |
| 24 | +php artisan vendor:publish --tag="laravel-sendy" |
| 25 | +``` |
| 26 | + |
| 27 | +This is the contents of the published config file: |
| 28 | + |
| 29 | +```php |
| 30 | +return [ |
| 31 | + /* |
| 32 | + |-------------------------------------------------------------------------- |
| 33 | + | Sendy Installation URL |
| 34 | + |-------------------------------------------------------------------------- |
| 35 | + | |
| 36 | + | This URL is used to connect to your Sendy installation. It should |
| 37 | + | point to the root of your Sendy installation. For example: |
| 38 | + | https://your-sendy-installation.com |
| 39 | + */ |
| 40 | + 'sendy_installation_url' => env('SENDY_INSTALLATION_URL', 'https://your-sendy-installation.com'), |
| 41 | + |
| 42 | + /* |
| 43 | + |-------------------------------------------------------------------------- |
| 44 | + | Sendy API Key |
| 45 | + |-------------------------------------------------------------------------- |
| 46 | + | |
| 47 | + | This key is used to authenticate your application with the Sendy |
| 48 | + | installation. You can find your API key in the Sendy settings. |
| 49 | + | Make sure to keep this key secure and do not share it with anyone. |
| 50 | + | It is recommended to use environment variables to store sensitive |
| 51 | + | information like API keys. You can set the SENDY_API_KEY |
| 52 | + */ |
| 53 | + 'sendy_api_key' => env('SENDY_API_KEY', 'your-sendy-api-key'), |
| 54 | +]; |
| 55 | +``` |
| 56 | + |
| 57 | +## API Keys |
| 58 | +After Installation, you can grab your `API KEYS` from the sendy app installation, then add them in `.env` file |
| 59 | + |
| 60 | +```env |
| 61 | +SENDY_INSTALLATION_URL=https://your-app-installation.com/ |
| 62 | +SENDY_API_KEY=your-api-key |
| 63 | +``` |
| 64 | + |
| 65 | +## Sendy Version |
| 66 | +This package is compatible with __Sendy v6.1.2__ (Latest) |
| 67 | + |
| 68 | +## Usage |
| 69 | + |
| 70 | +In order to use the package, you can use the facade directly, followed by the main method api (e.g. `subscribers()` then the verb (action)) |
| 71 | + |
| 72 | +```php |
| 73 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 74 | + |
| 75 | +$sendy = Sendy::{$service()}->{$action()} |
| 76 | +``` |
| 77 | + |
| 78 | +### Async Argument for HTTP Requests |
| 79 | + |
| 80 | +All HTTP requests support an `async` option, allowing you to __defer execution__. This is useful when a request doesn't need to run immediately or isn't a high priority. You can handle it later using await when you're ready to process the result. |
| 81 | + |
| 82 | +Example: |
| 83 | + |
| 84 | +```php |
| 85 | +$promise = Sendy::subscribers()->subscribe( |
| 86 | + data: $data, |
| 87 | + async: true // The request is deferred and returns a promise |
| 88 | +); |
| 89 | + |
| 90 | +// perform other tasks/operation here |
| 91 | + |
| 92 | +// later, wait for the response when you're ready. |
| 93 | +$response = $promise->await(); |
| 94 | +``` |
| 95 | + |
| 96 | +### Subscribers |
| 97 | +In order to create a create/delete a subscriber, you have to access the subscribers service first, then to the action |
| 98 | + |
| 99 | +#### Subscribe a User |
| 100 | + |
| 101 | +```php |
| 102 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 103 | + |
| 104 | +$data = [ |
| 105 | + 'name' => 'John Doe', |
| 106 | + |
| 107 | + 'list' => '123', |
| 108 | + 'country' => 'US', |
| 109 | +]; |
| 110 | + |
| 111 | +$response = Sendy::subscribers()->subscribe( |
| 112 | + data: $data, |
| 113 | + async: false |
| 114 | + ); |
| 115 | +``` |
| 116 | + |
| 117 | +Full Documentation [Here](https://sendy.co/api#subscribe) |
| 118 | + |
| 119 | +#### Unsubscribe a User |
| 120 | + |
| 121 | +```php |
| 122 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 123 | + |
| 124 | +$data = [ |
| 125 | + |
| 126 | + 'list' => '123', |
| 127 | + 'boolean' => true, // to get plan text response, instead of json. |
| 128 | +]; |
| 129 | + |
| 130 | +$response = Sendy::subscribers()->unsubscribe( |
| 131 | + data: $data, |
| 132 | + async: false |
| 133 | + ); |
| 134 | + |
| 135 | +``` |
| 136 | +Full Documentation [Here](https://sendy.co/api#unsubscribe) |
| 137 | + |
| 138 | +#### Delete Subscriber |
| 139 | + |
| 140 | +```php |
| 141 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 142 | + |
| 143 | +$data = [ |
| 144 | + |
| 145 | + 'list_id' => '123', |
| 146 | +]; |
| 147 | + |
| 148 | +$response = Sendy::subscribers()->delete( |
| 149 | + data: $data, |
| 150 | + async: false |
| 151 | + ); |
| 152 | + |
| 153 | +``` |
| 154 | + |
| 155 | +Full Documentation [Here](https://sendy.co/api#delete-subscriber) |
| 156 | + |
| 157 | +#### Subscriber Status |
| 158 | + |
| 159 | +```php |
| 160 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 161 | + |
| 162 | +$data = [ |
| 163 | + |
| 164 | + 'list_id' => '123', |
| 165 | +]; |
| 166 | + |
| 167 | +$response = Sendy::subscribers()->status( |
| 168 | + data: $data, |
| 169 | + async: false |
| 170 | + ); |
| 171 | + |
| 172 | +``` |
| 173 | + |
| 174 | +Full Documentation [Here](https://sendy.co/api#subscription-status) |
| 175 | + |
| 176 | +#### Subscribers Count |
| 177 | + |
| 178 | +```php |
| 179 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 180 | + |
| 181 | +$data = [ |
| 182 | + |
| 183 | + 'list_id' => '123', |
| 184 | +]; |
| 185 | + |
| 186 | +$response = Sendy::subscribers()->count( |
| 187 | + listId: '123', |
| 188 | + async: false |
| 189 | + ); |
| 190 | + |
| 191 | +``` |
| 192 | + |
| 193 | +Full Documentation [Here](https://sendy.co/api#active-subscriber-count) |
| 194 | + |
| 195 | +### Lists |
| 196 | + |
| 197 | +Same thing as the __subscribers__ service, you can access the `lists()` service, then the http action you want. |
| 198 | + |
| 199 | +#### Get Lists |
| 200 | + |
| 201 | +```php |
| 202 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 203 | + |
| 204 | +$data = [ |
| 205 | + 'brand_id' => '123', |
| 206 | + 'include_hidden' => 'yes', // either yes or no. |
| 207 | +]; |
| 208 | + |
| 209 | +$response = Sendy::lists()->get( |
| 210 | + data: $data, |
| 211 | + async: false |
| 212 | + ); |
| 213 | + |
| 214 | +``` |
| 215 | +Full Documentation [Here](https://sendy.co/api#get-lists) |
| 216 | + |
| 217 | +### Brands |
| 218 | + |
| 219 | +__Laravel Sendy__ allows you to retrieve all the brand list you have by |
| 220 | + |
| 221 | +```php |
| 222 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 223 | + |
| 224 | +$response = Sendy::brands()->get(); |
| 225 | + |
| 226 | +``` |
| 227 | + |
| 228 | +Full Documentation [Here](https://sendy.co/api#get-brands) |
| 229 | + |
| 230 | +### Create & Send Compaigns |
| 231 | + |
| 232 | +```php |
| 233 | +use Coderflex\LaravelSendy\Facades\Sendy; |
| 234 | + |
| 235 | +$data = [ |
| 236 | + 'subject' => 'Test Subject', |
| 237 | + 'from_name' => 'John Doe', |
| 238 | + 'from_email' => ' [email protected]', |
| 239 | + 'reply_to' => ' [email protected]', |
| 240 | + 'title' => 'Test Title', |
| 241 | + 'plain_text' => 'This is a plain text version of the email.', |
| 242 | + 'html_text' => '<h1>This is a HTML version of the email.</h1>', |
| 243 | + 'list_ids' => 'abc123', |
| 244 | + 'segment_ids' => 'xyz456', |
| 245 | + 'exclude_list_ids' => null, |
| 246 | + 'exclude_segment_ids' => null, |
| 247 | + 'brand_id' => '123', |
| 248 | + 'query_string' => null, |
| 249 | + 'track_opens' => 1, |
| 250 | + 'track_clicks' => 1, |
| 251 | + 'send_campaign' => 1, // if set to 1 the compaign will be created & sent. |
| 252 | + 'schedule_date_time' => null, |
| 253 | + 'schedule_timezone' => null, |
| 254 | +]; |
| 255 | + |
| 256 | +$response = Sendy::compaigns()->create( |
| 257 | + data: $data, |
| 258 | + async: false |
| 259 | + ); |
| 260 | + |
| 261 | +``` |
| 262 | + |
| 263 | +If you want to create and send the compaign at the same time, use `createAndSend` method |
| 264 | + |
| 265 | +```php |
| 266 | + |
| 267 | +$response = Sendy::compaigns()->createAndSend( |
| 268 | + data: $data, |
| 269 | + async: false |
| 270 | + ); |
| 271 | +``` |
| 272 | + |
| 273 | +Full Documentation [Here](https://sendy.co/api#create-send-campaigns) |
| 274 | + |
| 275 | +## Testing |
| 276 | + |
| 277 | +```bash |
| 278 | +composer test |
| 279 | +``` |
| 280 | + |
| 281 | +## Changelog |
| 282 | + |
| 283 | +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 284 | + |
| 285 | +## Contributing |
| 286 | + |
| 287 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 288 | + |
| 289 | +## Security Vulnerabilities |
| 290 | + |
| 291 | +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. |
| 292 | + |
| 293 | +## Credits |
| 294 | + |
| 295 | +- [Oussama Sid](https://github.com/ousid) |
| 296 | +- [All Contributors](../../contributors) |
| 297 | + |
| 298 | +## License |
| 299 | + |
| 300 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments