root/trunk/plagger/lib/Plagger/Plugin/Filter/HatenaDiaryKeywordLink.pm

Revision 201 (checked in by miyagawa, 15 years ago)

Filter::HatenaDiaryKeywordLink?: changed the log level. Fixed the pod

Line 
1 package Plagger::Plugin::Filter::HatenaDiaryKeywordLink;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use URI;
6 use XMLRPC::Lite;
7
8 our $XMLRPC_URL = 'http://d.hatena.ne.jp/xmlrpc';
9
10 sub register {
11     my($self, $context) = @_;
12     $context->register_hook(
13         $self,
14         'update.entry.fixup' => \&update,
15     );
16 }
17
18 sub update {
19     my($self, $context, $args) = @_;
20
21     $context->log(info => "hatena diary keyword auto link start : " . $args->{entry}->link);
22
23     my $rpc = XMLRPC::Lite->new;
24     $rpc->proxy($XMLRPC_URL);
25     my $body = $args->{entry}->body;
26
27     my $res = $rpc->call('hatena.setKeywordLink' => {
28         body => XMLRPC::Data->type('string', $body),
29         a_target => '_blank',
30         a_class => 'keyword',
31     });
32
33     if (my $fault = $res->fault){
34         for (keys %{$fault}){
35             $context->log(error => "hatena diary keyword auto link failed : $_ => " . $fault->{$_});
36         }
37     } else {
38         $body = $res->result;
39         $body =~ s/&lt;/</ig;
40         $body =~ s/&gt;/>/ig;
41         $body =~ s/&quot;/"/ig;
42     }
43
44     $args->{entry}->body($body);
45 }
46
47 1;
48
49 __END__
50
51 =head1 NAME
52
53 Plagger::Plugin::Filter::HatenaDiaryKeywordLink - HatenaDiary keyword link
54
55 =head1 SYNOPSIS
56
57   - module: Filter::HatenaDiaryKeywordLink
58
59 =head1 DESCRIPTION
60
61 This plugin queries Hatena Diary (L<http://d.hatena.ne.jp/>) using
62 its Keyword AutoLink API to link to hatena keyword.
63
64 =head1 AUTHOR
65
66 Tokuhiro Matsuno
67
68 =head1 SEE ALSO
69
70 L<Plagger>,
71 L<http://d.hatena.ne.jp/keyword/%A4%CF%A4%C6%A4%CA%A5%C0%A5%A4%A5%A2%A5%EA%A1%BC%A5%AD%A1%BC%A5%EF%A1%BC%A5%C9%BC%AB%C6%B0%A5%EA%A5%F3%A5%AFAPI>
72
73 =cut
74
Note: See TracBrowser for help on using the browser.