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

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

Subscription::PingServer? doesn't need HTML::RSSAutodiscovery

Line 
1 package Plagger::Plugin::Subscription::PingServer;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use List::Util qw(first);
6 use Plagger::UserAgent;
7 use XML::LibXML;
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 $servers = $self->conf->{servers};
22        $servers = [ $servers ] unless ref $servers;
23
24     my %cache;
25     for my $server (@{ $servers }) {
26         my $agent    = Plagger::UserAgent->new;
27         my $response = $agent->fetch($server->{url});
28         if ($response->is_error) {
29             $context->log(error => "GET $server->{url} failed: " .
30                           $response->http_status . " " .
31                           $response->http_response->message);
32             return;
33         }
34
35         my $link;
36         my $doc = XML::LibXML->new->parse_string($response->content);
37         my $items = $self->conf->{fetch_items} || 20;
38         for my $node ( $doc->findnodes('/weblogUpdates/weblog')) {
39             my $url = first { $_ } $node->findvalue('@url');
40             next unless $url;
41             next if $cache{$url}++;
42             $context->log(debug => "get url: $url");
43
44             my $feed = Plagger::Feed->new;
45             $feed->url($url);
46             $feed->link($url);
47             $feed->title(first { $_ } $node->findvalue('@name') || $url);
48
49             last if $context->subscription->add($feed) >= $items;
50         }
51     }
52 }
53
54 1;
55
56 __END__
57
58 =head1 NAME
59
60 Plagger::Plugin::Subscription::PingServer - Subscription from ping servers
61
62 =head1 SYNOPSIS
63
64     - module: Subscription::PingServer
65       config:
66         fetch_items: 20
67         servers:
68           - url: http://ping.bloggers.jp/changes.xml?last=100
69
70 =head1 DESCRIPTION
71
72 This plugin allows you to pingserver your subscription in C<config.yaml>.
73
74 =head1 AUTHOR
75
76 Kazuhiro Osawa
77
78 =head1 SEE ALSO
79
80 L<Plagger>
81
82 =cut
Note: See TracBrowser for help on using the browser.