root/trunk/plagger/lib/Plagger/Plugin/Notify/UpdatePing.pm

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

Notify::UpdatePing?: support weblogUpdates.extendedPing. Fixes #419

Line 
1 package Plagger::Plugin::Notify::UpdatePing;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use XMLRPC::Lite;
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'publish.feed' => \&feed,
12     );
13 }
14
15 sub feed {
16     my($self, $context, $args) = @_;
17
18     my $feed = $args->{feed};
19
20     my $urls = $self->conf->{url};
21     $urls = [ $urls ] unless ref $urls;
22
23     my @args = (XMLRPC::Data->type(string => $feed->title), $feed->link);
24     my $method;
25     if ($self->conf->{extended_ping}) {
26         $method = 'weblogUpdates.extendedPing';
27         push @args, $feed->count ? $feed->entries->[0]->permalink : $feed->link;
28         push @args, $feed->url;
29         push @args, join("|", map XMLRPC::Data->type(string => $_), @{ $feed->tags })
30             if @{ $feed->tags };
31     } else {
32         $method = 'weblogUpdates.ping';
33     }
34
35     for my $url (@$urls) {
36         $context->log(info => "Ping " . $feed->link . " to $url");
37         my $res = eval {
38             XMLRPC::Lite->new->proxy($url)->call($method, @args)->result;
39         };
40         if (my $err = $@ || $res->{flerror}) {
41             $context->log(error => "Error sending UpdatePing: $err");
42         }
43     }
44 }
45
46 1;
47
48 __END__
49
50 =head1 NAME
51
52 Plagger::Plugin::Notify::UpdatePing - Notify updates via XMLRPC update ping
53
54 =head1 SYNOPSIS
55
56   - module: Notify::UpdatePing
57     config:
58       url: http://www.bloglines.com/ping
59
60 =head1 DESCRIPTION
61
62 This plugin notifies feed updates to update ping servers using XML-RPC.
63
64 =head1 CONFIG
65
66 =over 4
67
68 =item extended_ping
69
70   extended_ping: 1
71
72 Whether to use I<weblogUpdates.extendedPing> method for extra
73 information. Defaults to 0.
74
75 =back
76
77 =head1 AUTHOR
78
79 Tatsuhiko Miyagawa
80
81 =head1 SEE ALSO
82
83 L<Plagger>, L<XMLRPC::Lite>
84
85 =cut
Note: See TracBrowser for help on using the browser.