Darren Ferguson - Umbraco, Dev, PhoRSS

Wednesday, May 28, 2008

Using Umbraco Webservices with Perl

Filed under: Umbraco, Perl - by Darren Ferguson @ 12:27 PM

I had quite a few spam comments on my site that I wanted to get rid of. Without a content search option available in Umbraco, I decided to use the webservices to get a list of all blog comments.

As a result of this, I have quite a nice example of how to access Umbraco via webservices with Perl. The example below will simply get all documents from Umbraco and print them to screen.

use SOAP::Lite +trace => 'debug';
use Data::Dumper;

use constant HOST => 'myhost';
use constant UID  => 'admin';
use constant PWD  => 'mypwd';
use constant ROOTNODE => 0;

my $access = SOAP::Lite
  -> proxy('http://'.HOST.'/umbraco/webservices/api/DocumentService.asmx')
  -> uri('http://umbraco.org/webservices/')
  -> on_action( sub {sprintf '%s%s', @_} );

my $username = SOAP::Data->type(string=> UID)->name('username');
my $password = SOAP::Data->type(string => PWD)->name('password');

my $result = $access->UserAuthenticates($username, $password);

if ($result->fault) {
    print $result->faultcode, " : ", $result->faultstring, "\n";
    die "Couldn't login";
}

my @docs = allDocs($access, ROOTNODE, $username, $password);
foreach my $doc (@docs) {
	print Dumper($doc);
}

sub allDocs {
	
	my ($access, $nodeId, $username, $password) = @_;
	my @docs;
	my $node = SOAP::Data->type(int=> $nodeId)->name('parentid');
	$result = $access->readList($node, $username, $password);
	if($result->result)
	{
		if($result->result->{documentCarrier}->{Id}) { 
			push @docs, $result->result->{documentCarrier};
		} else {
		 	@docs = @{$result->result->{documentCarrier}};
		}
	
	}
	foreach my $doc (@docs) {
		push(@docs, allDocs($access, $doc->{Id}, $username, $password));
	}
	return @docs;
}

Saturday, May 24, 2008

Back online with Umbraco 3.05

Filed under: Umbraco - by umbraco_system @ 6:59 PM

Wow, almost a year since my last post and loads of things have changed and happened

Way too much to detail here all at once, but in preparation for codegarden - which I'll be attending - I thought I should get upgraded to Umbraco 3 and get my Blog back online

I still need to fix the search and update my bio and CV but everything else should be pretty much working again

I'll post again over the weekend when I'll be revealing my codegarden treat for you all. Perl for Umbraco

Oh, and I still eat lots of noodles :) I found out there are a couple of Vietnamese places in Copenhagen, so I'll be checking them out when I am over there.

See you all at Tivoli a week Monday

Darren

Darren Ferguson - Umbraco, Dev, Pho is published with Umbraco 3.0.5