richardhj/newsletter2go-api
Composer 安装命令:
composer require richardhj/newsletter2go-api
包简介
Model based Newsletter2Go API implementation
关键字:
README 文档
README
This package provides a model based implementation of the Newsletter2Go API. It aims to make complex documentations unnecessary. With its clear structure and extensive PHPDoc, it is really easy to use.
Install
Via Composer
$ composer require richardhj/newsletter2go-api
Usage
Fetch and alter
If you want to fetch items via the API there might be a static function for. Example:
$users = Richardhj\Newsletter2Go\Api\Model\NewsletterUser::findAll(null, $apiCredentials); // Use a PHPDoc comment and profit from auto suggestion /** @var NewsletterUser $user */ foreach ($users as $user) { // What's about naming all users "Doe"? $user->setLastName('Doe'); // Save the user (via the API of course) $user->save(); // $data contains all data fetched for this item $data = $user->getData(); }
$recipients = Richardhj\Newsletter2Go\Api\Model\NewsletterRecipient::findByListAndGroup('abc123', 'xyz987', null, $apiCredentials); var_dump($recipients); foreach ($recipients as $recipient) { $recipient->addToGroup('xyz345'); $recipient->removeFromGroup('asdf12'); }
Api Credentials
ApiCredentials are mandatory for the api communication. First of all you need the auth_key that can be found
in the Newsletter2Go back end. The auth_key is the same for all company's accounts.
Furthermore you either need a user's username and password or a user's refresh_token.
If you rather want to use and save the refresh_token instead of username and password in your application, you
have to make an initial api authorization call with the username and password anyway. Check the
manual of the corresponding OAuth provider to
get to know how to fetch a refresh_token.
// Use the ApiCredentialsFactory $apiCredentials = ApiCredentialsFactory::createFromUsernameAndPassword('secret_auth_token', 'user@example.org', 'open_sesame'); $apiCredentials = ApiCredentialsFactory::createFromRefreshToken('secret_auth_token', 'secret_users_refresh_token'); // Or simply use ::create() $apiCredentials = ApiCredentialsFactory::create('secret_auth_token', 'secret_users_refresh_token');
Get parameters
When fetching a collection from the api, you can provide a GetParamters instance. Get parameters allow you to
filter, limit etc. the item collection that will be returned. Example:
$getParams = new Richardhj\Newsletter2Go\Api\Tool\GetParameters(); $getParams ->setExpand(true) ->setFilter('email=like="%@example.org"') ->setOffset(2) ->setLimit(1); $recipients = Richardhj\Newsletter2Go\Api\Model\NewsletterRecipient::findByListAndGroup('abc123', 'xyz987', $getParams, $apiCredentials); var_dump($recipients);
Create
If you want to create items via the API, this is how. Example:
$recipient = new Richardhj\Newsletter2Go\Api\Model\NewsletterRecipient(); $recipient->setApiCredentials($apiCredentials); $recipient ->setListId('abc123') ->setFirstName('John') ->setLastName('Doe') ->setEmail('doe@example.org') ->setGender('m'); // Good to have an id, otherwise the email address will be the primary key and you will not be able to change the email address of a recipient properly $recipient->setId('xyz123'); // Update an existing recipient (when id given or email address known in Newsletter2Go) or create a new recipient $recipient->save();
Delete
For models that implement Newsletter2Go\Api\Model\ModelDeletableInterface, delete() is available. Example:
$groups = Newsletter2Go\Api\Model\NewsletterGroup::findByList('abc123', $getParams, $credentials); /** @var NewsletterGroup $group */ foreach ($groups as $group) { $group->delete(); }
Official API documentation
Visit the official API documentation for reference.
License
The GNU Lesser General Public License (LGPL).
richardhj/newsletter2go-api 适用场景与选型建议
richardhj/newsletter2go-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.6k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「newsletter2go」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 richardhj/newsletter2go-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 richardhj/newsletter2go-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 richardhj/newsletter2go-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP API implementation of the Newsletter2Go REST API (https://docs.newsletter2go.com/)
A PSR-7 compatible library for making CRUD API endpoints
Newsletter2Go OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A LUYA library for newsletter2go service.
Synchronize recipients between Contao and Newsletter2Go
A lightweight plain-PHP framework for database-backed CRUD APIs.
统计信息
- 总下载量: 1.6k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2016-08-22