fa-land/mailup-rest-client

非官方MailUp Rest客户端

dev-master / 1.0.x-dev 2020-01-14 10:56 UTC

This package is auto-updated.

Last update: 2024-09-14 21:26:09 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

Fazland的MailUp Rest Client是一个非官方的PHP Rest客户端,用于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文件