File Coverage

blib/lib/Net/Blogger.pm
Criterion Covered Total %
statement 6 26 23.0
branch 0 6 0.0
condition 0 5 0.0
subroutine 2 6 33.3
pod 2 2 100.0
total 10 45 22.2


line stmt bran cond sub pod time code
1             {
2            
3             =head1 NAME
4            
5             Net::Blogger - an OOP-ish interface for accessing a weblog via
6             the Blogger XML-RPC API.
7            
8             =head1 SYNOPSIS
9            
10             use Net::Blogger;
11             my $b = Net::Blogger->new(appkey=>APPKEY);
12            
13             $b->BlogId(BLOGID);
14             $b->Username(USERNAME);
15             $b->Password(PASSWORD);
16            
17             $b->BlogId($b->GetBlogId(blogname=>'superfoobar'));
18            
19             # Get recent posts
20            
21             my ($ok,@p) = $b->getRecentPosts(numposts=>20);
22            
23             if (! $ok) {
24             croak $b->LastError();
25             }
26            
27             map { print "\t $_->{'postid'}\n"; } @p;
28            
29             # Post from a file
30            
31             my ($ok,@p) = $b->PostFromFile(file=>"/usr/blogger-test");
32            
33             if (! $ok) {
34             croak $b->LastError();
35             }
36            
37             # Deleting posts
38            
39             map {
40             $b->deletePost(postid=>"$_") || croak $b->LastError();
41             } @p;
42            
43             # Getting and setting templates
44            
45             my $t = $b->getTemplate(type => 'main');
46             $b->setTemplate(type=>'main',template=>\$t) || croak $b->LastError();
47            
48             # New post
49            
50             my $txt = "hello world.";
51             my $id = $b->newPost(postbody=>\$txt) || croak $b->LastError();
52            
53             # Get post
54            
55             my $post = $b->getPost($id) || croak $b->LastError();
56             print "Text for last post was $post->{'content'}\n";
57            
58             =head1 DESCRIPTION
59            
60             Blogger.pm provides an OOP-ish interface for accessing a weblog
61             via the Blogger XML-RPC API.
62            
63             =head1 ENGINES
64            
65             Blogger.pm relies on "engines" to implement it's functionality.
66             The Blogger.pm package itself is little more than a wrapper file
67             that happens to use a default "Blogger" engine is none other is
68             specified.
69            
70             my $manila = Net::Blogger->new(engine=>"manila");
71            
72             But wait!, you say. It's an API that servers implements and all I should have to
73             do is changed the login data. Why do I need an engine?
74            
75             Indeed. Every server pretty much gets the spirit of the API right, but each implements
76             the details slightly differently. For example :
77            
78             The MovableType XML-RPC server follows the spec for the I but because of
79             the way Perl auto-vivifies hashes it turns out you can slurp all the posts for a blog
80             rather than the just the 20 most recent.
81            
82             The Userland Manila server doesn't support the I method; the Userland
83             RadioUserland server does.
84            
85             The Blogger server imposes a limit on the maximum length of a post. Other servers don't.
86             (Granted the server in question will return a fault, if necessary, but Blogger.pm tries
87             to do the right thing and check for these sorts of things before adding to the traffic
88             on the network.)
89            
90             Lots of weblog-like applications don't support the Blogger API but do have a traditional
91             REST interface. With the introduction of Blogger.pm "engines", support for these applications
92             via the API can be added with all the magic happening behind the curtain, so to speak.
93            
94             =cut
95            
96             package Net::Blogger;
97 1     1   2546 use strict;
  1         3  
  1         51  
98            
99 1     1   7 use vars qw ( $AUTOLOAD $LAST_ERROR );
  1         2  
  1         547  
100            
101             $Net::Blogger::VERSION = '1.02';
102            
103             =head1 PACKAGE METHODS
104            
105             =cut
106            
107             =head2 __PACKAGE__->new(\%args)
108            
109             Instantiate a new Blogger object.
110            
111             Valid arguments are :
112            
113             =over 4
114            
115             =item *
116            
117             B (required)
118            
119             String. Default is "blogger".
120            
121             =item *
122            
123             B
124            
125             String. The magic appkey for connecting to the Blogger XMLRPC server.
126            
127             =item *
128            
129             B
130            
131             String. The unique ID that Blogger uses for your weblog
132            
133             =item *
134            
135             B
136            
137             String. A valid username for blogid
138            
139             =item *
140            
141             B
142            
143             String. A valid password for the username/blogid pair.
144            
145             =back
146            
147             Releases prior to Net::Blogger 0.85 accepted a list of arguments
148             rather than a reference. Version 0.85+ are backwards compatible.
149            
150             Returns an object. Woot!
151            
152             =head2 __PACKAGE__->init()
153            
154             Initializes the specified engine
155            
156             =cut
157            
158             sub new {
159 0     0 1   my $pkg = shift;
160 0           my $self = {};
161 0           bless $self,$pkg;
162 0 0         $self->init(@_) || return undef;
163 0           return $self;
164             }
165            
166             sub init {
167 0     0 1   my $self = shift;
168 0 0         my $args = (ref($_[0]) eq "HASH") ? shift : { @_ };
169            
170 0   0       my $engine = $args->{'engine'} || "blogger";
171 0           my $class = join("::",__PACKAGE__,"Engine",ucfirst $engine);
172            
173 0           eval "require $class";
174            
175 0 0         if ($@) {
176 0           print $@,"\n";
177 0           $LAST_ERROR = "Unrecognized implementation of the Blogger API.";
178 0           return 0;
179             }
180            
181             $self->{"_class"} = $class->new(%$args)
182 0   0       || &{ $LAST_ERROR = Error->prior(); return 0; };
183            
184 0           return 1;
185             }
186            
187             =head1 Blogger API METHODS
188            
189             =head2 $pkg->getUsersBlogs()
190            
191             Fetch the I, I and I for each of the Blogger blogs
192             the current user is registered to.
193            
194             Returns an array ref of hashes.
195            
196             =head2 $pkg->newPost(\%args)
197            
198             Add a new post to the Blogger server.
199            
200             Valid arguments are :
201            
202             =over 4
203            
204             =item *
205            
206             B
207            
208             Scalar ref. I
209            
210             =item *
211            
212             B
213            
214             Boolean.
215            
216             =back
217            
218             If the length of I exceeds maximum length allowed by the Blogger servers
219             -- 65,536 characters -- currently the text will be chunked into smaller pieces are
220             each piece will be posted separately.
221            
222             Returns an array containing one, or more, post ids.
223            
224             =head2 $pkg->getPost($postid)
225            
226             Returns a hash ref, containing the following keys : userid, postid, content and dateCreated.
227            
228             =head2 $pkg->getRecentPosts(\%args)
229            
230             Fetch the latest (n) number of posts for a given blog. The most recent posts are returned
231             first.
232            
233             Valid arguments are
234            
235             =over 4
236            
237             =item *
238            
239             B
240            
241             Int. If no argument is passed to the method, default is 1.
242            
243             "NumberOfPosts is limited to 20 at this time. Let me know if this
244             gets annoying. Letting this number get too high could result in some
245             expensive db access, so I want to be careful with it." --Ev
246            
247             =back
248            
249             Releases prior to Net::Blogger 0.85 accepted a list of arguments
250             rather than a reference. Version 0.85+ are backwards compatible.
251            
252             Returns true or false, followed by an array of hash refs. Each hash ref contains the following
253             keys : postid,content,userid,dateCreated
254            
255             =head2 $pkg->editPost(\%args)
256            
257             Update the Blogger database. Set the body of entry $postid to $body.
258            
259             Valid arguments are :
260            
261             =over 4
262            
263             =item *
264            
265             B (required)
266            
267             Scalar ref or a valid filehandle.
268            
269             =item *
270            
271             B (required)
272            
273             String.
274            
275             =item *
276            
277             B
278            
279             Boolean.
280            
281             =back
282            
283             If the length of I exceeds maximum length allowed by the Blogger servers
284             -- 65,536 characters -- currently the text will be chunked into smaller pieces are
285             each piece will be posted separately.
286            
287             Releases prior to Net::Blogger 0.85 accepted a list of arguments
288             rather than a reference. Version 0.85+ are backwards compatible.
289            
290             Returns an array containing one, or more, post ids.
291            
292             =head2 $pkg->deletePost(\%args)
293            
294             Delete a post from the Blogger server.
295            
296             Valid arguments are
297            
298             =over 4
299            
300             =item *
301            
302             B (required)
303            
304             String.
305            
306             =item *
307            
308             B
309            
310             Boolean.
311            
312             =back
313            
314             Releases prior to Net::Blogger 0.85 accepted a list of arguments
315             rather than a reference. Version 0.85+ are backwards compatible.
316            
317             Returns true or false.
318            
319             =head2 $pkg->setTemplate(\%args)
320            
321             Set the body of the template matching type I<$type>.
322            
323             "template is the HTML (XML, whatever -- Blogger can output any sort of text).
324             Must contain opening and closing tags to be valid and accepted."
325             --Evan
326            
327             Valid arguments are
328            
329             =over 4
330            
331             =item *
332            
333             B