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

Revision 1915 (checked in by miyagawa, 1 year ago)

shiny Notify::Lingr!

Line 
1 package Plagger::Plugin::Notify::Lingr;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Encode;
6 use POE::Component::IKC::ClientLite;
7
8 sub register {
9     my($self, $context) = @_;
10     $context->register_hook(
11         $self,
12         'publish.entry' => \&update,
13         'plugin.init'   => \&initialize,
14     );
15 }
16
17 sub initialize {
18     my($self, $context, $args) = @_;
19
20     my $host = $self->conf->{daemon_host} || 'localhost',
21     my $port = $self->conf->{daemon_port} || 9998;
22
23     $self->{remote} = POE::Component::IKC::ClientLite::create_ikc_client(
24         port    => $port,
25         ip      => $host,
26         name    => 'Plagger' . $$,
27         timeout => 5,
28     );
29
30     unless ($self->{remote}) {
31         my $msg = q{unable to connect to plagger-lingrbot process on }
32             . "$host:$port"
33             . q{, if you're not running plagger-lingrbot, you should be able }
34             . q{to start it with the same Notify::Lingr config you passed to }
35             . q{plagger. };
36         $context->log( error => $msg );
37         return;
38     }
39 }
40
41 sub update {
42     my($self, $context, $args) = @_;
43
44     $context->log(info => "Notifying " . $args->{entry}->title . " to Lingr");
45
46     my $body = $self->templatize('notify.tt', $args);
47     Encode::_utf8_off($body) if Encode::is_utf8($body);
48     for my $line (split("\n", $body)) {
49         $self->{remote}->post( 'notify_lingr/update', $line );
50     }
51 }
52
53 1;
54 __END__
55
56 =head1 NAME
57
58 Plagger::Plugin::Notify::Lingr - Notify feed updates to Lingr
59
60 =head1 SYNOPSIS
61
62   - module: Notify::Lingr
63     config:
64       api_key:  YOUR_API_KEY
65       room:     plagger
66       nickname: Plaggerbot
67
68 =head1 DESCRIPTION
69
70 This plugin notifies updates to Lingr using POE::Component::Client::Lingr module.
71
72 =head1 CONFIG
73
74 =over 4
75
76 =item api_key
77
78 Your Lingr API Key. Required.
79
80 =item room
81
82 Room to enter and notify the updates. Required.
83
84 =item nickname
85
86 Nickname for your bot. Defaults to I<plaggerbot>.
87
88 =back
89
90 =head1 AUTHOR
91
92 Tatsuhiko Miyagawa
93
94 =head1 SEE ALSO
95
96 L<Plagger>, L<POE::Component::Client::Lingr>
97
98 =cut
99
Note: See TracBrowser for help on using the browser.