mailingreport/mailingreport-php

此包已被废弃,不再维护。未建议替代包。

PHP官方MailingReport库

2.2.0 2016-10-21 15:54 UTC

This package is not auto-updated.

Last update: 2021-02-12 12:03:33 UTC


README

Latest Stable Version Build Status

这是MailingReport API的官方PHP客户端。有关MailingReport API的更多信息、文档、集成、插件等,请访问开发者专属网站:https://fr.mailingreport.com/api/

安装

建议通过composer安装MailingReport API。

{
    "require": {
        "mailingreport/mailingreport-php": "@stable"
    }
}

使用

创建API客户端

您可以在MailingReport账户的“设置”部分“API密钥”中找到这些凭据。

$api = \Mgrt\Client::factory(array(
    'public_key' => 'your_public_key',
    'private_key' => 'your_private_key',
));

以下是可用的设置列表。有关更多选项,请参阅Guzzle手册。

  • public_key : 您的API密钥
  • private_key : 您的API密钥

检索集合

检索集合时,您将获得一个ResultCollection类。您可以获取当前页、限制和全局集合中的元素总数。

$contacts = $api->getContacts();

$contacts->getPage(); // 1
$contacts->getLimit(); // 50
$contacts->getTotal(); // 250 for example

您还可以在检索集合时设置参数。

$contacts = $contacts->getContacts(array(
    'page'      => 2,
    'limit'     => 10,
    'sort'      => 'createdAt',
    'direction' => 'asc',
));

$contacts->getPage(); // 2
$contacts->getLimit(); // 10
$contacts->getTotal(); // 250 for example

使用ResultCollection可以遍历集合。

foreach ($contacts as $contact) {
    echo $contact->getId(); // 1 for example
}

创建条目

您可以通过使用默认构造函数并逐个设置字段来创建一个新对象。

$custom_field = new \Mgrt\Model\CustomField();
$custom_field
    ->setId(42);
    ->setValue('the answer to life the universe and everything');
$contact = new \Mgrt\Model\Contact();
$contact
    ->setEmail('somebody@example.com');
    ->setCustomFields(array(
        $custom_field
    ));

或者,您可以使用PHP数组结构来定义新对象

$contact = new \Mgrt\Model\Contact();
$contact->fromArray(array(
    'email'         => 'somebody@example.com',
    'custom_fields' => array(
        'id'    => 42,
        'value' => 'the answer to life the universe and everything'
    )
));

账户

可用的API方法

  • $api->getAccount() 将返回一个Account对象。

Account对象上的可用方法

  • $account->getId() 将返回一个integer
  • $account->getCompany() 将返回一个string
  • $account->getAddressStreet() 将返回一个string
  • $account->getAddressCity() 将返回一个string
  • $account->getAddressZipcode() 将返回一个string
  • $account->getAddressCountry() 将返回一个string
  • $account->getCurrency() 将返回一个string
  • $account->getTimezone() 将返回一个string
  • $account->getCredits() 将返回一个integer
  • $account->getPlanType() 将返回一个string

API密钥

可用的API方法

  • $api->getApiKeys() 将返回一个包含ApiKey集合的ResultCollection
  • $api->getApiKey($apiKeyId) 将返回一个ApiKey对象。
  • $api->createApiKey(ApiKey $apiKey) 将返回一个ApiKey对象。
  • $api->updateApiKey(ApiKey $apiKey) 将返回一个boolean
  • $api->deleteApiKey(ApiKey $apiKey) 将返回一个boolean
  • $api->disableApiKey(ApiKey $apiKey) 将返回一个boolean
  • $api->enableApiKey(ApiKey $apiKey) 将返回一个boolean

ApiKeys对象上的可用方法

获取器

  • $apiKey->getId() 将返回一个integer
  • $apiKey->getName() 将返回一个string
  • $apiKey->getPublicKey() 将返回一个string
  • $apiKey->getPrivateKey() 将返回一个string
  • $apiKey->getEnabled() 将返回一个boolean
  • $apiKey->getCreatedAt() 将返回一个 DateTime
  • $apiKey->getDisabledAt() 将返回一个 DateTime

设置器

  • $apiKey->setName($name) 其中 $name 是一个 string

活动

可用的API方法

  • $api->getCampaigns() 将返回一个包含活动集合的 ResultCollection
  • $api->getCampaign($contactId) 将返回一个 Campaign 对象。
  • $api->createCampaign(Campaign $campaign) 将返回一个 Campaign 对象。
  • $api->updateCampaign(Campaign $campaign) 将返回一个 boolean
  • $api->deleteCampaign(Campaign $campaign) 将返回一个 boolean
  • $api->scheduleCampaign(Campaign $campaign) 将返回一个 boolean
  • $api->unscheduleCampaign(Campaign $campaign) 将返回一个 boolean
  • $api->summaryCampaign(Campaign $campaign) 将返回一个 CampaignSummary 对象。

Campaign 对象上的可用方法

获取器

  • $campaign->getId() 将返回一个 integer
  • $campaign->getName() 将返回一个 string
  • $campaign->getMailingLists() 将返回一个包含 MailingList 对象的数组。
  • $campaign->getSegments() 将返回一个包含 Segment 对象的数组。
  • $campaign->getSubject() 将返回一个 string
  • $campaign->getBody() 将返回一个 string
  • $campaign->getFromMail() 将返回一个 string
  • $campaign->getFromName() 将返回一个 string
  • $campaign->getReplyMail() 将返回一个 string
  • $campaign->getCreatedAt() 将返回一个 DateTime
  • $campaign->getUpdatedAt() 将返回一个 DateTime
  • $campaign->getScheduledAt() 将返回一个 DateTime
  • $campaign->getSentAt() 将返回一个 DateTime
  • $campaign->getTrackingEndsAt() 将返回一个 DateTime
  • $campaign->getStatus() 将返回一个 string
  • $campaign->getIsPublic() 将返回一个 boolean
  • $campaign->getShareUrl() 将返回一个 string

设置器

  • $campaign->setName($name) 其中 $name 是一个 string
  • $campaign->setMailingLists($mailingLists) 其中 $mailingLists 是一个包含 MailingLists 对象的数组。
  • $campaign->setSegments($segments) 其中 $segments 是一个包含 Segments 对象的数组。
  • $campaign->setSubject($subject) 其中 $subject 是一个 string
  • $campaign->setBody($body) 其中 $body 是一个 string
  • $campaign->setFromMail($fromMail) 其中 $fromMail 是一个 string
  • $campaign->setFromName($fromName) 其中 $fromName 是一个 string
  • $campaign->setReplyMail($replyMail) 其中 $replyMail 是一个 string

联系人

可用的API方法

  • $api->getContacts() 将返回一个包含联系人集合的 ResultCollection
  • $api->getContact($contactId) 将返回一个 Contact 对象。
  • $api->getContact($contactEmail) 将返回一个 Contact 对象。
  • $api->createContact(Contact $contact) 将返回一个 Contact 对象。
  • $api->updateContact(Contact $contact) 将返回一个 boolean
  • $api->deleteContact(Contact $contact) 将返回一个 boolean
  • $api->unsubscribeContact(Contact $contact) 将返回一个 boolean
  • $api->resubscribeContact(Contact $contact) 将返回一个 boolean

Contact 对象上的可用方法

获取器

  • $contact->getId() 将返回一个 integer
  • $contact->getEmail() 将返回一个 string
  • $contact->getMailingLists() 将返回一个包含 MailingList 对象的数组。
  • $contact->getMailingListsToArray() 将返回一个包含 integer 的数组。
  • $contact->getCustomFields() 将返回一个 CustomField 对象数组。
  • $contact->getCustomFieldsToArray() 将返回一个格式为 {id, value} 的 CustomFields 数组。
  • $contact->getLatitude() 将返回一个 string
  • $contact->getLongitude() 将返回一个 string
  • $contact->getCountryCode() 将返回一个 string
  • $contact->getTimeZone() 将返回一个 string
  • $contact->getCreatedAt() 将返回一个 DateTime
  • $contact->getUpdatedAt() 将返回一个 DateTime

设置器

  • $contact->setEmail($email) 其中 $email 是一个 string
  • $contact->setMailingLists($mailingList) 其中 $mailingList 是一个 MailingList 对象数组。
  • $contact->setCustomFields($customFields) 其中 $customFields 是一个 CustomField 对象数组。

其他方法

  • $contact->addMailingLists($mailingList) 其中 $mailingList 是一个 MailingList 对象数组。
  • $contact->removeMailingLists($mailingList) 其中 $mailingList 是一个 MailingList 对象数组。
  • $contact->addMailingList($mailingList) 其中 $mailingList 是一个 MailingList 对象。
  • $contact->removeMailingList($mailingList) 其中 $mailingList 是一个 MailingList 对象。
  • $contact->addCustomFields($customFields) 其中 $customFields 是一个 CustomField 对象数组。
  • $contact->removeCustomFields($customFields) 其中 $customFields 是一个 CustomField 对象数组。
  • $contact->addCustomField($customFields) 其中 $customFields 是一个 CustomField 对象。
  • $contact->removeCustomField($customFields) 其中 $customFields 是一个 CustomField 对象。

自定义字段

自定义字段不能通过 API 创建或更新

可用的API方法

  • $api->getCustomFields() 将返回一个包含 CustomField 集合的 ResultCollection

CustomField 对象上可用的方法

  • $customField->getId() 将返回一个 integer
  • $customField->getName() 将返回一个 string
  • $customField->getFieldType() 将返回一个 string
  • $customField->getValue() 将返回一个 string
  • $customField->getChoices() 将返回一个 string 数组。

域名

域名不能通过 API 创建或更新

可用的API方法

  • $api->getDomains() 将返回一个包含 Domain 集合的 ResultCollection
  • $api->getDomain($domainId) 将返回一个 Domain 对象。
  • $api->checkDomain(Domain $domain) 将返回一个 Domain 对象。

Domain 对象上可用的方法

  • $domain->getId() 将返回一个 integer
  • $domain->getDomainName() 将返回一个 string
  • $domain->getCheckedAt() 将返回一个 DateTime
  • $domain->getSpfFqdn() 将返回一个 string
  • $domain->getSpfStatus() 将返回一个 integer
  • $domain->getDkimFqdn() 将返回一个 string
  • $domain->getDkimStatus() 将返回一个 integer
  • $domain->getPublicKey() 将返回一个 string

发票

发票不能通过 API 创建或更新

可用的API方法

  • $api->getInvoices() 将返回一个包含 Invoice 集合的 ResultCollection
  • $api->getInvoice($invoiceId) 将返回一个 Invoice 对象。

Invoice 对象上可用的方法

  • $invoice->getId() 将返回一个 integer
  • $invoice->getNumber() 将返回一个 string
  • $invoice->getNetAmount() 将返回一个 float
  • $invoice->getTaxAmount() 将返回一个 float
  • $invoice->getTotalAmount() 将返回一个 float
  • $invoice->getDueAt() 将返回一个 DateTime
  • $invoice->getPaidAt() 将返回一个 DateTime
  • $invoice->getInvoiceLines() 将返回一个包含 InvoiceLine 对象的数组。

InvoiceLine 对象上的可用方法

  • $invoiceLine->getId() 将返回一个 integer
  • $invoiceLine->getTitle() 将返回一个 string
  • $invoiceLine->getDescription() 将返回一个 string
  • $invoiceLine->getQuantity() 将返回一个 float
  • $invoiceLine->getPrice() 将返回一个 float

邮件列表

可用的API方法

  • $api->getMailingLists() 将返回一个包含 MailingList 集合的 ResultCollection
  • $api->getMailingList($mailingListId) 将返回一个 MailingList 对象。
  • $api->createMailingList(MailingList $mailingList) 将返回一个 MailingList 对象。
  • $api->updateMailingList(MailingList $mailingList) 将返回一个 boolean
  • $api->deleteMailingList(MailingList $mailingList) 将返回一个 boolean
  • $api->getMailingListContacts(MailingList $mailingList) 将返回一个包含 Contact 集合的 ResultCollection

MailingList 对象上的可用方法

获取器

  • $mailingList->getId() 将返回一个 integer
  • $mailingList->getName() 将返回一个 string
  • $mailingList->getCreatedAt() 将返回一个 DateTime
  • $mailingList->getUpdatedAt() 将返回一个 DateTime

设置器

  • $mailingList->setName($name) 其中 $name 是一个 string

发送者

发送者不能通过 API 创建或更新

可用的API方法

  • $api->getSenders() 将返回一个包含 Sender 集合的 ResultCollection
  • $api->getSender($senderId) 将返回一个 Sender 对象。
  • $api->deleteSender(Sender $sender) 将返回一个 boolean

Sender 对象上的可用方法

  • $sender->getId() 将返回一个 integer
  • $sender->getEmail() 将返回一个 string
  • $sender->getEmailType() 将返回一个 string
  • $sender->getIsEnabled() 将返回一个 boolean

模板

可用的API方法

  • $api->getTemplates() 将返回一个包含 Template 集合的 ResultCollection
  • $api->getTemplate($templateId) 将返回一个 Template 对象。
  • $api->createTemplate(Template $template) 将返回一个 Template 对象。
  • $api->deleteTemplate(Template $template) 将返回一个 boolean
  • $api->updateTemplate(Template $template) 将返回一个 boolean

Template 对象上的可用方法

获取器

  • $template->getId() 将返回一个 integer
  • $template->getName() 将返回一个 string
  • $template->getBody() 将返回一个 DateTime

设置器

  • $campaign->setName($name) 其中 $name 是一个 string
  • $template->setBody($body) 其中 $body 是一个 string

单元测试

要运行单元测试,您需要一组可以使用 Composer 安装的依赖项

安装后,只需启动以下命令

phpunit

将 phpunit.xml.dist 文件重命名为 phpunit.xml,然后取消注释以下行并添加您自己的 API 密钥

<php>
    <!-- <server name="PUBLIC_KEY" value="your_public_key" /> -->
    <!-- <server name="PRIVATE_KEY" value="your_private_key" /> -->
</php>

完成。

更多信息

致谢

非常感谢所有贡献者

许可证

本软件在MIT许可证下发布。请参阅附带LICENSE文件以获取详细信息。