Skip to content

mgallego/DucksboardBundle

Repository files navigation

DucksboardBundle for Symfony2

Build Status

This bundle integrates Symfony2 applications with the Ducksboard API.

Dependencies

PHP Curl library http://php.net/manual/en/book.curl.php

Instalation

With composer

Add the project in the composer.json file:

...
"require": {
...
	"sfm/ducksboard-bundle": "dev-master"
...
}

and in the AppKernel.php file:

	$bundles = array(
        ...
	    new SFM\DucksboardBundle\SFMDucksboardBundle(),
	...
        );

Execute php composer.phar install

With deps files

Add the project in the deps file:

[DucksboardBundle]
    git=https://github.com/mgallego/DucksboardBundle.git
    target=/bundles/SFM/DucksboardBundle

and in the `autoload.php' file:

$loader->registerNamespaces(array(
    ...
    'SFM'         => __DIR__.'/../vendor/bundles',
    ...

and in the AppKernel.php file:

	$bundles = array(
        ...
	    new SFM\DucksboardBundle\SFMDucksboardBundle(),
	...
        );

Use like an own service

First you need to include the Ducksboard apiKey into the parameters file (ini/yml):

ducksboard_api    =  xxxxxxxxxxxxxxx

Second, create the service:

services:
...
...
    example.ducksboard:
        class: SFM\DucksboardBundle\Adapter\Widget
        arguments: [@sfm.ducksboard.connector]	
        calls:
            - [setApiKey, [%ducksboard_api%]]

Now you can use your own service that set automatically the apikey

Use the bundle service

The bundle has a service prepared to use. Example:

$widget = $this->container->get('sfm.ducksboard.widget');
$widget->setApiKey($this->container->getParameter('ducksboard_api'));

Examples of use

Push method

Simple Widget

        $widget = $this->container->get('screencast.ducksboard');
        $widget->setData(array($widgetID => array('value' => $val1)));
        $widget->push();

Double Widget

        $widget = $this->container->get('screencast.ducksboard');
        $dateData1 = array(
            array('timestamp' => time(), 'value' => '130'),
            array('timestamp' => time() - ((24*60*60)) , 'value' => '50'),
            array('timestamp' => time() - ((2*24*60*60)) , 'value' => '70'),
            array('timestamp' => time() - ((3*24*60*60)) , 'value' => '20'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '50'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '80'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '100'));

        $dateData2 = array(
            array('timestamp' => time(), 'value' => '80'),
            array('timestamp' => time() - ((24*60*60)) , 'value' => '20'),
            array('timestamp' => time() - ((2*24*60*60)) , 'value' => '70'),
            array('timestamp' => time() - ((3*24*60*60)) , 'value' => '80'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '50'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '90'),
            array('timestamp' => time() - ((4*24*60*60)) , 'value' => '30'));

        $widgetGraphData = array(
            $widgetId1=> $dateData1,
            $widgetId2 => $dateData2
            );

        $widget->setData($widgetGraphData);
        $widget->push();

Delta Values

        $widget	= $this->container->get('screencast.ducksboard');
	$widgetData = array($widgetId => array('delta' => 1 ));
	$widget->setData($widgetData);
	$widget->push();

Pull method

Get the 3 last data of a widget

   $widget->getLastValues($widgetId, 3);
   $widgetActualData = $widget->getArrayResponse();		     
   //or
   $widgetActualData = $widget->getRawResponse();		     

Find data by seconds

   $widget->findBySeconds($widgetId, $seconds);
   $widgetActualData = $widget->getArrayResponse();		     
   //or
   $widgetActualData = $widget->getRawResponse();		     

Find data by timespan

   $widget->findByTimespan($widgetId, 'monthly', $timezone);
   $widgetActualData = $widget->getArrayResponse();		     
   //or
   $widgetActualData = $widget->getRawResponse();		     

Other resources

Oficial Ducskboard API documentation: http://ducksboard.com/our-apis/

A Demo video with examples (spanish): https://vimeo.com/46636287

About

A Symfony2 Bundle to integrate an app with Ducksboard

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages