DucksboardBundle for Symfony2
, (*1)
This bundle integrates Symfony2 applications with the Ducksboard API., (*2)
Dependencies
PHP Curl library http://php.net/manual/en/book.curl.php, (*3)
Instalation
With composer
Add the project in the composer.json
file:, (*4)
...
"require": {
...
"sfm/ducksboard-bundle": "dev-master"
...
}
and in the AppKernel.php
file:, (*5)
$bundles = array(
...
new SFM\DucksboardBundle\SFMDucksboardBundle(),
...
);
Execute
php composer.phar install, (*6)
With deps files
Add the project in the deps
file:, (*7)
[DucksboardBundle]
git=https://github.com/mgallego/DucksboardBundle.git
target=/bundles/SFM/DucksboardBundle
and in the `autoload.php' file:, (*8)
$loader->registerNamespaces(array(
...
'SFM' => __DIR__.'/../vendor/bundles',
...
and in the AppKernel.php
file:, (*9)
$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):, (*10)
ducksboard_api = xxxxxxxxxxxxxxx
Second, create the service:, (*11)
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, (*12)
Use the bundle service
The bundle has a service prepared to use. Example:, (*13)
$widget = $this->container->get('sfm.ducksboard.widget');
$widget->setApiKey($this->container->getParameter('ducksboard_api'));
Examples of use
Push method
Simple Widget, (*14)
$widget = $this->container->get('screencast.ducksboard');
$widget->setData(array($widgetID => array('value' => $val1)));
$widget->push();
Double Widget, (*15)
$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, (*16)
$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, (*17)
$widget->getLastValues($widgetId, 3);
$widgetActualData = $widget->getArrayResponse();
//or
$widgetActualData = $widget->getRawResponse();
Find data by seconds, (*18)
$widget->findBySeconds($widgetId, $seconds);
$widgetActualData = $widget->getArrayResponse();
//or
$widgetActualData = $widget->getRawResponse();
Find data by timespan, (*19)
$widget->findByTimespan($widgetId, 'monthly', $timezone);
$widgetActualData = $widget->getArrayResponse();
//or
$widgetActualData = $widget->getRawResponse();
Other resources
Oficial Ducskboard API documentation: http://ducksboard.com/our-apis/, (*20)
A Demo video with examples (spanish): https://vimeo.com/46636287, (*21)