File Coverage

blib/lib/Buzznet/API.pm
Criterion Covered Total %
statement 114 384 29.6
branch 0 44 0.0
condition n/a
subroutine 38 74 51.3
pod n/a
total 152 502 30.2


line stmt bran cond sub pod time code
1             package Buzznet::API;
2            
3 1     1   19763 use strict; use warnings;
  1     1   1  
  1         35  
  1         5  
  1         2  
  1         34  
4            
5             require Exporter;
6 1     1   837 use AutoLoader qw(AUTOLOAD);
  1         1475  
  1         5  
7            
8             our @ISA = qw(Exporter);
9            
10             # Items to export into callers namespace by default. Note: do not export
11             # names by default without a very good reason. Use EXPORT_OK instead.
12             # Do not simply export all your public functions/methods/constants.
13            
14             # This allows declaration use Buzznet::API ':all';
15             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
16             # will save memory.
17             our %EXPORT_TAGS = ( 'all' => [ qw(
18            
19             ) ] );
20            
21             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
22            
23             our @EXPORT = qw(
24            
25             );
26            
27             our $VERSION = '0.01';
28            
29             #require XSLoader;
30             #XSLoader::load('Buzznet::API', $VERSION);
31            
32             # Preloaded methods go here.
33             require RPC::XML;
34             require RPC::XML::Client;
35             require MIME::Base64;
36 1     1   494 use Buzznet::Entry;
  1         2  
  1         52  
37 1     1   433 use Buzznet::Comment;
  1         3  
  1         43  
38 1     1   443 use Buzznet::Profile;
  1         2  
  1         37  
39 1     1   451 use Buzznet::Gallery;
  1         2  
  1         36  
40            
41            
42             # Method constants
43 1     1   6 use constant NEWPOST => "buzznet.newPost";
  1         1  
  1         79  
44 1     1   4 use constant EDITPOST => "buzznet.editPost";
  1         2  
  1         32  
45 1     1   4 use constant REMOVEPOST => "buzznet.removePost";
  1         1  
  1         30  
46 1     1   16 use constant GETENTRY => "buzznet.getEntry";
  1         2  
  1         30  
47 1     1   4 use constant GETCOMMENTS => "buzznet.getComments";
  1         1  
  1         30  
48 1     1   4 use constant ADDCOMMENT => "buzznet.addComment";
  1         1  
  1         41  
49 1     1   4 use constant REMOVECOMMENT => "buzznet.removeComment";
  1         2  
  1         35  
50 1     1   4 use constant GETRECENTCOMMENTS => "buzznet.getRecentComments";
  1         1  
  1         41  
51 1     1   4 use constant ADDBUZZWORDS => "buzznet.addBuzzwords";
  1         1  
  1         30  
52 1     1   4 use constant REMOVEBUZZWORDS => "buzznet.removeBuzzwords";
  1         1  
  1         33  
53 1     1   4 use constant UPDATEPROFILE => "buzznet.updateProfile";
  1         1  
  1         27  
54 1     1   4 use constant ADDFRIEND => "buzznet.addFriend";
  1         2  
  1         32  
55 1     1   4 use constant REMOVEFRIEND => "buzznet.removeFriend";
  1         2  
  1         33  
56 1     1   3 use constant ADDGALLERY => "buzznet.addGallery";
  1         8  
  1         29  
57 1     1   4 use constant EDITGALLERY => "buzznet.editGallery";
  1         1  
  1         38  
58 1     1   4 use constant REMOVEGALLERY => "buzznet.removeGallery";
  1         2  
  1         29  
59 1     1   3 use constant ADDBOOKMARK => "buzznet.addBookmark";
  1         2  
  1         38  
60 1     1   4 use constant REMOVEBOOKMARK => "buzznet.removeBookmark";
  1         1  
  1         33  
61 1     1   3 use constant GETBOOKMARKS => "buzznet.getBookmarks";
  1         2  
  1         27  
62 1     1   4 use constant GETMYFRIENDS => "buzznet.getMyFriends";
  1         1  
  1         32  
63 1     1   4 use constant GETFRIENDS => "buzznet.getFriends";
  1         1  
  1         33  
64 1     1   3 use constant GETFRIENDSRECENT => "buzznet.getFriendsRecent";
  1         2  
  1         40  
65 1     1   5 use constant GETMOSTPOPULAR => "buzznet.getMostPopular";
  1         1  
  1         48  
66 1     1   4 use constant GETTODAYSBIRTHDAYS => "buzznet.getTodaysBirthdays";
  1         1  
  1         30  
67 1     1   3 use constant GETONLINENOW => "buzznet.getOnlineNow";
  1         2  
  1         40  
68 1     1   5 use constant GETRECENTPOSTS => "buzznet.getRecentPosts";
  1         1  
  1         32  
69 1     1   4 use constant GETFEATUREDUSERS => "buzznet.getFeaturedUsers";
  1         1  
  1         28  
70 1     1   4 use constant GETBUZZWORD => "buzznet.getBuzzwords";
  1         1  
  1         47  
71 1     1   4 use constant BROWSEBUZZWORDS => "buzznet.browseBuzzwords";
  1         3  
  1         56  
72 1     1   5 use constant GETGALLERY => "buzznet.getGallery";
  1         1  
  1         36  
73 1     1   4 use constant GETSUBGALLERIES => "buzznet.getSubGalleries";
  1         2  
  1         3818  
74            
75             sub new
76             {
77 0     0     my ($package,@refs) = @_;
78 0           my $inst = {@refs};
79 0           $inst->{"error"} = undef;
80 0           return bless($inst,$package);
81             }
82            
83             sub url
84             {
85 0     0     my $self = shift;
86 0           my $url = "http://www.buzznet.com/interface/xmlrpc/?key=" . $self->{"key"};
87 0           return $url;
88             }
89            
90             sub getXMLRPC
91             {
92 0     0     my $self = shift;
93 0           my $cli = RPC::XML::Client->new($self->url);
94 0           $cli->credentials("Buzznet",$self->{"username"},$self->{"password"});
95 0           my $request = $cli->request;
96 0           return $cli;
97             }
98            
99             sub sendRequest
100             {
101 0     0     my $self = shift;
102            
103 0           my $request = RPC::XML::request->new(@_);
104            
105 0           my $client = $self->getXMLRPC;
106            
107 0           my $response = $client->send_request($request);
108            
109 0 0         if(ref($response))
110             {
111 0 0         if(!$response->value)
112             {
113 0           $self->{"error"} = "Error response from server";
114             }
115 0           return $response->value;
116             }
117             else
118             {
119 0           $self->{"error"} = $response;
120            
121             # error condition
122 0           return 0;
123             }
124             }
125            
126             sub error
127             {
128 0     0     my $self = shift;
129 0           return $self->{"error"};
130             }
131            
132             sub newPost
133             {
134 0     0     my $self = shift;
135 0           my ($filename, $caption, $body, $category) = @_;
136            
137 0           my $encoded_file = "";
138            
139             eval
140 0           {
141 0 0         open(FILE,$filename) || die "Could not open $filename: $!\n";
142 0           while(read(FILE,my $buf,60*57))
143             {
144 0           $encoded_file .= MIME::Base64::encode_base64($buf);
145             }
146            
147             };
148            
149 0 0         if($@)
150             {
151 0           $self->{"error"} = $@;
152            
153             # error condition
154 0           return 0;
155             }
156            
157 0           return $self->sendRequest(NEWPOST,
158             RPC::XML::string->new($encoded_file),
159             RPC::XML::string->new($caption),
160             RPC::XML::string->new($body),
161             RPC::XML::string->new($category));
162            
163             }
164            
165             sub editPost
166             {
167 0     0     my $self = shift;
168 0           my ($entryId, $filename, $caption, $body, $category) = @_;
169            
170 0           my $encoded_file = "";
171            
172             eval
173 0           {
174 0 0         open(FILE,$filename) || die "Could not open $filename: $!\n";
175 0           while(read(FILE,my $buf,60*57))
176             {
177 0           $encoded_file .= MIME::Base64::encode_base64($buf);
178             }
179            
180             };
181            
182 0 0         if($@)
183             {
184 0           $self->{"error"} = $@;
185            
186             # error condition
187 0           return 0;
188             }
189            
190 0           return $self->sendRequest(EDITPOST,
191             RPC::XML::string->new($entryId),
192             RPC::XML::string->new($encoded_file),
193             RPC::XML::string->new($caption),
194             RPC::XML::string->new($body));
195             }
196            
197             sub removePost
198             {
199 0     0     my $self = shift;
200 0           my $entryId = shift;
201            
202 0           return $self->sendRequest(REMOVEPOST,RPC::XML::string->new($entryId));
203             }
204            
205             sub getEntry
206             {
207 0     0     my $self = shift;
208 0           my ($entryId, $type) = @_;
209            
210 0           print "ENTRY: $entryId\n";
211 0           print "TYPE: $type\n";
212 0           my $rawentry = $self->sendRequest(GETENTRY,
213             RPC::XML::string->new($entryId),
214             RPC::XML::string->new($type));
215            
216 0 0         if($rawentry)
217             {
218 0           return Buzznet::Entry->new(%{$rawentry});
  0            
219             }
220             else
221             {
222 0           return $rawentry;
223             }
224             }
225            
226             sub addGallery
227             {
228 0     0     my $self = shift;
229 0           my ($name, $title, $description, $keyword, $password) = @_;
230            
231 0           return $self->sendRequest(ADDGALLERY,
232             RPC::XML::string->new($name),
233             RPC::XML::string->new($title),
234             RPC::XML::string->new($description),
235             RPC::XML::string->new($keyword),
236             RPC::XML::string->new($password));
237             }
238            
239             sub editGallery
240             {
241 0     0     my $self = shift;
242 0           my ($name, $title, $description, $keyword, $password) = @_;
243            
244 0           return $self->sendRequest(EDITGALLERY,
245             RPC::XML::string->new($name),
246             RPC::XML::string->new($title),
247             RPC::XML::string->new($description),
248             RPC::XML::string->new($keyword),
249             RPC::XML::string->new($password));
250             }
251            
252             sub removeGallery
253             {
254 0     0     my $self = shift;
255 0           my $name = shift;
256            
257 0           return $self->sendRequest(REMOVEGALLERY,RPC::XML::string->new($name));
258             }
259            
260             sub getSubGalleries
261             {
262 0     0     my $self = shift;
263 0           my $username = shift;
264            
265 0           my $rawgalleries = $self->sendRequest(GETSUBGALLERIES,
266             RPC::XML::string->new($username));
267            
268 0           my @galleries = ();
269 0 0         if($rawgalleries)
270             {
271 0           foreach my $gallery (@{$rawgalleries})
  0            
272             {
273 0           my %hash = %{$gallery};
  0            
274 0           my $buzznetGallery = Buzznet::Gallery->new(%hash);
275 0           push(@galleries,$buzznetGallery);
276             }
277             }
278            
279 0           return @galleries;
280             }
281            
282             sub getGallery
283             {
284 0     0     my $self = shift;
285 0           my ($blogname, $mode, $user_cat, $current_page, $pagesize) = @_;
286            
287 0           my $rawentries = $self->sendRequest(GETGALLERY,
288             RPC::XML::string->new($blogname),
289             RPC::XML::string->new($mode),
290             RPC::XML::string->new($user_cat),
291             RPC::XML::int->new($current_page),
292             RPC::XML::int->new($pagesize));
293            
294            
295 0           my @entries = ();
296 0 0         if($rawentries)
297             {
298 0           foreach my $entry (@{$rawentries})
  0            
299             {
300 0           my %hash = %{$entry};
  0            
301 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
302 0           push(@entries,$buzznetEntry);
303             }
304             }
305            
306 0           return @entries;
307            
308             }
309            
310             sub getRecentPosts
311             {
312 0     0     my $self = shift;
313 0           my $type = shift;
314            
315 0           my $rawentries = $self->sendRequest(GETRECENTPOSTS,
316             RPC::XML::string->new($type));
317            
318            
319 0           my @entries = ();
320 0 0         if($rawentries)
321             {
322 0           foreach my $entry (@{$rawentries})
  0            
323             {
324 0           my %hash = %{$entry};
  0            
325 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
326 0           push(@entries,$buzznetEntry);
327             }
328             }
329            
330 0           return @entries;
331             }
332            
333             sub getComments
334             {
335 0     0     my $self = shift;
336 0           my ($entryId, $type) = @_;
337            
338 0           my $rawcomments = $self->sendRequest(GETCOMMENTS,
339             RPC::XML::string->new($entryId),
340             RPC::XML::string->new($type));
341            
342            
343 0           my @comments = ();
344 0 0         if($rawcomments)
345             {
346 0           foreach my $comment (@{$rawcomments})
  0            
347             {
348 0           my %hash = %{$comment};
  0            
349 0           my $buzznetComment = Buzznet::Comment->new(%hash);
350 0           push(@comments,$buzznetComment);
351             }
352             }
353            
354 0           return @comments;
355            
356             }
357            
358             sub addComment
359             {
360 0     0     my $self = shift;
361 0           my ($entryId, $comment, $type) = @_;
362            
363 0           return $self->sendRequest(ADDCOMMENT,
364             RPC::XML::string->new($entryId),
365             RPC::XML::string->new($comment),
366             RPC::XML::string->new($type));
367             }
368            
369             sub removeComment
370             {
371 0     0     my $self = shift;
372 0           my $commentId = shift;
373            
374 0           return $self->sendRequest(REMOVECOMMENT,
375             RPC::XML::string->new($commentId));
376            
377             }
378            
379             sub getRecentComments
380             {
381 0     0     my $self = shift;
382 0           my $username = shift;
383            
384 0           my $rawcomments = $self->sendRequest(GETRECENTCOMMENTS,
385             RPC::XML::string->new($username));
386            
387            
388 0           my @comments = ();
389 0 0         if($rawcomments)
390             {
391 0           foreach my $comment (@{$rawcomments})
  0            
392             {
393 0           my %hash = %{$comment};
  0            
394 0           my $buzznetComment = Buzznet::Comment->new(%hash);
395 0           push(@comments,$buzznetComment);
396             }
397             }
398            
399 0           return @comments;
400             }
401            
402             sub addBuzzwords
403             {
404 0     0     my $self = shift;
405 0           my ($entryId, $buzzwords, $type) = @_;
406            
407 0           return $self->sendRequest(ADDBUZZWORDS,
408             RPC::XML::string->new($entryId),
409             RPC::XML::string->new($buzzwords),
410             RPC::XML::string->new($type));
411             }
412            
413             sub removeBuzzwords
414             {
415 0     0     my $self = shift;
416 0           my ($entryId, $buzzword) = @_;
417            
418 0           return $self->sendRequest(REMOVEBUZZWORDS,
419             RPC::XML::string->new($entryId),
420             RPC::XML::string->new($buzzword));
421             }
422            
423             sub getBuzzword
424             {
425 0     0     my $self = shift;
426 0           my ($buzzword, $pagesize, $pageNumber) = @_;
427            
428 0           my $rawentries = $self->sendRequest(GETBUZZWORD,
429             RPC::XML::string->new($buzzword),
430             RPC::XML::int->new($pagesize),
431             RPC::XML::int->new($pageNumber));
432            
433            
434 0           my @entries = ();
435 0 0         if($rawentries)
436             {
437 0           foreach my $entry (@{$rawentries})
  0            
438             {
439 0           my %hash = %{$entry};
  0            
440 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
441 0           push(@entries,$buzznetEntry);
442             }
443             }
444            
445 0           return @entries;
446            
447            
448             }
449            
450             sub browseBuzzwords
451             {
452 0     0     my $self = shift;
453 0           my $numberBuzzwords = shift;
454            
455 0           my $rawbuzzwords = $self->sendRequest(BROWSEBUZZWORDS,
456             RPC::XML::int->new($numberBuzzwords));
457            
458            
459 0           my @buzzwords = ();
460 0 0         if($rawbuzzwords)
461             {
462 0           foreach my $buzzword (@{$rawbuzzwords})
  0            
463             {
464 0           my %hash = %{$buzzword};
  0            
465 0           my $buzznetBuzzword = Buzznet::Buzzword->new(%hash);
466 0           push(@buzzwords,$buzznetBuzzword);
467             }
468             }
469            
470 0           return @buzzwords;
471             }
472            
473             sub updateProfile
474             {
475 0     0     my $self = shift;
476 0           my $profile = shift;
477            
478 0           return $self->sendRequest(UPDATEPROFILE,
479             RPC::XML::string->new($profile->password),
480             RPC::XML::string->new($profile->keyword),
481             RPC::XML::string->new($profile->fname),
482             RPC::XML::string->new($profile->lname),
483             RPC::XML::string->new($profile->email),
484             RPC::XML::string->new($profile->address),
485             RPC::XML::string->new($profile->city),
486             RPC::XML::string->new($profile->state),
487             RPC::XML::string->new($profile->zip),
488             RPC::XML::string->new($profile->country),
489             RPC::XML::string->new($profile->dob),
490             RPC::XML::string->new($profile->gender),
491             RPC::XML::string->new($profile->status));
492             }
493            
494             sub addFriend
495             {
496 0     0     my $self = shift;
497 0           my ($username, $order) = @_;
498            
499            
500 0           return $self->sendRequest(ADDFRIEND,
501             RPC::XML::string->new($username),
502             RPC::XML::int->new($order));
503            
504             }
505            
506             sub removeFriend
507             {
508 0     0     my $self = shift;
509 0           my $username = shift;
510            
511 0           return $self->sendRequest(REMOVEFRIEND, RPC::XML::string->new($username));
512             }
513            
514             sub getMyFriends
515             {
516 0     0     my $self = shift;
517            
518 0           my $rawfriends = $self->sendRequest(GETMYFRIENDS);
519            
520 0           my @friends = ();
521 0 0         if($rawfriends)
522             {
523 0           foreach my $friend (@{$rawfriends})
  0            
524             {
525 0           my %hash = %{$friend};
  0            
526 0           my $buzznetFriend = Buzznet::Profile->new(%hash);
527 0           push(@friends,$buzznetFriend);
528             }
529             }
530            
531 0           return @friends;
532             }
533            
534             sub getFriends
535             {
536 0     0     my $self = shift;
537 0           my $userId = shift;
538            
539 0           my $rawfriends = $self->sendRequest(GETFRIENDS, RPC::XML::int->new($userId));
540            
541 0           my @friends = ();
542 0 0         if($rawfriends)
543             {
544 0           foreach my $friend (@{$rawfriends})
  0            
545             {
546 0           my %hash = %{$friend};
  0            
547 0           my $buzznetFriend = Buzznet::Profile->new(%hash);
548 0           push(@friends,$buzznetFriend);
549             }
550             }
551            
552 0           return @friends;
553            
554             }
555            
556             sub getFriendsRecent
557             {
558 0     0     my $self = shift;
559 0           my $userId = shift;
560            
561 0           my $rawentries = $self->sendRequest(GETFRIENDSRECENT,
562             RPC::XML::int->new($userId));
563            
564            
565 0           my @entries = ();
566 0 0         if($rawentries)
567             {
568 0           foreach my $entry (@{$rawentries})
  0            
569             {
570 0           my %hash = %{$entry};
  0            
571 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
572 0           push(@entries,$buzznetEntry);
573             }
574             }
575            
576 0           return @entries;
577             }
578            
579             sub addBookmark
580             {
581 0     0     my $self = shift;
582 0           my ($entryId, $type, $order) = @_;
583            
584 0           return $self->sendRequest(ADDBOOKMARK,
585             RPC::XML::string->new($entryId),
586             RPC::XML::string->new($type),
587             RPC::XML::string->new($order));
588            
589             }
590            
591             sub removeBookmark
592             {
593 0     0     my $self = shift;
594 0           my ($entryId, $type) = @_;
595            
596 0           return $self->sendRequest(REMOVEBOOKMARK,
597             RPC::XML::string->new($entryId),
598             RPC::XML::string->new($type));
599             }
600            
601             sub getBookmarks
602             {
603 0     0     my $self = shift;
604            
605 0           my $rawentries = $self->sendRequest(GETBOOKMARKS);
606            
607            
608 0           my @entries = ();
609 0 0         if($rawentries)
610             {
611 0           foreach my $entry (@{$rawentries})
  0            
612             {
613 0           my %hash = %{$entry};
  0            
614 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
615 0           push(@entries,$buzznetEntry);
616             }
617             }
618            
619 0           return @entries;
620             }
621            
622             sub getMostPopular
623             {
624 0     0     my $self = shift;
625 0           my $type = shift;
626            
627 0           my $rawentries = $self->sendRequest(GETMOSTPOPULAR,
628             RPC::XML::string->new($type));
629            
630 0           my @entries = ();
631 0 0         if($rawentries)
632             {
633 0           foreach my $entry (@{$rawentries})
  0            
634             {
635 0           my %hash = %{$entry};
  0            
636 0           my $buzznetEntry = Buzznet::Entry->new(%hash);
637 0           push(@entries,$buzznetEntry);
638             }
639             }
640            
641 0           return @entries;
642             }
643            
644             sub getTodaysBirthdays
645             {
646 0     0     my $self = shift;
647            
648 0           my $rawbirthdays = $self->sendRequest(GETTODAYSBIRTHDAYS);
649            
650 0           my @birthdays = ();
651 0 0         if($rawbirthdays)
652             {
653 0           foreach my $birthday (@{$rawbirthdays})
  0            
654             {
655 0           my %hash = %{$birthday};
  0            
656 0           my $buzznetBirthday = Buzznet::Profile->new(%hash);
657 0           push(@birthdays,$buzznetBirthday);
658             }
659             }
660            
661 0           return @birthdays;
662             }
663            
664             sub getOnlineNow
665             {
666 0     0     my $self = shift;
667 0           my $rawonline = $self->sendRequest(GETONLINENOW);
668            
669 0           my @onlines = ();
670 0 0         if($rawonline)
671             {
672 0           foreach my $online (@{$rawonline})
  0            
673             {
674 0           my %hash = %{$online};
  0            
675 0           my $buzznetOnline = Buzznet::Profile->new(%hash);
676 0           push(@onlines,$buzznetOnline);
677             }
678             }
679            
680 0           return @onlines;
681             }
682            
683             sub getFeaturedUsers
684             {
685 0     0     my $self = shift;
686 0           my $numberUsers = shift;
687            
688 0           my $rawfeatured = $self->sendRequest(GETFEATUREDUSERS,
689             RPC::XML::int->new($numberUsers));
690            
691 0           my @featureds = ();
692 0 0         if($rawfeatured)
693             {
694 0           foreach my $featured (@{$rawfeatured})
  0            
695             {
696 0           my %hash = %{$featured};
  0            
697 0           my $buzznetFeatured = Buzznet::Profile->new(%hash);
698 0           push(@featureds,$buzznetFeatured);
699             }
700             }
701            
702 0           return @featureds;
703             }
704            
705             # Autoload methods go after =cut, and are processed by the autosplit program.
706            
707             1;
708             __END__