root/trunk/plagger/lib/Plagger/Plugin/Subscription/HatenaGroup.pm

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

use FeedParser? and UserAgent? in Subscription::HatenaGroup?

Line 
1 package Plagger::Plugin::Subscription::HatenaGroup;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use URI;
6 use Plagger::FeedParser;
7 use Plagger::UserAgent;
8
9 sub register {
10     my($self, $context) = @_;
11
12     $context->register_hook(
13         $self,
14         'subscription.load' => \&load,
15     );
16 }
17
18 sub load {
19     my($self, $context) = @_;
20
21     my $group = $self->conf->{group}
22         or $context->error('group is missing');
23
24     my $feed_uri = "http://$group.g.hatena.ne.jp/diarylist?mode=rss";
25
26     my $agent = Plagger::UserAgent->new;
27     my $remote = eval { $agent->fetch_parse(URI->new($feed_uri)) }
28         or $context->error("feed parse error $feed_uri: $@");
29     for my $r ($remote->entries) {
30         $context->log(info => "diary: ". $r->link);
31
32         my $feed = Plagger::Feed->new;
33         $feed->url($r->link . "rss");
34         $feed->link($r->link);
35         $feed->title($r->title);
36         $context->subscription->add($feed);
37     }
38 }
39
40 1;
41
42 __END__
43
44 =head1 NAME
45
46 Plagger::Plugin::Subscription::HatenaGroup - HatenaGroup Subscription via RSS
47
48 =head1 SYNOPSIS
49
50   - module: Subscription::HatenaGroup
51     config:
52       group: subtech
53
54 =head1 DESCRIPTION
55
56 Subscription from Hatena Group.
57
58 =head1 AUTHOR
59
60 Tokuhiro Matsuno
61
62 =head1 SEE ALSO
63
64 L<Plagger>, L<XML::Feed>
65
66 =cut
Note: See TracBrowser for help on using the browser.