The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Net::Blogger - an OOP-ish interface for accessing a weblog via the Blogger XML-RPC API.

SYNOPSIS

 use Net::Blogger;
 my $b = Net::Blogger->new(appkey=>APPKEY);

 $b->BlogId(BLOGID);
 $b->Username(USERNAME);
 $b->Password(PASSWORD);

 $b->BlogId($b->GetBlogId(blogname=>'superfoobar'));

 # Get recent posts

 my ($ok,@p) = $b->getRecentPosts(numposts=>20);

 if (! $ok) {
   croak $b->LastError();
 }

 map { print "\t $_->{'postid'}\n"; } @p;

 # Post from a file

 my ($ok,@p) = $b->PostFromFile(file=>"/usr/blogger-test");

 if (! $ok) {
   croak $b->LastError();
 }

 # Deleting posts

 map {
   $b->deletePost(postid=>"$_") || croak $b->LastError();
 } @p;

 # Getting and setting templates

 my $t = $b->getTemplate(type => 'main');
 $b->setTemplate(type=>'main',template=>\$t) || croak $b->LastError();

 # New post

 my $txt = "hello world.";
 my $id = $b->newPost(postbody=>\$txt) || croak $b->LastError();

 # Get post

 my $post = $b->getPost($id) || croak $b->LastError();
 print "Text for last post was $post->{'content'}\n";

DESCRIPTION

Blogger.pm provides an OOP-ish interface for accessing a weblog via the Blogger XML-RPC API.

ENGINES

Blogger.pm relies on "engines" to implement it's functionality. The Blogger.pm package itself is little more than a wrapper file that happens to use a default "Blogger" engine is none other is specified.

   my $manila = Net::Blogger->new(engine=>"manila");

But wait!, you say. It's an API that servers implements and all I should have to do is changed the login data. Why do I need an engine?

Indeed. Every server pretty much gets the spirit of the API right, but each implements the details slightly differently. For example :

The MovableType XML-RPC server follows the spec for the getRecentPost but because of the way Perl auto-vivifies hashes it turns out you can slurp all the posts for a blog rather than the just the 20 most recent.

The Userland Manila server doesn't support the getUsersBlogs method; the Userland RadioUserland server does.

The Blogger server imposes a limit on the maximum length of a post. Other servers don't. (Granted the server in question will return a fault, if necessary, but Blogger.pm tries to do the right thing and check for these sorts of things before adding to the traffic on the network.)

Lots of weblog-like applications don't support the Blogger API but do have a traditional REST interface. With the introduction of Blogger.pm "engines", support for these applications via the API can be added with all the magic happening behind the curtain, so to speak.

CONSTRUCTOR METHODS

$pkg = Net::Blogger->new(%args)

Instantiate a new Blogger object.

Valid arguments are :

  • engine (required)

    String. Default is "blogger".

  • appkey

    String. The magic appkey for connecting to the Blogger XMLRPC server.

  • blogid

    String. The unique ID that Blogger uses for your weblog

  • username

    String. A valid username for blogid

  • password

    String. A valid password for the username/blogid pair.

Blogger API METHODS

$pkg->getUsersBlogs()

Fetch the blogid, url and blogName for each of the Blogger blogs the current user is registered to.

Returns an array ref of hashes.

$pkg->newPost(%args)

Add a new post to the Blogger server.

Valid arguments are :

  • postbody (required)

    Scalar ref.

  • publish

    Boolean.

If the length of postbody exceeds maximum length allowed by the Blogger servers -- 65,536 characters -- currently the text will be chunked into smaller pieces are each piece will be posted separately.

Returns an array containing one, or more, post ids.

$pkg->getPost($postid)

Returns a hash ref, containing the following keys : userid, postid, content and dateCreated.

$pkg->getRecentPosts(%args)

Fetch the latest (n) number of posts for a given blog. The most recent posts are returned first.

Valid arguments are

  • numposts

    Int. If no argument is passed to the method, default is 1.

    "NumberOfPosts is limitemd to 20 at this time. Let me know if this gets annoying. Letting this number get too high could result in some expensive db access, so I want to be careful with it." --Ev

Returns true or false, followed by an array of hash refs. Each hash ref contains the following keys : postid,content,userid,dateCreated

$pkg->editPost(%args)

Update the Blogger database. Set the body of entry $postid to $body.

Valid arguments are :

  • postbody (required)

    Scalar ref or a valid filehandle.

  • postid (required)

    String.

  • publish

    Boolean.

If the length of postbody exceeds maximum length allowed by the Blogger servers -- 65,536 characters -- currently the text will be chunked into smaller pieces are each piece will be posted separately.

Returns an array containing one, or more, post ids.

$pkg->deletePost(%args)

Delete a post from the Blogger server.

Valid arguments are

  • postid (required)

    String.

  • publish

    Boolean.

Returns true or false.

$pkg->setTemplate(%args)

Set the body of the template matching type $type.

"template is the HTML (XML, whatever -- Blogger can output any sort of text). Must contain opening and closing <Blogger> tags to be valid and accepted." --Evan

Valid arguments are

  • template (required)

    Scalar ref.

  • type (required)

    String. Valid types are "main" and "archiveIndex"

Returns true or false.

$pkg->getTemplate(%args)

Fetch the body of the template matching type $type.

Valid types are

  • type (required)

    String. Valid types are "main" and "archiveIndex"

Returns a string.

EXTENDED METHODS

$pkg->MaxPostLength()

TBW

$pkg->GetBlogId(%args)

Return the unique blogid for $args{'blogname'}.

Valid arguments are

  • blogname

    String.

Returns a string. If no blogname is specified, the current blogid for the object is returned.

$pkg->DeleteAllPosts(%args)

TBW

$pkg->PostFromFile(%args)

Open a filehandle, and while true, post to Blogger. If the length of the amount read from the file exceeds the per-post limit assigned by the Blogger servers -- currently 65,536 characters -- the contents of the file will be posted in multiple "chunks".

Valid arguments are

  • file (required)

    /path/to/file

  • postid

    String.

  • publish

    Boolean.

  • tail

    Boolean.

    If true, the method will not attempt to post data whose length exceeds the limit set by the Blogger server in the order that the data is read. Translation : last in becomes last post becomes the first thing you see on your weblog.

If a postid argument is present, the method will call the Blogger API editPost method with postid. Otherwise the method will call the Blogger API newPost method.

Returns true or false, followed by an array of zero, or more, postids.

$pkg->PostFromOutline(%args)

Like PostFromFile, only this time the file is an outliner document.

This method uses Simon Kittle's Text::Outline::asRenderedHTML method for posting. As of this writing, the Text::Outline package has not been uploaded to the CPAN. See below for a link to the homepage/source.

Valid outline formats are OPML, tabbed text outline, Emacs' outline-mode format, and the GNOME Think format.

Valid arguments are

  • file (required)

    /path/to/file

  • postid

    String.

  • publish

    Boolean.

If a postid argument is present, the method will call the Blogger API editPost method with postid. Otherwise the method will call the Blogger API newPost method.

Returns true or false, followed by an array of zero, or more, postids.

VERSION

0.8.3

DATE

September 23, 2002

AUTHOR

Aaron Straup Cope

SEE ALSO

Net::Blogger::API::Core

Net::Blogger::Engine::Base

http://plant.blogger.com/api/

CHANGES

0.8.3

  • Updated POD

0.8.2

  • Added support for the metaWeblog API to the Manila engine.

0.8.1

  • Added support for the mt.getTrackbackPings method in Net::Blogger::Engine::Movabletype::mt.pm

0.8

  • Added Slash engine

0.7

0.6.4

  • Added support for the metaWeblog API to the Movabletype engine.

  • Added quotes to all the VERSION numbers

0.6.3

  • Updated POD for Net::Blogger and all child packages.

0.6.2.2

  • No changes. But, since I uploaded the current codebase to the CPAN as v 0.6.1.2, I decided to upload a new version with a new version number just to keep everyone on first.

0.6.2.1

  • Updated POD.

0.6.2

  • Added support for the UserLand metaWeblog API in the RadioUserLand engine

0.6.1

  • Bugs fixes in Net::Blogger::Engine::Base

0.6

  • Moved most of the code in to Net::Blogger::API::Core, Net::Blogger::API::Extended, Net::Blogger::Engine::Base and Net::Blogger::Engine::Blogger

  • Replaced use of Frontier::Client with XMLRPC::Litem (in Net::Blogger::Engine::Base)

  • Updated POD

0.5.1

  • Modified internals to load implementation specific subclass based on the engine argument passed to the constructor. Props to Simon Kittles for the smack upside the head about the right way to do this :-)

  • Updated POD.

0.5

  • Added Blogger API getPost method.

  • Updated POD.

0.4.6.1

  • Added conditional, where necessary, to see if a maximum post length is applicable.

0.4.6

  • Added Blogger.pm BLOGGER_PROXY constant.

  • Added Blogger.pm Proxy and MaxPostPostLength accessors for corresponding constants. Previously, these values were either read from a scalar constant or an AUTOLOAD method. The change allows [insert blogger-mimicking interface here] subclasses to override the methods and specify an approriate value.

  • Updated POD

0.4.5

  • Added Blogger API getRecentPosts method.

  • Updated POD

0.4.4.1

  • Clarified a few error messages;

  • Fixed remaining instances of "Error::Simple->record() and return 0" in &AUTOLOAD

0.4.4

  • Added use of Error.pm

  • Added Blogger.pm LastError method.

  • Wrapped Frontier::Client method calls in eval statements to prevent unnecessary die-ing.

  • Added stub function and methods calls for Blogger.pm private _TrimPostBody method.

  • Changed return value of Blogger.pm PostFromFile to (boolean, array)

  • Updated POD.

0.4.3

  • Made sure all Blogger.pm methods begin with title case.

0.4.2

  • Added private Blogger.pm _Encode method. Code courtesy of Matt Sergeant's rssmirror.pl script. Someone, give this guy a YAS grant.

  • Added --tail flag to Blogger.pm PostFromFile method.

  • Fixed a bug in Blogger.pm _PostInChunks method where I would end up subscripting outside of the string.

0.4.1

  • Added idiot-level escaping of entities in Blogger.pm newPost and editPost methods. Duh.

0.4

  • Switched to named-based pair arguments.

  • Added Blogger API deletePost method.

  • Added the Blogger.pm PostFromFile method. Experimental

  • Changed Blogger.pm MAX_POSTLENGTH constant.

  • Updated POD

0.3.1

  • Updated POD

0.3

  • Added the Blogger API getTemplate and setTemplate methods.

  • Added the Blogger.pm _PostInChunks method.

  • Changed the order in which parameters are passed to editPost.

  • Changed the return value of both the Blogger API newPost and editPost methods.

0.2

  • Added the Blogger API getUsersBlogs and editPost methods.

  • Adde the Blogger.pm GetBlogId method.

  • Removed the Blogger.pm Publish method.

  • Modifed the Blogger API newPost method to accept the option to publish.

0.1

  • Initial setup.

  • Added the constructor methods.

  • Added the Blogger API newPost method.

  • Added the Blogger.pm Publish method.

BUGS

Hopefully, few.

Please reports all bugs to http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net::Blogger

LICENSE

Copyright (c) 2001-2002 Aaron Straup Cope.

This is free software, you may use it and distribute it under the same terms as Perl itself.