2017 © Pedro Peláez
 

library drill

Mandrill API interface with no bells and whistles.

image

gajus/drill

Mandrill API interface with no bells and whistles.

  • Tuesday, January 26, 2016
  • by gajus
  • Repository
  • 2 Watchers
  • 6 Stars
  • 155 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Drill

Build Status Coverage Status Latest Stable Version License, (*1)

Mandrill API interface with no bells and whistles., (*2)

Drill Client implementation makes no assumptions about the underlying API schema or required parameters. However, it will throw an exception when you do not provide the required parameters based on the response. Therefore, it is not an abstraction that will prevent your code from braking if/when Mandrill API changes. It is used to interact with the API endpoint and handle errors. That said, Mandrill RESTful API implements versioning, which ought to prevent breaking code that is using Drill implementation when API changes occur., (*3)

The only provided method is api, (*4)

/**
 * @param string $key Mandrill API key.
 */
$drill = new \Gajus\Drill\Client('NlLdhX5FVKS55VBK1xPW_g');

/**
 * @see https://mandrillapp.com/api/docs/messages.JSON.html
 * @param string $path
 * @param array $parameters
 */
$response = $drill->api('messages/send', [
    'message' => [
        'text' => 'Test',
        'subject' => 'test',
        'from_email' => 'dummy@gajus.com',
        'to' => [
            ['email' => 'dummy@gajus.com']
        ],
    ]
]);

Mandrill response is converted to an associative array:, (*5)

array(1) {
  [0]=>
  array(4) {
    ["email"]=>
    string(15) "dummy@gajus.com"
    ["status"]=>
    string(4) "sent"
    ["_id"]=>
    string(32) "f65f65c266f74e2884344ccfff3bb337"
    ["reject_reason"]=>
    NULL
  }
}

Handling errors

Cases that can be caught before making a request to the API or rules that are enforced by Drill implementation, as opposed to the API spec, will throw Gajus\Drill\Exception\InvalidArgumentException., (*6)

All errors that occur during the runtime will result in Gajus\Drill\Exception\ErrorException., (*7)

Beware that errors returned from Mandrill API have inconsistent naming convention (CamelCase vs underscore, e.g. "UserError", "Invalid_Key"). Drill will cast all errors to CamelCase convention (e.g. "Invalid_Key" becomes "InvalidKeyException")., (*8)

$drill = new \Gajus\Drill\Client('fxBTBjWKxJ05K9MjkFak1A');

try {
  $response = $drill->api('messages/send', [
      'message' => [
          'text' => 'Test',
          'subject' => 'test',
          'from_email' => 'invalidemail',
          'to' => [
              ['email' => 'dummy@gajus.com']
          ],
      ]
  ]);
} catch (\Gajus\Drill\Exception\RuntimeException\ValidationErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\UserErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\UnknownSubaccountException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\PaymentRequiredException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\GeneralErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException\ValidationErrorException $e) {
    // @see https://mandrillapp.com/api/docs/messages.html
} catch (\Gajus\Drill\Exception\RuntimeException $e) {
    // All possible API errors.
} catch (\Gajus\Drill\Exception\InvalidArgumentException $e) {
    // Invalid SDK use errors.
} catch (\Gajus\Drill\Exception\DrillException $e) {
    // Everything.
}

The Versions

26/01 2016

dev-master

9999999-dev https://github.com/gajus/drill

Mandrill API interface with no bells and whistles.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

by Gajus Kuizinas

email mandrill

26/08 2014

0.0.3

0.0.3.0 https://github.com/gajus/drill

Mandrill API interface with no bells and whistles.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3

 

The Development Requires

by Gajus Kuizinas

email mandrill