root/trunk/plagger/lib/Plagger/Plugin/Summary/HatenaBookmark.pm

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

merge from hackathon-summary

Line 
1 package Plagger::Plugin::Summary::HatenaBookmark;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Plagger::UserAgent;
6 use URI;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'summarizer.summarize' => \&summarize,
13     );
14 }
15
16 sub summarize {
17     my($self, $context, $args) = @_;
18
19     my $permalink = $args->{entry}->permalink;
20        $permalink =~ s/\#/%23/;
21     my $uri = "http://b.hatena.ne.jp/entry/rss/$permalink";
22
23     my $agent = Plagger::UserAgent->new;
24     my $summary;
25     eval {
26         my $feed = $agent->fetch_parse($uri);
27         $summary = $feed->tagline;
28     };
29
30     if ($@) {
31         $context->log(warn => "Fetch $uri failed: $@");
32         return;
33     }
34
35     return $summary;
36 }
37
38 1;
39 __END__
40
41 =head1 NAME
42
43 Plagger::Plugin::Summary::HatenaBookmark - Generate summary using Hatena Bookmark summary field
44
45 =head1 SYNOPSIS
46
47   - module: Summary::HatenaBookmark
48
49 =head1 DESCRIPTION
50
51 This plugin calls Hatena Bookmark Feed API (atomfeed) to get summary
52 from a certain web page.
53
54 =head1 AUTHOR
55
56 Tatsuhiko Miyagawa
57
58 =head1 SEE ALSO
59
60 L<Plagger>
61
62 =cut
Note: See TracBrowser for help on using the browser.