mmollick/drip-php

Community supported library for Drip.com's API

v0.1.1 2018-02-13 15:32 UTC

This package is auto-updated.

Last update: 2024-11-11 04:41:33 UTC


README

Build Status

Requirements

  • PHP 5.6 or greater
  • PHP JSON extension
  • PHP cURL extension

Installation

Composer Installation

Run the following command in the terminal:

composer require mmollick/drip-php

Or add the following to your composer.json file:

{
  "require": {
    "mmollick/drip-php":"~0.1.0"
  }
}

Manual Installation

This package conforms to the PSR-4 autoloading standard. To include it in your project we recommend using composer, however you can use your own PSR-4 autoloader or manually load all the files contained in the src directory to load this library.

Usage

This package allows you use it in both an object-oriented or singleton approach depending on your preferences. All authentication and request methods are available with either approach.

Initialization as Singleton

Specify your authentication credentials with either the setTokenCredentials or setOAuthAccessToken static methods on the Drip class.

// Authenticating w/ API key
\MMollick\Drip\Drip::setTokenCredentials($accountId, $api_key)

// Authenticating w/ OAuth access_token
\MMollick\Drip\Drip::setOAuthAccessToken($accountId, $access_token)

Initialization as Object

Using the object-oriented approach allows you to create multiple isolated instances of the Drip API. To do this first create new a \MMollick\Drip\Auth object and pass this into a new \MMollick\Drip\Request object.

// 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);

Error Handling

This library will throw one of several exceptions when an error occurs either with the Request or the package itself. It's recommended that requests are made within in a try...catch block to properly handle errors as they arise. See the example below.

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
}

Methods

All of the request methods can be accessed statically from the \MMollick\Drip\Drip class or by calling them from the \MMollick\Drip\Request object.

Account
Broadcasts
Campaigns
Campaign Subscriptions
Conversions
Custom Fields
Events
Forms
Purchases
Subscribers
Tags
Webhooks
Workflows
Workflow Triggers

Contributing

  1. Fork it ( https://github.com/mmollick/drip-php/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
    • Add tests when relevant
    • If you add a new method to the Request class or the Request traits be sure to include the static declaration in Drip.php's phpdoc
  4. Push to the branch (git push origin my-new-feature)
    • Fix linting issues Code-Climate Identifies
  5. Create a new Pull Request

Support

This package is open-source and maintained by the community. Drip does not directly participate in the maintenance of this package. Any issues with this package should be addressed by opening a new issue.