Source

cerberus-docs / docs / developers.rst

Full commit

Developers

We have made a library available that makes it easy for you to integrate Cerberus into your own addons. It is released under the MIT licence so you can use it for commercial purposes if required.

Cerberus Library Requirements

You must have the PHP MCRYPT and Curl extensions installed.

Cerberus Library Usage

The library can be used just like any other EE or CodeIgniter library. Here is an example of loading the library and passing in an array of configuration parameters an EE addon:

<?php

$params = array(
    'hostname' => parse_url($this->EE->config->item('site_url'), PHP_URL_HOST),
    'update_access_key' => 'your_access_key'
);

$this->EE->load->library('cerberus', $params);

The hostname and access key are the only required parameters. See the :doc:`updater/api` for full details of how to use the library.

You should then pass your data as a JSON-encoded array of arrays to the library encrypt method:

<?php

$data = array(
    array(
        'username' => 'username',
        'screen_name' => 'screen_name',
        'email' => 'email',
        'ip_address' => 'ip_address',
        'url' => 'url'
    )
);

$encrypted = $this->EE->cerberus->encrypt(json_encode($data));

Attention!

Note that you must send keys for all five member fields even if they are empty strings

Having encrypted your data you can now send it the Cerberus database:

<?php

$response = $this->EE->cerberus->update($encrypted);

If all goes will the $response will contain a JSON-encoded string indicating success:

{"code": 200, "message": "Ok"}

Please see :doc:`updater/response-codes` for all the possible API responses.