root/trunk/plagger/lib/Plagger/Plugin/Publish/Twitter.pm

Revision 1934 (checked in by miyagawa, 13 years ago)

shiny new Publish::Twitter!

Line 
1 package Plagger::Plugin::Publish::Twitter;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Net::Twitter;
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'publish.entry' => \&publish_entry,
12         'plugin.init'   => \&initialize,
13     );
14 }
15
16 sub initialize {
17     my($self, $context) = @_;
18     $self->{twitter} = Net::Twitter->new(
19         username => $self->conf->{username},
20         password => $self->conf->{password},
21     );
22 }
23
24 sub publish_entry {
25     my($self, $context, $args) = @_;
26
27     my $body = ( $args->{entry}->summary || $args->{entry}->title ) . " " . $args->{entry}->permalink;
28     $context->log(info => "Updating Twitter status to '$body'");
29     $self->{twitter}->update($body);
30 }
31
32 1;
33 __END__
34
35 =head1 NAME
36
37 Plagger::Plugin::Publish::Twitter - Update your status with feeds
38
39 =head1 SYNOPSIS
40
41   - module: Publish::Twitter
42     config:
43       username: twitter-id
44       password: twitter-password
45
46 =head1 DESCRIPTION
47
48 This plugin sends feed entries summary to your Twitter account status.
49
50 =head1 CONFIG
51
52 =over 4
53
54 =item username
55
56 Twitter username. Required.
57
58 =item password
59
60 Twitter password. Required.
61
62 =back
63
64 =head1 AUTHOR
65
66 Tatsuhiko Miyagawa
67
68 =head1 SEE ALSO
69
70 L<Plagger>, L<Net::Twitter>
71
72 =cut
Note: See TracBrowser for help on using the browser.