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

Revision 436 (checked in by ko, 14 years ago)

Added new plugin Subscription::PingServer?

Line 
1 package Plagger::Plugin::Subscription::PingServer;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use HTML::RSSAutodiscovery;
6 use List::Util qw(first);
7 use Plagger::UserAgent;
8 use XML::LibXML;
9
10 sub register {
11     my($self, $context) = @_;
12
13     $context->register_hook(
14         $self,
15         'subscription.load' => \&load,
16     );
17 }
18
19 sub load {
20     my($self, $context) = @_;
21
22     my $servers = $self->conf->{servers};
23        $servers = [ $servers ] unless ref $servers;
24
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 $feed->url;
41             $context->log(debug => "get url: $url");
42
43             my $feed = Plagger::Feed->new;
44             $feed->url($url);
45             $feed->link($url);
46             $feed->title(first { $_ } $node->findvalue('@name') || $url);
47
48             last if $context->subscription->add($feed) >= $items;
49         }
50     }
51 }
52
53 1;
54
55 __END__
56
57 =head1 NAME
58
59 Plagger::Plugin::Subscription::PingServer - Subscription from ping servers
60
61 =head1 SYNOPSIS
62
63     - module: Subscription::PingServer
64       config:
65         fetch_items: 20
66         servers:
67           - url: http://ping.bloggers.jp/changes.xml?last=100
68
69 =head1 DESCRIPTION
70
71 This plugin allows you to pingserver your subscription in C<config.yaml>.
72
73 =head1 AUTHOR
74
75 Kazuhiro Osawa
76
77 =head1 SEE ALSO
78
79 L<Plagger>
80
81 =cut
Note: See TracBrowser for help on using the browser.