list-interop / convertkit-client
ConvertKit的API客户端
0.4.0
2023-06-29 14:42 UTC
Requires
- php: ~8.1 || ~8.2
- ext-json: *
- fig/http-message-util: ^1.1
- myclabs/php-enum: ^1.8
- php-http/discovery: ^1.14.3
- psr/container: ^1 || ^2
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-message: ^1.1 || ^2.0
- webmozart/assert: ^1.11
Requires (Dev)
- ext-curl: *
- doctrine/coding-standard: ^12.0
- ergebnis/composer-normalize: ^2.31
- laminas/laminas-diactoros: ^3.0.0
- php-http/curl-client: ^2.3
- phpunit/phpunit: ^10.2.2
- psalm/plugin-phpunit: ^0.18.4
- react/child-process: ^0.6.5
- react/http: ^1.9
- roave/security-advisories: dev-latest
- vimeo/psalm: ^5.13.1
Provides
Conflicts
- symfony/options-resolver: <5.3.7
This package is auto-updated.
Last update: 2024-09-15 17:09:01 UTC
README
简介
这是一个适用于PHP 8.0及以上版本的ConvertKit邮件列表服务的API客户端
在Packagist上可找到几个客户端,但此处的主要动机是对所使用的HTTP客户端无依赖。
客户端使用PSR17和18标准,因此您可以携带自己的首选库。
实现的功能
- 通过ID检索表单
- 订阅表单 (自定义字段尚不可用)
- 列出和查找标签
- 创建标签
- 列出自定义字段
- 自定义字段的CRUD操作
- 获取表单订阅者
- 其他订阅者CRUD操作
- 订阅后标记订阅者。
- 关于webhooks和购买的内容…
路线图
很愿意实现API中其余的功能,但这可能不会很快发生,我更可能先专注于不同的实现来确立规范,以便能够发布稳定版本。对于API中很少改变的部分,使用psr cache pool发布一个缓存客户端将很有用。这也很容易实现。
安装
Composer是唯一支持的安装方法…
如前所述,您首先需要一个PSR-18 HTTP客户端,以及PSR-7和PSR-17的实现。例如
composer require php-http/curl-client composer require laminas/laminas-diactoros
然后您可以使用以下命令安装此软件包
composer require list-interop/convertkit-client
使用方法
文档确实很少。
库包含一个PSR11工厂,您可以使用您选择的容器进行集成。它会回退到发现以处理您安装的任何PSR-7/17/18内容。
最终,您需要API密钥才能开始,假设您可以为构造函数提供所需的依赖项,您就可以开始发布命令并获取结果
添加订阅者…
use ListInterop\ConvertKit\Client; use ListInterop\ConvertKit\Exception\ApiError; use ListInterop\ConvertKit\Exception\ConvertKitError; use ListInterop\ConvertKit\Exception\RequestFailure; assert($client instanceof Client); $formId = 123; // Retrieve this from the dashboard or by inspecting the forms returned by the api. try { $client->subscribeToForm($formId, 'me@example.com', 'Fred', ['tag 1', 'tag 2']); } catch (RequestFailure $error) { // Network error - can't reach ConvertKit } catch (ApiError $error) { // Something was wrong with the values provided, or your API key was wonky // i.e. The API rejected your request } catch (ConvertKitError $error) { // Generic Error, Assertion failed etc. // All exceptions implement this interface, Providing an invalid email address will get you here. }
您应该会发现异常是一致的并且有意义的,但为了现在了解这些异常,您需要查看源代码。
贡献
非常欢迎,但请确保拉取请求包含相关测试。您可以在本地运行一个方便的Composer脚本
composer check
…它将检查编码标准,并依次运行psalm和phpunit。