Subscribe to Mailing List
Submit requests and bugs
Follow Astroboa on Twitter
Installation Guide
Maven Repository
Get Source code at GITHUB
Building from Sources
API Documentation
Submit a Bug or Request

Astroboa PHP Client

The Astroboa PHP client is build on top of the Astroboa Resource API and allows for performing all CRUD operations on any repository.

Installation

Download astroboa-php-client from github (use the provided buttons "Download as zip" or "Download as tar.gz"). Extract the zip file in some directory of your preference. Next you should include this directory in your system's PHP include path. If you are not allowed to modify the system's PHP include path, then you may do just fine by creating your programs in the same directory where you extracted the Astroboa PHP client.

Verify that everything is in place running the following:

php -r "require_once('AstroboaClient.php'); print 'Client installed';"

Create an AstroboaClient

You may create an AstroboaClient by invoking its constructor:

	AstroboaClient($repositoryIPAddressOrFQDN="localhost", $repositoryName="astroboa", $username=null, $password=null)

Parameters:

If no username and password are specified, then an unauthenticated client is created. An example is shown below:

<?php
require_once("AstroboaClient.php"); 

$astroboaHost = "demo.betaconcept.com"; 
$repositoryName = "astroboa-demo";
 
$astroboaClient = new AstroboaClient($astroboaHost, $repositoryName); 
?>

You may also create an authenticated AstroboaClient which allows for creating, updating, deleting objects, taxonomies and topics in a repository as show below:

<?php
require_once("AstroboaClient.php");

$astroboaHost = "http://demo.betaconcept.com"; 
$repositoryName = "myrepository"; 
$username="demo"; 
$password="astroboa-demo"; 

$astroboaClient = new AstroboaClient($astroboaHost, $repositoryName, $username, $password);
?>

Query objects

The AstroboaClient offers two methods for quering objects, the getObjectCollection and getObjectCollectionByObjectType.

The getObjectCollectionByObjectType() allows for retrieving a collection of object of a certain type:

	function getObjectCollectionByObjectType($objectType, $offset=0, $limit=50, $orderBy)

Parameters:

Response:

The getObjectCollectionByType methods return a JSON decoded array of retrieved objects.

The code listing below presents how to retrieve e-book objects found in some repository ordered by their title:

<?php

require_once('AstroboaClient.php');

$astroboaHost = "demo.betaconcept.com"; 
$repositoryName = "astroboa-demo";  
$astroboaClient = new AstroboaClient($astroboaHost, $repositoryName); 

$eBookCollection = $astroboaClient->getObjectCollectionByObjectType("eBookObject", 0, 50, "profile.title"); 
print "Total books found: " .  $eBookCollection["totalResourceCount"];

foreach($eBookCollection["resourceCollection"]["resource"] as $eBook) {   
    print "Title : " . $eBook["profile"]["title"];
    print "\n";
}

?>

The getObjectCollection method allows for performing more fine grained object queries:

	function getObjectCollection($query, $projectionPaths, $offset=0, $limit=50, $orderBy)

Parameters:

Response:

The getObjectCollection methods return a JSON decoded array of retrieved objects.

The following code listing presents how to retrieve all objects whose title (actually profile.title) contains the word 'peace' and fetch only the first 20 objects ordered by their modification time (profile.modified). The query will not return all the properties of the objects found, but only their profile property. Note that different object types may be fetched as we did not constrain the object type. e.g. fetch only book or articles.

<?php

require_once("AstroboaClient.php");

$astroboaHost = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";

$client = new AstroboaClient($astroboaHost, $repositoryName);

$eBookCollection = $client->getObjectCollection("profile.title CONTAINS \"peace\"",
                                                "profile",
                                                0,
                                                20,
                                                "profile.modified");

print "Total books found: " . $eBookCollection["totalResourceCount"] . "\n";
foreach ($eBookCollection["resourceCollection"]["resource"] as $eBook) {
    
    print "Title : " . $eBook["profile"]["title"]  . "\n";
    
}
?>

Retrieve a single object

The getObjectByIdOrName method returns an object identified by its id or name:

	function getObjectByIdOrName($idOrName)

Parameters:

Response:

The getObjectIdOrName method returns a JSON decoded representation of the retrieved object.

Create a new object

The addObject method adds a new object to a repository. You have to use an authenticated AstroboaClient to add a new object to a repository:

	function addObject($object)

Parameters:

Create a new object with binary data 

The addObjectWithBinaryData() method adds a new object with binary data to a repository. As with regular objects you have to use an authenticated AstroboaClient to add a new object with binary data to a repository:

function addObjectWithBinaryData($object, $multiparts)

Parameters:

The setBinaryProperty method prepares a binary property of an object to accept the binary data of a file: 

function setBinaryProperty(&$objectBinaryProperty, &$multiparts, $filenamePath)

Parameters:

The code listing below presents how to add a new genericContentResourceObject with an image attached:

<?php
require_once("AstroboaClient.php");

$serverName = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($serverName, $repositoryName, $username, $password);

$filenamePath = "/tmp/rainbow.png";

$object = array("contentObjectTypeName" => "genericContentResourceObject");

$object["profile"] = array ("title" => "rainbow", "contentObjectStatus" => "published");

$multiparts = array();

// &$object["image"] entry will be created by setBinaryProperty
$client->setBinaryProperty(&$object["image"], &$multiparts, $filenamePath);

$client->addObjectWithBinaryData($object, $multiparts);
?>

Here is how to add a fileResource object with a pdf file attached:

<?php
require_once("AstroboaClient.php");

$serverName = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($serverName, $repositoryName, $username, $password);

$filenamePath = "/tmp/guide.pdf";

$object = array("contentObjectTypeName" => "fileResourceObject");

$object["profile"] = array ("title" => "some-guide", "contentObjectStatus" => "published");

$multiparts = array();

// &$object["content"] entry will be created by setBinaryProperty
$client->setBinaryProperty(&$object["content"], &$multiparts, $filenamePath);

$client->addObjectWithBinaryData($object, $multiparts);
?>

The arrayOfFileResourceTypeObject allows for creating a list of files or in other words a file list collection. The code listing below shows how to create a file list consisting of an image and pdf file

<?php
require_once("AstroboaClient.php");

$serverName = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($serverName, $repositoryName, $username, $password);

$object = array("contentObjectTypeName" => "arrayOfFileResourceTypeObject");

$object["profile"] = array ("title" => "my-file-list", "contentObjectStatus" => "published");

$multiparts = array();

$object["fileResource"] = array();

$object["fileResource"][0] = array("title" => "bridge");
$filenamePath = "/tmp/bridge.jpg";
// &$object["fileResource"][0]["content"] entry will be created by setBinaryProperty
$client->setBinaryProperty(&$object["fileResource"][0]["content"], &$multiparts, $filenamePath);

$object["fileResource"][1] = array("title" => "guide");
$filenamePath = "/tmp/guide.pdf";
// &$object["fileResource"][1]["content"] entry will be created by setBinaryProperty
$client->setBinaryProperty(&$object["fileResource"][1]["content"], &$multiparts, $filenamePath);


$client->addObjectWithBinaryData($object, $multiparts);
?>

Update an object

The updateObject method updates an already existing object in a repository. You have to use an authenticated AstroboaClient to update an existing object:

	function updateObject($object)

Parameters:

Update an object with Binary Data

The updateObjectWithBinaryData() method updates an existing object which contains binary data. As with regular objects you have to use an authenticated AstroboaClient to add a new object with binary data to a repository:

function updateObjectWithBinaryData($object, $multiparts)

Parameters:

You should use the setBinaryProperty to prepare an object's property to accept binary data in the same way as when you are creating an object with binary data.

The code listing below shows how to retrieve an array of file resources and update its first file resource:

<?php
require_once('AstroboaClient.php');

$astroboaHost = "demo.betaconcept.com";
$repository = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($astroboaHost, $repository, $username, $password);
if (! is_null($client)) {
    print "Client successfully initialized\n";
}
$filelist = $client->getObjectByIdOrName("test-file-list");

$filenamePath = "/tmp/somefile.pdf";
$multiparts = array();

$client->setBinaryProperty(&$filelist["fileResource"][0]["content"], &$multiparts, $filenamePath);

$client->updateObjectWithBinaryData($filelist, $multiparts);

?>

Delete an Object

The deleteObjectByIdOrName method removes an of a repository. You have to use an authenticated AstroboaClient to delete an object:

	function deleteObjectByIdOrName($objectIdOrName)

Parameters:

Retrieve a single Taxonomy

The getTaxonomyByIdOrName method returns a taxonomy identified by its id or name.

	function getTaxonomyByIdOrName($idOrName)

Parameters

Response:

The getTaxonomyByIdOrName method returns a JSON decoded representation of the retrieved taxonomy

Create a new Taxonomy

The addTaxonomy method creates a new taxonomy in a repository. You have to use an authenticated AstroboaClient to create a new taxonomy:

	function addTaxonomy($taxonomy)

Parameters:

Here is how to create a music taxonomy:

// The user demo@astroboa-demo (user demo of repository astroboa-demo)
// is not allowed to create/update/delete taxonomies

<?php

require_once("AstroboaClient.php");

$client = new AstroboaClient("demo.betaconcept.com", "astroboa-demo", "demo", "astroboa-demo");

$taxonomyToAdd = array(); 
$taxonomyToAdd["name"] = "music-taxonomy"; 
$taxonomyToAdd["localization"] = array("label" => array ("en" => "Music"));

$resp = $client->addTaxonomy($taxonomyToAdd);
print "Response for add taxonomy: $resp[http_code] \n";
?>

Update a Taxonomy

The updateTaxonomy method updates an already existing taxonomy in a repository. You have to use an authenticated AstroboaClient to update a taxonomy:

	function updateTaxonomy($taxonomy)

Parameters:

The code snippet below shows how to update the music taxonomy and add a label for French.

// The user demo@astroboa-demo (user demo of repository astroboa-demo)
// is not allowed to create/update/delete taxonomies 

<?php

require_once("AstroboaClient.php");

$astroboaHost = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($astroboaHost, $repositoryName, $username, $password);

$taxonomyToUpdate = array(); 
$taxonomyToUpdate["cmsIdentifier"] = "d53be6e0-2db7-4b8f-430F-8a3849b2925f"; 
$taxonomyToUpdate["localization"] = array("label" => array("en" => "Music", "fr" => "Musique"));

$resp = $client->updateTaxonomy($taxonomyToUpdate);
print "Response for update taxonomy: $resp[http_code] \n";
?>

Delete a Taxonomy

The deleteTaxonomyByIdOrName method removes a taxonomy of a repository. You have to use an authenticated AstroboaClient to delete a taxonomy:

	function deleteTaxonomyByIdOrName($topicIdOrName)

Parameters:

Query Topics

The getTopicCollection() allows for retrieving a collection of topics specified by a query:

	function getTopicCollection($query, $projectionPaths, $offset=0, $limit=50, $orderBy)

Parameters:

Retrieve a single Topic

The getTopicByIdOrName retrieves a single topic from a repository.

The getTopicByIdOrName method returns a topic identified by its id or name:

	function getTopicByIdOrName($idOrName)

Parameters:

Response:

The getTopicByIdOrName method returns a JSON decoded representation of the retrieved taxonomy:

Create a new Topic

The addTopic method add a new topic to a repository. You have to use an authenticated AstroboaClient to create a new topic.

	function addTopic($topic)

Parameters:

Here is how to create a rock-music topic and place in music taxonomy:

// The user demo@astroboa-demo (user demo of repository astroboa-demo)
// is not allowed to create/update/delete topics

<?php
require_once("AstroboaClient.php");

$astroboaHost = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($astroboaHost, $repositoryName, $username, $password);

$topicToAdd = array(); 
$topicToAdd["name"] = "rock-music"; 
$topicToAdd["localization"] = array("label" => array ("en" => "Rock music"));
$topicToAdd["taxonomy"] = array("name" => "music-taxonomy");

$resp = $client->addTopic($topicToAdd);
print "Response for add topic: $resp[http_code] \n";

?>

Update a Topic

The updateTopic method updates an already existing topic in a repository. You have to use an authenticated AstroboaClient to update a topic:

	function updateTopic($topic)

Parameters:

Here is an example which set the allowsReferrerContentObjects to false, so as no object can use this topic as tag:

// The user demo@astroboa-demo (user demo of repository astroboa-demo)
// is not allowed to create/update/delete topics
 
<?php

require('AstroboaClient.php');

$astroboaHost = "demo.betaconcept.com";
$repositoryName = "astroboa-demo";
$username = "demo";
$password = "astroboa-demo";

$client = new AstroboaClient($astroboaHost, $repositoryName, $username, $password);

$topicToUpdate = array(); 
$topicToUpdate["cmsIdentifier"] = "d53be6e0-2db7-4a8f-8034-8a3849a3b25b"; 
$topicToUpdate["allowsReferrerContentObjects"] = false; 

$resp = $client->updateTopic($topicToUpdate);
print "Response for update: $resp[http_code] \n";
?>

Delete a Topic

The deleteTopic method removes a topic of a repository. You have to use an authenticated AstroboaClient to delete a topic:

	function deleteTopicByIdOrName($topicIdOrName)

Parameters:

 

Last Modified: 17 December 2011
ajax activity image Loading...