| Net-Blogger documentation | Contained in the Net-Blogger distribution. |
Net::Blogger::Engine::Userland::metaWeblog - UserLand metaWeblog API engine
my $radio = Blogger->new(engine=>"radio"); $radio->Proxy(PROXY); $radio->Username(USERNAME); $radio->Password(PASSWORD); $radio->metaWeblog()->newPost( title=>"hello", description=>"world", publish=>1, );
Implements the UserLand metaWeblog API functionality.
This package is meant to be subclassed. It should not be used on it's own.
Valid arguments are :
Releases prior to Net::Blogger 0.85 accepted a list of arguments rather than a reference. Version 0.85+ are backwards compatible.
Returns an int, or false.
Returns the most recent posts
Valid arguments are:
The maximum number of posts to return
Valid argument are :
Releases prior to Net::Blogger 0.85 accepted a list of arguments rather than a reference. Version 0.85+ are backwards compatible.
Returns a hash reference, or undef.
Releases prior to Net::Blogger 0.85 accepted a list of arguments rather than a reference. Version 0.85+ are backwards compatible.
Returns true or false.
Valid arguments are :
Releases prior to Net::Blogger 0.85 accepted a list of arguments rather than a reference. Version 0.85+ are backwards compatible.
Returns a hash reference or undef.
Returns an array reference or undef.
1.0
$Date: 2005/03/26 19:29:08 $
Aaron Straup Cope
http://www.xmlrpc.com/metaWeblogApi
http://groups.yahoo.com/group/weblog-devel/message/200
http://www.xmlrpc.com/discuss/msgReader$2393
Copyright (c) 2002-2005 Aaron Straup Cope. All Rights Reserved.
This is free software, you may use it and distribute it under the same terms as Perl itself.
| Net-Blogger documentation | Contained in the Net-Blogger distribution. |
{
package Net::Blogger::Engine::Userland::metaWeblog; use strict; $Net::Blogger::Engine::Userland::metaWeblog::VERSION = '1.0'; @Net::Blogger::Engine::Userland::metaWeblog::ISA = qw ( Exporter Net::Blogger::Engine::Base ); @Net::Blogger::Engine::Userland::metaWeblog::EXPORT = qw (); @Net::Blogger::Engine::Userland::metaWeblog::EXPORT_OK = qw (); use Exporter; use Net::Blogger::Engine::Base;
sub getRecentPosts { my $self = shift; my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; my $call = $self->_Client()->call( "metaWeblog.getRecentPosts", $self->_Type(string=>$self->BlogId()), $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), $self->_Type(int=>$args->{'numberOfPosts'}), ); my @posts = ($call) ? (1,@{$call->result()}) : (0,undef); return @posts; }; sub newPost { my $self = shift; my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; my $publish = 0; if (exists $args->{publish}) { $publish = $args->{publish}; delete $args->{publish}; } if (($args->{categories}) && (ref($args->{categories}) ne "ARRAY")) { $self->LastError("Categories must be passed as an array reference."); return 0; } my $call = $self->_Client->call( "metaWeblog.newPost", $self->_Type(string=>$self->BlogId()), $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), $self->_Type(hash=>$args), $self->_Type(boolean=>$publish), ); return ($call) ? $call->result() : return 0; }
sub newMediaObject { my $self = shift; my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; # if ($args->{file}) { my $pkg = "MIME::Base64"; eval "require $pkg"; if ($@) { $self->LastError("Failed to load $pkg for automagic encoding, $@"); return undef; } open(FILE, $args->{file}) or &{ $self->LastError("Failed to open $args->{file} for reading, $!"); return undef; }; my $buf = undef; while (read(FILE, $buf, 60*57)) { $args->{bits} .= &{$pkg."::encode_base64"}($buf); } close FILE; # if (! $args->{type}) { eval "require $pkg"; if ($@) { $self->LastError("Failed to load $pkg for automagic type checking $@"); return undef; } # my $mm = undef; eval { $mm = $pkg->new(); }; if ($@) { $self->LastError("Failed to instantiate $pkg for automagic type checking, $@"); return undef; } $args->{type} = $mm->checktype_filename($args->{file}); if (! $args->{type}) { $self->LastError("Unable to determine file type "); } } # if (! $args->{name}) { require "File::Basename"; $args->{name} = File::Basename::basename($args->{file}); } } # else { foreach ("name","type","bin") { if (! $args->{$_}) { $self->LastError("You must define a value for the $_ property."); return undef; } } } # my $call = $self->_Client->call( "metaWeblog.newMediaObject", $self->_Type(string=>$self->BlogId()), $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), $self->_Type(hash=>$args), ); return ($call) ? $call->result() : undef; }
sub editPost { my $self = shift; my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; my $postid = $args->{postid}; if (! $postid) { $self->LastError("You must specify a postid"); return 0; } delete $args->{postid}; if (($args->{categories}) && (ref($args->{categories}) ne "ARRAY")) { $self->LastError("Categories must be passed as an array reference."); return 0; } my $publish = 0; if (exists $args->{publish}) { $publish = $args->{publish}; delete $args->{publish}; } my $call = $self->_Client->call( "metaWeblog.editPost", $postid, $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), $self->_Type(hash=>$args), $self->_Type(boolean=>$publish), ); return ($call) ? $call->result() : undef; }
sub getPost { my $self = shift; my $args = (ref($_[0]) eq "HASH") ? shift : {@_}; my $postid = $args->{postid}; if (! $postid) { $self->LastError("You must specify a postid"); return 0; } my $call = $self->_Client->call( "metaWeblog.getPost", $postid, $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), ); return ($call) ? $call->result() : undef; }
sub getCategories { my $self = shift; if ($self->{'__parent'} eq "Movabletype") { $self->LastError("This method is not supported by the $self->{'__parent'} engine."); return undef; } my $call = $self->_Client()->call( "metaWeblog.getCategories", $self->_Type(string=>$self->BlogId()), $self->_Type(string=>$self->Username()), $self->_Type(string=>$self->Password()), ); return ($call) ? $call->result() : undef; }
return 1; }