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

Revision 810 (checked in by miyagawa, 14 years ago)
  • added Plagger::Mechanize for a wrapper class around WWW::Mech (to set User-Agent from global config)
  • Updated plugins to use Plagger::Mechanize where WWW::Mech was used.
  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::HatenaRSS;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::OPML );
4
5 use Plagger::Mechanize;
6
7 sub register {
8     my($self, $context) = @_;
9
10     $context->register_hook(
11         $self,
12         'subscription.load' => \&load,
13     );
14 }
15
16 sub load {
17     my($self, $context) = @_;
18
19     my $username = $self->conf->{username}
20         or $context->error('username is missing');
21
22     my $start = "https://www.hatena.ne.jp/login?backurl=http%3A%2F%2Fr.hatena.ne.jp%2F";
23
24     # support cookie_jar
25     my $mech = Plagger::Mechanize->new;
26     $mech->get($start);
27
28     $mech->submit_form(
29         fields => {
30             key      => $username,
31             password => $self->conf->{password},
32         },
33     );
34
35     if ( $mech->content =~ m!<div class="error">! ) {
36         $context->log(error => "Login to HatenaRSS failed.");
37         return;
38     }
39
40     $context->log(info => "Login to HatenaRSS succeed.");
41
42     $mech->get("http://r.hatena.ne.jp/$username/config");
43     $mech->submit_form(form_name => 'opmlexport');
44
45     my $opml = $mech->content;
46     $context->log(info => "Exported OPML: " . length($opml) . " bytes");
47
48     $self->load_opml($context, \$opml);
49 }
50
51 1;
52
53 __END__
54
55 =head1 NAME
56
57 Plagger::Plugin::Subscription::HatenaRSS - HatenaRSS Subscription via OPML
58
59 =head1 SYNOPSIS
60
61   - module: Subscription::HatenaRSS
62     config:
63       username: example
64       password: xxxxxxxx
65
66 =head1 DESCRIPTION
67
68 This plugin creates Subscription by fetching Hatena RSS
69 L<http://r.hatena.ne.jp> OPML by HTTP. Since Hatena RSS OPML export
70 requires login state, it uses WWW::Mechanize module to emulate the
71 browser's login authentication procedure.
72
73 =head1 AUTHOR
74
75 Tatsuhiko Miyagawa
76
77 =head1 SEE ALSO
78
79 L<Plagger>, L<Plagger::Plugin::Subscription::OPML>, L<WWW::Mechanize>
80
81 =cut
Note: See TracBrowser for help on using the browser.