mmollick / drip-php
Drip.com API 的社区支持库
v0.1.1
2018-02-13 15:32 UTC
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is auto-updated.
Last update: 2024-09-11 04:23:05 UTC
README
需求
- PHP 5.6 或更高版本
- PHP JSON 扩展
- PHP cURL 扩展
安装
Composer 安装
在终端中运行以下命令
composer require mmollick/drip-php
或者在您的 composer.json
文件中添加以下内容
{ "require": { "mmollick/drip-php":"~0.1.0" } }
手动安装
此包符合 PSR-4 自动加载标准。为了将其包含到您的项目中,我们建议使用 composer,但是您也可以使用自己的 PSR-4 自动加载器或手动加载 src
目录中包含的所有文件来加载此库。
使用方法
此包允许您根据个人喜好以面向对象或单例模式使用它。两种方法都提供了所有身份验证和请求方法。
作为单例初始化
使用 Drip 类的 setTokenCredentials
或 setOAuthAccessToken
静态方法指定您的身份验证凭据。
// Authenticating w/ API key \MMollick\Drip\Drip::setTokenCredentials($accountId, $api_key) // Authenticating w/ OAuth access_token \MMollick\Drip\Drip::setOAuthAccessToken($accountId, $access_token)
作为对象初始化
使用面向对象的方法允许您创建多个隔离的 Drip API 实例。为此,首先创建一个新的 \MMollick\Drip\Auth
对象,并将其传递给一个新的 \MMollick\Drip\Request
对象。
// Authentication w/ API Key $auth = new \MMollick\Drip\Auth($account_id, $api_key); $drip = new \MMollick\Drip\Request($auth); // Authentication w/ OAuth access_token $authUsingOauth = new \MMollick\Drip\Auth($account_id, $access_token, true); $dripUsingOauth = new \MMollick\Drip\Request($authUsingOauth);
错误处理
当请求或包本身发生错误时,此库将抛出多个异常之一。建议在 try...catch
块中执行请求,以正确处理错误。请参阅下面的示例。
try { $drip->getSubscribers(); } catch (\MMollick\Drip\Errors\AuthException $e) { // Authentication failed, check API keys } catch (\MMollick\Drip\Errors\ValidationException $e) { //The request failed validation, see message or $e->getErrors() for more info } catch (\MMollick\Drip\Errors\ApiExceptions $e) { // Non-specific API error returned, see message or $e->getErrors() for more info } catch (\MMollick\Drip\Errors\RateLimitException $e) { // Requests are being throttled, try the request again in a while } catch (\MMollick\Drip\Errors\HttpClientException $e) { // Most likely a network or Curl related error, see the message for more details } catch (\MMollick\Drip\Errors\GeneralException $e) { // A generic exception, see message for details } catch (\Exception $e) { // Catch anything else just for good measure }
方法
所有请求方法都可以从 \MMollick\Drip\Drip
类静态访问,或者通过从 \MMollick\Drip\Request
对象调用它们。
账户
广播
活动
活动订阅
转化
自定义字段
事件
表单
购买
订阅者
标签
Webhooks
工作流程
工作流程触发器
贡献
- 分叉它 ( https://github.com/mmollick/drip-php/fork )
- 创建您的功能分支 (git checkout -b my-new-feature)
- 提交您的更改 (git commit -am '添加一些功能')
- 添加相关测试
- 如果您向 Request 类或 Request traits 添加了新方法,请确保在 Drip.php 的 phpdoc 中包含静态声明。
- 推送到分支 (git push origin my-new-feature)
- 修复 Code-Climate 识别的 linting 问题
- 创建一个新的拉取请求
支持
此包是开源的,并由社区维护。Drip 不会直接参与此包的维护。有关此包的任何问题应通过 新建问题 来解决。