root/trunk/plagger/lib/Plagger/Plugin/Filter/HatenaBookmarkUsersCount.pm

Revision 189 (checked in by miyagawa, 15 years ago)

Added docs to some plugins

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Filter::HatenaBookmarkUsersCount;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use XMLRPC::Lite;
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'update.feed.fixup' => \&update,
12     );
13 }
14
15 sub update {
16     my($self, $context, $args) = @_;
17
18     my @permalink = map $_->permalink, $args->{feed}->entries;
19
20     $context->log(info => 'Requesting XMLRPC call to Hatena Bookmark with ' . scalar(@permalink) . ' link(s)');
21
22     my $map = XMLRPC::Lite
23         ->proxy('http://b.hatena.ne.jp/xmlrpc')
24         ->call('bookmark.getCount', @permalink)
25         ->result;
26
27     unless ($map) {
28         $context->log(warn => 'Hatena Bookmark XMLRPC failed');
29         return;
30     }
31
32     $context->log(info => 'XMLRPC request success.');
33
34     for my $entry ($args->{feed}->entries) {
35         if (defined(my $count = $map->{$entry->permalink})) {
36             $entry->meta->{hatenabookmark_users} = $count;
37         }
38     }
39 }
40
41 1;
42
43 __END__
44
45 =head1 NAME
46
47 Plagger::Plugin::Filter::HatenaBookmarkUsersCount - Queries Hatena Bookmark users count
48
49 =head1 SYNOPSIS
50
51   - module: Filter::HatenaBookmarkUsersCount
52
53 =head1 DESCRIPTION
54
55 This plugin queries Hatena Bookmark (L<http://b.hatena.ne.jp/>) how
56 many people bookmarked each of feed entries, using its XMLRPC API
57 C<bookmark.getCount>.
58
59 Users count is stored in C<hatenabookmark_users> metadata of
60 Plagger::Entry so that other plugins or smartfeeds can make use of.
61
62 =head1 AUTHOR
63
64 Kazuhiro Osawa, Tatsuhiko Miyagawa
65
66 =head1 SEE ALSO
67
68 L<Plagger>, L<http://d.hatena.ne.jp/keyword/%A4%CF%A4%C6%A4%CA%A5%D6%A5%C3%A5%AF%A5%DE%A1%BC%A5%AF%B7%EF%BF%F4%BC%E8%C6%C0API>
69
70 =cut
Note: See TracBrowser for help on using the browser.