2.4.2014

foto Tomáš Hofman

Tomáš Hofman
+420 777 634 660
tomas.hofman@hobrasoft.cz

Deko is based on distributed database CouchDB, which gives unusual flexibility in way you can use it in different circumstances. Even if your bussines is built up as one-man-show, or on cooperation of two people, or even on large team play, everytime it gives you everything you need for your work.
But what if you need to connect your data from Deko to another systems, you are already using, or with company website or intranet? Even on these circumstances we have answer called Deko API.

Deko API is fairly simple PHP library, which give you power to connect data stored in CouchDB to another datasources or applications. API is object oriented and you need PHP version 5.3 or higher to run it.

Lets show, how to create a simple list of projects on the highest level (so called root). At the begin, you must download Deko API to some directory (eg. libs). You can do this for example through SCM Git command:

git clone https://github.com/hobrasoft-cz/deko-api.git

If you do not use Git, you can download from our GitHubu repository a ZIP file, which contains same thing.

Using of this library is quiet straightforward and looks like this:

<?php

include_once('libs/deko-api/php/Api.php');

$configuration = array(
	// database name is deko
	'database' => 'deko',
	// database runs on localhost
	'host'     => 'localhost',
	// datanase user which can read is called dekouser
	'user'     => 'dekouser',
	// and have some strong password
	'password' => 'Dek0Pa5sw0rd'
);

// create na instance of Deko API
$api = new Api($configuration);

try {
	// login to database
	$api->login();

	// load the root project
	$rootProject = $api->get('root');

	// load all subprojects of root project
	$rootProject->loadProjects();

	// walk all subprojects and print their name
	foreach ($rootProject->projects as $id => $project) {
		echo $project->name.'<br>';
	}
} catch (ApiException $e) {
	// if something go wrong print and error message
	echo $e->getMessage();
}
?>

Simple, isn't it? You can print other document types linked with project, like timesheets in similar way:

$rootProject->loadTimesheets();

foreach ($rootProject->timesheets as $id => $timesheet) {
	echo $timesheet->name.'<br>';
}

You can find more details in API documentation.

Thats all for today. Next time, we will show something more complex. Until then, you can take some inspiration in web interface (sorry, it is only in czech language right now), which we use to provide access for our customer to timesheets (this is sample project).

Hobrasoft s.r.o. | Contact