karacweb / infomaniak-newsletter
Implementation of the Infomaniak's newsletter service for Laravel
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
- karacweb/client-api-newsletter: ~2.0
Requires (Dev)
- mockery/mockery: ^1.4.4
- nunomaduro/phpinsights: ^2.6
- phpunit/phpunit: ^9.5.10
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Infomaniak Newsletter for Laravel helps you interact with Infomaniak's API.
Installation
Install the package through Composer.
Run the Composer require command from the terminal:
composer require karacweb/infomaniak-newsletter
Publish the configuration using the following command:
php artisan vendor:publish --provider="Karacweb\InfomaniakNewsletter\ServiceProvider"
Configuration
Set your env keys and list(s) id(s) in config/infomaniak-newsletter.php.
return [ /* * The API keys of an Infomaniak newsletter account. You can find yours at * https://newsletter.infomaniak.com/accounts/access-token */ 'apiKey' => env('INFOMANIAK_APIKEY'), 'secretKey' => env('INFOMANIAK_SECRETKEY'), /* * The listName to use when no listName has been specified in a method. */ 'defaultListName' => 'subscribers', /* * Here you can define properties of the lists. */ 'lists' => [ /* * This key is used to identify this list. It can be used * as the listName parameter provided in the various methods. * * You can set it to any string you want and you can add * as many lists as you want. */ 'subscribers' => [ /* * Id of a newsletter contact list. You can retrieve it * by looking at the last characters of the list's URL : * https://newsletter.infomaniak.com/mailinglists/show/XXXXX */ 'id' => env('INFOMANIAK_LISTID'), ], ], ];
Usage
NewsletterInfomaniak::importContact()
Subscribe an email address to the default list.
use InfomaniakNewsletter; InfomaniakNewsletter::importContact("email@example.com");
Provide a firstname and a lastname as an optional parameter.
InfomaniakNewsletter::importContact("email@example.com", ["firstname" => "John", "lastname" => "Doe"]);
Finally, choose the list to add the email to as a third parameter.
InfomaniakNewsletter::importContact("email@example.com", [], "subscribers");
NewsletterInfomaniak::isSubscribed()
Check if the email is subscribed to the default list.
InfomaniakNewsletter::isSubscribed("email@example.com");
Check if the email is subscribed in the subscribers list.
InfomaniakNewsletter::isSubscribed("email@example.com", "subscribers");
NewsletterInfomaniak::unsubscribeContact()
Unsubscribe an email from the default list. The contact is not deleted, only its status change.
InfomaniakNewsletter::unsubscribeContact("email@example.com");
Unsubscribe an email from the subscribers list.
InfomaniakNewsletter::unsubscribeContact("email@example.com", "subscribers");
NewsletterInfomaniak::deleteContact()
Remove an email from the default list.
InfomaniakNewsletter::deleteContact("email@example.com");
Remove an email from the subscribers list
InfomaniakNewsletter::deleteContact("email@example.com", "subscribers");
NewsletterInfomaniak::getContact()
Get the data regarding a contact.
InfomaniakNewsletter::getContact("email@example.com");
NewsletterInfomaniak::getContacts()
Get the contacts from the default list. The result is paginated.
InfomaniakNewsletter::getContacts();
Get the contacts from the subscribers list.
InfomaniakNewsletter::getContacts("subscribers");
Get the contact from the subscribers list with specified pagination options.
InfomaniakNewsletter::getContacts("subscribers", ["page" => 2, "perPage" => 50]);
NewsletterInfomaniak::updateContact()
Update the firstname of a contact. This updates the contacts in all the mailing lists of the account.
InfomaniakNewsletter::updateContact("email@example.com", ["firstname" => "Joe"]);
You can provide a lastname too.
InfomaniakNewsletter::updateContact("email@example.com", ["firstname" => "Joe", "lastname" => "Donovan"]);
NewsletterInfomaniak::getMailinglists()
Get the account's mailing lists. The result is paginated.
InfomaniakNewsletter::getMailinglists();
Get the account's mailing lists with specified pagination options.
InfomaniakNewsletter::getMailinglists(["page" => 1, "perPage" => 50]);
NewsletterInfomaniak::getMailinglist()
Get the information of the default list.
InfomaniakNewsletter::getMailinglist();
Get the information of the subscribers list.
InfomaniakNewsletter::getMailinglist("subscribers");
NewsletterInfomaniak::createMailinglist()
Create the subscribers_fr mailing list.
InfomaniakNewsletter::createMailinglist("subscribers_fr");
NewsletterInfomaniak::updateMailinglist()
Rename the subscribers_fr mailing list to subscribers_french.
InfomaniakNewsletter::updateMailinglist("subscribers_fr", "subscribers_french");
NewsletterInfomaniak::deleteMailinglist()
Delete the default list.
InfomaniakNewsletter::deleteMailinglist();
Delete the subscribers_french mailing list.
InfomaniakNewsletter::deleteMailinglist("subscribers_french");
NewsletterInfomaniak::getTask()
Get information about the task 123456.
InfomaniakNewsletter::getTask(123456);