O cliente REST da Fazland é um cliente REST PHP não oficial para o email e o SMS GatewayProvider MailUp.
O método de instalação sugerido é via compositor:
$ composer require fazland/mailup-rest-clientÉ realmente simples. Primeiro de tudo, configuração!
Os parâmetros de configuração obrigatórios são:
usernamepasswordclient_idclient_secret O único parâmetro opcional é cache_dir . Se definido, o token de acesso é salvo nesse caminho.
Basta criar um objeto Context que passa ao construtor os parâmetros como uma matriz:
use Fazland MailUpRestClient Context ;
$ config = [
' username ' => ' your_username ' ,
' password ' => ' your_password ' ,
' client_id ' => ' your_client_id ' ,
' client_secret ' => ' your_client_secret ' ,
' cache_dir ' => ' path_to_your_cache_dir ' , // Optional
];
$ httpClient = new HttpClientImplementation ();
$ context = new Context ( $ config , $ httpClient ); Para criar uma MailingList você pode seguir este exemplo. Consulte os documentos da API oficial do MailUp para obter a matriz $params .
use Fazland MailUpRestClient MailingList ;
$ email = " [email protected] " ;
$ listName = " list_name " ;
$ params = [
// your params...
];
$ list = MailingList:: create ( $ context , $ listName , $ email , $ params ); Você também pode obter todas as listas existentes em sua conta de e -mail chamando o método estático MailingList::getAll() :
use Fazland MailUpRestClient MailingList ;
$ lists = MailingList:: getAll ( $ context ); Depois de ter uma instância da MailingList , você pode fazer as seguintes operações:
Recipient use Fazland MailUpRestClient Recipient ;
$ list -> addRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3333333333 ' , ' +39 ' ));Recipient use Fazland MailUpRestClient Recipient ;
$ list -> updateRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3334444444 ' , ' +39 ' ));Recipient use Fazland MailUpRestClient Recipient ;
$ list -> removeRecipient ( new Recipient ( ' Aragorn ' , ' [email protected] ' , ' 3333333333 ' , ' +39 ' ));Recipient por seu email $ recipient = $ list -> findRecipient ( ' [email protected] ' ); // null returned if current email was not found $ groups = $ list -> getGroups (); $ countRecipients = $ list -> countRecipients (); // equal to $list->countRecipients(Recipient::STATUS_SUBSCRIBED);
// OR
$ countRecipients = $ list -> countRecipients (Recipient:: STATUS_UNSUBSCRIBED );
// OR
$ countRecipients = $ list -> countRecipients (Recipient:: STATUS_PENDING ); $ recipients = $ list -> getRecipientsPaginated ( $ pageNumber , $ pageSize );Recipient : $ list -> import ( $ recipients ); Cada MailingList pode ser dividida em vários grupos. As operações disponíveis são as seguintes:
$ group -> getName ();
$ group -> setName ( ' Gondor Army ' ); $ group -> getNotes ();
$ group -> setNotes ( ' 10.000 knights and 20.000 peons ' ); $ group -> isDeletable ();
$ group -> setDeletable ( true ); $ group -> delete (); use Fazland MailUpRestClient Recipient ;
$ legolas = new Recipient ( ' Legolas Thranduilion ' , ' [email protected] ' , ' 3334444444 ' , ' +39 ' );
$ group -> addRecipient ( $ legolas );
$ group -> removeRecipient ( $ legolas );
$ lothlorienCitizens = $ group -> getRecipients ();Contribuições são bem -vindas. Sinta -se à vontade para abrir um PR ou apresentar um problema aqui no Github!
O cliente REST do MailUp está licenciado sob a licença do MIT - consulte o arquivo de licença para obter detalhes