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

Revision 1768 (checked in by miyagawa, 14 years ago)

Filter::HatenaBookmarkUsersCount?: splice by 50 links. via http://subtech.g.hatena.ne.jp/otsune/20061016/HatenaBookmarkAPIfix

  • 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     while (my @links = splice(@permalink, 0, 50)) {
21         $context->log(info => 'Requesting XMLRPC call to Hatena Bookmark with ' . scalar(@links) . ' link(s)');
22
23         my $map = XMLRPC::Lite
24             ->proxy('http://b.hatena.ne.jp/xmlrpc')
25             ->call('bookmark.getCount', @links)
26             ->result;
27
28         unless ($map) {
29             $context->log(warn => 'Hatena Bookmark XMLRPC failed');
30             return;
31         }
32
33         $context->log(info => 'XMLRPC request success.');
34
35         for my $entry ($args->{feed}->entries) {
36             if (defined(my $count = $map->{$entry->permalink})) {
37                 $entry->meta->{hatenabookmark_users} = $count;
38             }
39         }
40     }
41 }
42
43 1;
44
45 __END__
46
47 =head1 NAME
48
49 Plagger::Plugin::Filter::HatenaBookmarkUsersCount - Queries Hatena Bookmark users count
50
51 =head1 SYNOPSIS
52
53   - module: Filter::HatenaBookmarkUsersCount
54
55 =head1 DESCRIPTION
56
57 This plugin queries Hatena Bookmark (L<http://b.hatena.ne.jp/>) how
58 many people bookmarked each of feed entries, using its XMLRPC API
59 C<bookmark.getCount>.
60
61 Users count is stored in C<hatenabookmark_users> metadata of
62 Plagger::Entry so that other plugins or smartfeeds can make use of.
63
64 =head1 AUTHOR
65
66 Kazuhiro Osawa, Tatsuhiko Miyagawa
67
68 =head1 SEE ALSO
69
70 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>
71
72 =cut
Note: See TracBrowser for help on using the browser.