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

Revision 1942 (checked in by tokuhirom, 13 years ago)

Plugin::Twitter: you can set the different API URL/HOST, for Twitter Compatible API Services(e.g. Frepa, Caspeee)

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     my %opt = (
19         username => $self->conf->{username},
20         password => $self->conf->{password},
21     );
22     for my $key (qw/ apihost apiurl apirealm/) {
23         $opt{$key} = $self->conf->{$key} if $self->conf->{$key};
24     }
25     $self->{twitter} = Net::Twitter->new(%opt);
26 }
27
28 sub publish_entry {
29     my($self, $context, $args) = @_;
30
31     my $body = ( $args->{entry}->summary || $args->{entry}->title ) . " " . $args->{entry}->permalink;
32     $context->log(info => "Updating Twitter status to '$body'");
33     $self->{twitter}->update($body) or $context->error("Can't update twitter status");
34 }
35
36 1;
37 __END__
38
39 =head1 NAME
40
41 Plagger::Plugin::Publish::Twitter - Update your status with feeds
42
43 =head1 SYNOPSIS
44
45   - module: Publish::Twitter
46     config:
47       username: twitter-id
48       password: twitter-password
49
50 =head1 DESCRIPTION
51
52 This plugin sends feed entries summary to your Twitter account status.
53
54 =head1 CONFIG
55
56 =over 4
57
58 =item username
59
60 Twitter username. Required.
61
62 =item password
63
64 Twitter password. Required.
65
66 =item apiurl
67
68 OPTIONAL. The URL of the API for twitter.com. This defaults to "http://twitter.com/statuses" if not set.
69
70 =item apihost
71
72 =item apirealm
73
74 Optional.
75 If you do point to a different URL, you will also need to set "apihost" and "apirealm" so that the internal LWP can authenticate.
76
77     "apihost" defaults to "www.twitter.com:80".
78     "apirealm" defaults to "Twitter API".
79
80 =back
81
82 =head1 AUTHOR
83
84 Tatsuhiko Miyagawa
85
86 =head1 SEE ALSO
87
88 L<Plagger>, L<Net::Twitter>
89
90 =cut
Note: See TracBrowser for help on using the browser.