Wednesday, April 25, 2007

Using BlueDot's SOAP API with PHP

In the last few weeks I've been working on a Flex based browser for BlueDot. It's been a good project for bringing together a few of my current interests (Flex, MVC, SOAP, PHP, BlueDot). The project is developing nicely but it's not ready for show and tell. But one thing I didn't find when I started the project was information about accessing the API with php. Don't take that the wrong way the BlueDot SOAP API is well documented. But I just couldn't find any information that directly related to using the API with PHP. Hence I thought it might save fellow travellers some leg work if I posted an example.

To get this working I'm using PHP4 and NuSOAP and naturally you'll need a BlueDot account with some Dots and Tags . You'll need to download NuSOAP into folder that will be accessible from your script. If you will be doing a lot of work with SOAP you'll want to place it somewhere that can be easily accessed by all of your projects. I thought we could start by getting the datetime of your last dot. This is the simplest method in BlueDot's API and consequently there are less points to go wrong. So let's look at some code:

<?php
require_once("nusoap/lib/nusoap.php");

//set path to server and create new client
$serverpath = "https://secure.bluedot.us/BlueDotApi.asmx?WSDL";
$client = new soapclient($serverpath);
?>

Just the basics to get started. The first line adds the nusoap libraries which obviously need to be available before they can be called. Next we create a variable with the path to the BlueDot API. Then we create the soap client. The soap client will format the SOAP request based on the details we provide and manage the request.

$client->setCredentials('your_username','your_password','basic');
$err = $client->getError();

if ($err)
{
print_r($err);
}

BlueDot uses basic authentication to check that you have a right to the data we are requesting. Consequently you'll need to use setCredentials with your BlueDot username and password. The third parameter just tells the soap client that we'll be using basic authentication. Finally we use getError to check that the login was passed. In our example we are checking for an error and printing it out so we can debug the login. If there isn't an error then we can proceed to calling the method.

$client->setCredentials('your_username','your_password','basic');
$err = $client->getError();

if ($err)
{
print_r($err);
}
else
{
$namespace ='http://bluedot.us/api';
$soapAction = "http://bluedot.us/api/GetLastUpdatedDateTime";

$result = $client->call('GetLastUpdatedDateTime',"",$namespace,$soapAction);
}

To get the datetime of the last update we call 'GetLastUpdatedDateTime'. This method requires no parameters and returns a datetime (i.e 2007-04-24T23:23:54). The namespace will be the same for all the calls you'll use. But the soap action will change depending on the method name. Next you'll want to check that the call was processed without any problems.

if ($client->fault)
{
print_r($client->response);
}
else
{
$err = $client->getError();

if($err)
{
print_r($err);
}
else
{
echo "<pre>";
print_r($result);
echo "</pre>";
}
}

We can use fault to check for faults and then use response to print out the fault details. If there is no fault we can test for an error and print the error if one exists. If there are no problems then lets just print out the result. Depending on where and how you are going to use the result you'll need to do something more useful here. So lets see it altogether:

<?php

require_once("../../serverScripts/nusoap/lib/nusoap.php");
//set path to server and create new client
$serverpath = "https://secure.bluedot.us/BlueDotApi.asmx?WSDL";
$client = new soapclient($serverpath);
$client->setCredentials('your_username','your_password','basic');
$err = $client->getError();

if ($err)
{
print_r($err);
}
else
{
$namespace ='http://bluedot.us/api';
$soapAction = "http://bluedot.us/api/GetLastUpdatedDateTime";
$result = $client->call('GetLastUpdatedDateTime',"",$namespace,$soapAction);

if ($client->fault)
{
print_r($client->response);
}
else
{
$err = $client->getError();

if ($err)
{
print_r($err);
}
else
{
echo "<pre>";
print_r($result);
echo "</pre>";
}
}
}
?>

Hopefully that's enough to get you started. Most of the available methods are as simple to call. The exceptions are RenameTag (requires two strings) and Search (which requires a Search object; you may want to leave this till you've had a bit of practice). The main differnce between GetLastUpdatedDateTime and most methods is that it returns a very simple object. For example, getTags returns an array of Tags that contain the tags name and a count of the number of dots it's used for. But the differnce is how you process the result not how you make the SOAP call.

Saturday, April 21, 2007

MUV : my first meeting

Finally, attended my first meeting of Macromedia Users Victoria (MUV). I've been planning to go for the last few years. But for a while I was always working on the meeting night. Then they went quiet for a while as they sorted out the change from Macromedia to Adobe (still using Macromedia in the groups branding; not sure what they have planned there). They had their first meeting back last month but I once again had a clash. Anyway I finally got there.

The first half of the evening was spent looking at and discussing the CS3 release. It is a huge release program with many new options for users whatever their level. Therefore any opportunity to discuss the options and their relative merits is much appreciated.

In the second half of the evening Chris Burgess presented the what, why and how of Apollo. I've been keen to get any and all available info on Apollo. Hence a lot of what Chris presented was news. But it was still invaluable to get his views on where Apollo is right now and where it will be heading.

The only disappointing part of the evening was the numbers. It is only their second night back so they are still finding their feet. I guess I'm the last person to comment having taken so long to get to a meeting. But there are a lot more Adobe users than we saw on Thursday night. It would be great to see more developers at future meetings. To state the obvious the more who come the more worthwhile it is for everyone who attends. To get more information you need to register so if you are in Victoria get to it.

Wednesday, April 18, 2007

Flex Framework Posters

The mail just arrived with our Flex Framwork posters and they are massive. There are three posters in all (two that we think are B0 size and one we think is A1). We're trying to convince the manager we'll need to move to a larger office to fit them on the walls. He keeps suggesting dark rooms at the other end of the building. The posters are very impressive and will be very useful if we can think of a way to display them in the space available.

Silverlight Vs Flash

There is a lot of discussion emerging comparing MS's Silverlight and Adobe's Flash. I will use this post to keep track of this discussion:

Noise on the Wire

Over the last few days there has been an excess of noise on the feeds around three topics:
There's not much actual information around the first two mostly speculation and FUD. The third has been coming for a while with a launch a few weeks ago and some online presentations since then.

Everyone will be watching CS3 with interest as it is the first big release since Adobe swallowed Macromedia. This will tell us a lot about the impact of this merger. At work the ability to easy integrate between the design and web teams will decide how quickly we upgrade. For my personal client work it will be about integration with Flex and so I'll probably wait and see what happens with the next Flex release (later this year).

Friday, April 13, 2007

Flex and ActionScript Error Codes

Just a quick post in case you haven't seen this posted elsewhere. The Flex docs team have created a wiki page for documenting Flex error codes and common solutions. If you've ever stared at a Flex error message and scratched your head wondering what it could mean then you'll understand the potential of this document. I'd encourage everyone to participate in promoting and extending this resource.

Monday, April 02, 2007

Sidebar Massage

After studying the Site Overlay results in Google Analytics I realised my blogs sidebar needed a minor makeover. The core of the makeover is changing my Labels to a cloud (instructions here). This meant the Label widget would take up much less room and consequently could sit much higher in the sidebar. I also removed the My Profile widget and moved the profile link into the Links widget. Finally I added a link to my account on BlueDot . Not sure why I hadn't done this earlier.