PHPackages                             timacdonald/kumulos - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. timacdonald/kumulos

AbandonedArchivedUtility[API Development](/categories/api)

timacdonald/kumulos
===================

Kumulos PHP API SDK

v1.0.1(9y ago)2429[1 PRs](https://github.com/timacdonald/kumulos-api/pulls)MITPHPPHP &gt;=5.6

Since Apr 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/timacdonald/kumulos-api)[ Packagist](https://packagist.org/packages/timacdonald/kumulos)[ RSS](/packages/timacdonald-kumulos/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (3)DependenciesVersions (5)Used By (0)

Kumulos PHP API SDK Package
===========================

[](#kumulos-php-api-sdk-package)

This package is a modern PHP SDK for the [Kumulos API](https://docs.kumulos.com/build/api/).

Installation
------------

[](#installation)

You can install using [composer](https://getcomposer.org/) from [Packagist](https://packagist.org/packages/timacdonald/kumulos).

```
composer require timacdonald/kumulos

```

Although it is not recommended, because this package does not contain any dependencies, you can simply download and include the files in your project.

Versioning
----------

[](#versioning)

This package uses *Semantic Versioning*. You can find out more about what this is and why it matters by reading [the spec](http://semver.org) or for something more readable, check out [this post](https://laravel-news.com/building-apps-composer).

Usage
-----

[](#usage)

Create a Kumulos API object and then simply call the methods you've created in your API on the API object.

```
use TiMacDonald\Kumulos\Api;

/**
 * Create our api object instance.
 */
$api = new Api($key, $secret);

/**
 * Call an API method on the object, passing in an associative array of values.
 */
$api->createUser([
    'name' => 'Tim MacDonald',
    'twitter' => '@timacdonald87',
    'github' => 'timacdonald',
    'website' => 'timacdonald.me'
]);

/**
 * Check if it failed.
 */
if ($api->failed()) {
    // deal with failure, perhaps with an exception
    throw new Exception($api->response()->message(), $api->response()->statusCode());
}

/**
 * Retrieve the response payload.
 */
$userId = $api->response()->payload();
```

### Normalized Status Codes

[](#normalized-status-codes)

Kumulos responds with custom status codes, but if you would like to normalize these status codes to the [standard HTTP response codes](http://bit.ly/2ovBMPg), you can simply call the following methods:

```
// Check if it failed
if ($api->failed()) {
    // deal with failure, perhaps with an exception
    throw new Exception($api->response()->normalizedMessage(), $api->response()->normalizedStatusCode());
}
```

Wiring Up DI in Laravel
-----------------------

[](#wiring-up-di-in-laravel)

If you are utilising the [Laravel](https://laravel.com) framework, you will want to put you API key and secret in you environment (.env) file.

```
...
DB_USERNAME=homestead
DB_PASSWORD=secret

KUMULOS_API_KEY=your-api-key-here
KUMULOS_API_SECRET=your-secrethere

```

The in your `./config/services.php` file, you can add the Kumulos service like so:

```
return [
    'kumulos' => [
        'key' => env('KUMULOS_API_KEY'),
        'secret' => env('KUMULOS_API_SECRET')
    ],
    ...
```

Great. Now the config is sorted, lets bind it to the IOC container. In your app service provider's register method, simply add the following binding method:

```
$this->app->bind(\TiMacDonald\Kumulos\Api::class, function ($app) {
    return new \TiMacDonald\Kumulos\Api(
        $app['config']->get('services.kumulos.key'),
        $app['config']->get('services.kumulos.secret')
    );
});
```

Now you can have the container resolve your API class for you without having to 'new' up an instance.

```
