NAME
Atompub::Client - A client for the Atom Publishing Protocol
SYNOPSIS
use Atompub::Client;
## Constructs client objects
my $client = Atompub::Client->new;
$client->username('Melody');
$client->password('Nelson');
#$client->proxy( $proxy_uri );
## Get Service Document
my $service = $client->getService( $service_uri );
my @workspaces = $service->workspaces;
my @collections = $workspaces[0]->collections;
## CRUD Entry Resource
## Assuming that the 0-th collection supports Entry Resource
my $collection_uri = $collections[0]->href;
my $entry = XML::Atom::Entry->new;
$entry->title('New Post');
$entry->content('Content of my post.');
my $edit_uri = $client->createEntry( $collection_uri, $entry );
my $entry = $client->getEntry( $edit_uri );
my $entry = $client->EditEntry( $edit_uri, $entry );
$client->DeleteEntry( $edit_uri );
my $feed = $client->getFeed( $collection_uri );
my @entries = $feed->entries;
## CRUD Media Resource
## Assuming that the 1-st collection supports Media Resource
my $collection_uri = $collections[1]->href;
my ( $entry, $headers )
= $client->createMedia( $collection_uri, 'sample.png', 'image/png' );
my $edit_uri = $headers->header('Location');
my ( $edit_media_uri )
= map { $_->href } grep { $_->rel eq 'edit-media' } $entry->link;
my ( $binary, $headers ) = $client->getMedia( $edit_media_uri );
my ( $binary, $headers )
= $client->EditMedia( $edit_media_uri, 'sample.jpg', 'image/jpeg' );
$client->DeleteEntry( $edit_media_uri );
DESCRIPTION
Atompub::Client implements a client for the Atom Publishing Protocol described at http://www.ietf.org/internet-drafts/draft-ietf-atompub-protocol-17.txt.
The client supports following features:
Authentication
Atompub::Client supports the Basic and WSSE Authentication described at http://www.intertwingly.net/wiki/pie/DifferentlyAbledClients.
Service Document
Atompub::Client understands Service Document, in which information of collections are described, such as URIs, acceptable media types, and allowable categories.
Media and Entry Resource
Media Resource as well as Entry Resource are supported. You can create and edit binary resources such as image and video by using Atompub::Client.
Slug header
The client can specify Slug header when creating resources, which may be used as part of the resource URI.
Media type check
Atompub::Client automatically checks media types of the resources before creating and editing them to a collection. Acceptable media types are shown in app:accept elements of the Service Document.
Category check
Atompub::Client automatically checks categories of the Entry Resource before creating and editing them to a collection. Allowable categories are shown in app:categories elements of the Service Document.
Cache control
On-memory cache mechanizm is implemented in Atompub::Client, which is controlled by ETag header.
This module was tested in InteropTokyo2007 http://intertwingly.net/wiki/pie/July2007InteropTokyo, and interoperated with other implementations.
METHODS
Atompub::Client->new([ %options ])
Creates a new Atompub client object. The options are same as LWP::UserAgent.
$client->username([ $username ])
If called with an argument, sets the username for login to $username.
Returns the current username that will be used when logging in to the Atompub server.
$client->password([ $password ])
If called with an argument, sets the password for login to $password.
Returns the current password that will be used when logging in to the Atompub server.
$client->proxy([ $proxy_uri ])
If called with an argument, sets URI of proxy server.
Returns the current URI of the proxy server.
$client->slug([ $slug ])
If called with an argument, sets Slug header which may be used as part of the resource URI. $slug must not be escaped.
Returns the current Slug header.
$client->getService( $service_uri )
Retrieves the Service Document at URI $service_uri.
Returns an XML::Atom::Service object representing the Service Document returned from the server.
Returns false on error.
$client->retrieveService( $service_uri )
An alias for getService.
$client->getCategories( $category_uri )
Retrieves the Category Document at URI $category_uri.
Returns an XML::Atom::Categories object representing the Category Document returned from the server.
Returns false on error.
$client->retrieveCategories( $category_uri )
An alias for getCategories.
$client->createEntry( $collection_uri, $entry )
Creates a new entry in the collection at URI $collection_uri. $entry must be an XML::Atom::Entry object.
If called in scalar context, returns a Location header.
my $location = $client->createEntry( $collection_uri, $entry );
If called in list context, returns an XML::Atom::Entry object and an HTTP::Headers object.
my ( $entry, $headers )
= $client->createEntry( $collection_uri, $entry );
my $location = $headers->header('Location');
Returns false on error.
$client->postEntry( $collection_uri, $entry )
An alias for createEntry.
$client->createMedia( $collection_uri, $media, $media_type )
Creates a new Media Resource and Media Link Entry in the collection at URI $collection_uri.
If $media is a reference to a scalar, it is treated as the binary. If a scalar, treated as a file containing the Media Resource.
$media_type is the media type of the Media Resource, such as 'image/png'.
If called in scalar context, returns a Location header.
my $location
= $client->createMedia( $collection_uri, $media, $media_type );
If called in list context, returns an XML::Atom::Entry object of the Media Link Entry and an HTTP::Headers object.
my ( $entry, $headers )
= $client->createMedia( $collection_uri, $media, $media_type );
my $location = $headers->header('Location');
Returns false on error.
$client->postMedia( $collection_uri, $media, $media_type )
An alias for createMedia.
$client->getEntry( $edit_uri )
Retrieves an entry with the given URI $edit_uri.
Returns an XML::Atom::Entry object. If the server returns 304, returns a cache of the Media Resource.
Returns false on error.
$client->retrieveEntry( $edit_uri )
An alias for getEntry.
$client->getMedia( $edit_uri )
Retrieves Media Resource with the given URI $edit_uri.
If called in scalar context, returns binary of the Media Resource.
my $media = $client->getMedia( $edit_uri );
If called in list context, returns binary of Media Resource and an HTTP::Headers object. If the server returns 304, returns a cache of the Media Resource.
my ( $entry, $headers ) = $client->getMedia( $edit_uri );
my $media_type = $headers->header('Content-Type');
Returns false on error.
$client->retrieveMedia( $edit_uri )
An alias for getMedia.
$client->editEntry( $edit_uri, $entry )
Updates the entry at URI $edit_uri with the entry $entry, which must be an XML::Atom::Entry object.
Returns an XML::Atom::Entry object. If the server returns no content with successful status code, the requested entry is returned.
Returns false on error.
$client->putEntry( $edit_uri, $entry )
An alias for editEntry.
$client->updateEntry( $edit_uri, $entry )
An alias for updateEntry.
$client->editMedia( $edit_uri, $media, $media_type )
Updates the Media Resource at URI $edit_uri with the $media.
If $media is a reference to a scalar, it is treated as the binary. If a scalar, treated as a file containing the Media Resource.
$media_type is the media type of the Media Resource, such as 'image/png'.
If called in scalar context, returns a Media Resource.
my $media
= $client->editMedia( $edit_uri, $media, $media_type );
If called in list context, returns a Media Resource and an HTTP::Headers object.
my ( $media, $headers )
= $client->createMedia( $edit_uri, $media, $media_type );
my $media_type = $headers->header('Content-Type');
If the server returns no content with successful status code, the requested entry is returned.
Returns false on error.
$client->putMedia( $edit_uri, $media, $media_type )
An alias for editMedia.
$client->updateMedia( $edit_uri, $media, $media_type )
An alias for updateMedia.
$client->deleteEntry( $edit_uri );
Deletes the entry at URI $edit_uri.
Returns true on success, false otherwise.
$client->deleteMedia( $edit_uri );
Deletes the Media Resource at URI $edit_uri, and related Media Link Entry.
Returns true on success, false otherwise.
$client->getFeed( $collection_uri )
Retrieves a feed from the collection at URI $collection_uri.
Returns an XML::Atom::Feed object representing the feed returned from the server.
Returns false on error.
$client->retrieveFeed( $collection_uri )
An alias for getFeed.
$client->_info( $collection )
$client->munge_request( $req )
$client->init
SEE ALSO
XML::Atom XML::Atom::Service Atompub::Server
AUTHOR
Takeru INOUE, <takeru.inoue _ gmail.com>
LICENCE AND COPYRIGHT
Copyright (c) 2007, Takeru INOUE <takeru.inoue _ gmail.com>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.