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

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

typo on PODs

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::Odeo;
2 use strict;
3 use base qw( Plagger::Plugin::Subscription::OPML );
4
5 use URI::Escape;
6 use HTML::Entities;
7
8 sub register {
9     my($self, $context) = @_;
10
11     $context->register_hook(
12         $self,
13         'subscription.load' => \&load,
14     );
15 }
16
17 sub load {
18     my($self, $context) = @_;
19
20     my $account = $self->conf->{account}
21         or $context->error("config 'account' is missing");
22
23     my $uri = URI->new("http://www.odeo.com/profile/$account/opml.xml");
24     $context->log(debug => "Fetch remote OPML from $uri");
25
26     my $response = Plagger::UserAgent->new->get($uri);
27     unless ($response->is_success) {
28         $context->error("Fetch $uri failed: ". $response->status_line);
29     }
30
31     my $xml = $response->content;
32
33     # fix Odeo's bad OPML
34     $xml =~ s{<outline text="(.*?)" type="link" url="(http://.*?)" count="(\d+)"/>}{
35         my($title, $url, $count) = ($1, $2, $3);
36
37         $title = uri_unescape($title);
38         $title =~ s/\r\n//g;
39         $title =~ tr/\+/ /;
40         $title = encode_html($title);
41         $url   = encode_html($url);
42
43         qq(<outline text="$title" type="rss" xmlUrl="$url" count="$count"/>)
44     }eg;
45
46     $self->load_opml($context, \$xml);
47 }
48
49 sub encode_html {
50     HTML::Entities::encode($_[0], q("<>&));
51 }
52
53 1;
54
55 __END__
56
57 =head1 NAME
58
59 Plagger::Plugin::Subscription::Odeo - Odeo Subscription via OPML
60
61 =head1 SYNOPSIS
62
63   - module: Subscription::Odeo
64     config:
65       account: TatsuhikoMiyagawa
66
67 =head1 DESCRIPTION
68
69 This plugin creates Subscription by fetching Odeo
70 L<http://www.odeo.com/> OPML by HTTP.
71
72 =head1 NOTE
73
74 We should probably better use C<rss.xml> or C<pcast.xml> they provide and
75 synchronizes enclosures as well, ala Bloglines Subscription plugin.
76
77 =head1 AUTHOR
78
79 Tatsuhiko Miyagawa
80
81 =head1 SEE ALSO
82
83 L<Plagger>, L<Plagger::Plugin::Subscription::OPML>
84
85 =cut
86
Note: See TracBrowser for help on using the browser.