lorenzofaresin / mailup-rest-client
非官方MailUp Rest Client
dev-master / 1.0.x-dev
2021-05-14 14:56 UTC
Requires
- php: >=7.0
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/message: ^1.0
- php-http/message-factory: ^1.0
- psr/http-message: ^1.0
- psr/http-message-implementation: ^1.0
- symfony/options-resolver: ^2.7|^3.0|^4.0|^5.0
Requires (Dev)
- guzzlehttp/psr7: ^1.0
- php-http/guzzle6-adapter: ^1.1.1
- php-mock/php-mock: ^1.0
- phpunit/phpunit: ^6.0.3
This package is not auto-updated.
Last update: 2024-09-28 07:37:18 UTC
README
Fazland的MailUp Rest Client是一个非官方的PHP Rest Client,用于Email和SMS网关服务提供商MailUp。
要求
- php >= 7.0
- php-http/client-implementation >= 1.0
- php-http/discovery >= 1.0
- php-http/message >= 1.0
- php-http/message-factory >= 1.0
- psr/http-message >= 1.0
- psr/http-message-implementation >= 1.0
- symfony/options-resolver >= 2.7
安装
建议使用composer进行安装。
$ composer require fazland/mailup-rest-client
使用MailUp Rest Client
非常简单。首先,进行配置!
配置
必需的配置参数有
用户名
密码
客户端ID
客户端密钥
唯一的可选参数是cache_dir
。如果设置,访问令牌将被保存在该路径。
只需创建一个Context
对象,将参数作为数组传递给构造函数
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);
邮件列表
要创建一个MailingList
,可以参考以下示例。请参阅MailUp官方API文档了解$params
数组。
use Fazland\MailUpRestClient\MailingList; $email = "owner_of_the_list@email.com"; $listName = "list_name"; $params = [ // your params... ]; $list = MailingList::create($context, $listName, $email, $params);
您还可以通过调用静态方法MailingList::getAll()
获取MailUp账户中的所有现有列表
use Fazland\MailUpRestClient\MailingList; $lists = MailingList::getAll($context);
一旦您有一个MailingList
的实例,您可以执行以下操作
- 添加一个
Recipient
use Fazland\MailUpRestClient\Recipient; $list->addRecipient(new Recipient('Aragorn', 'aragorn@gondor.com', '3333333333', '+39'));
- 更新一个
Recipient
use Fazland\MailUpRestClient\Recipient; $list->updateRecipient(new Recipient('Aragorn', 'aragorn@gondor.com', '3334444444', '+39'));
- 删除一个
Recipient
use Fazland\MailUpRestClient\Recipient; $list->removeRecipient(new Recipient('Aragorn', 'aragorn@gondor.com', '3333333333', '+39'));
- 通过其
email
找到Recipient
$recipient = $list->findRecipient('aragorn@gondor.com'); // 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);
- 分页获取收件人(您可以指定与MailingList::countRecipients()中使用的相同状态)
$recipients = $list->getRecipientsPaginated($pageNumber, $pageSize);
- 最后但并非最不重要的是,导入一组
Recipient
对象
$list->import($recipients);
组
每个MailingList
可以分成多个组。可用的操作如下
- 检索或修改其名称
$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', 'legolas@lothlorien.elf', '3334444444', '+39'); $group->addRecipient($legolas); $group->removeRecipient($legolas); $lothlorienCitizens = $group->getRecipients();
贡献
欢迎贡献。请随意在此GitHub上提交PR或报告问题!
许可
MailUp Rest Client受MIT许可协议的许可 - 有关详细信息,请参阅LICENSE文件。