root/lang/perl/plagger/lib/Plagger/Plugin/Publish/Wassr.pm

Revision 18912, 2.4 kB (checked in by hsbt, 3 months ago)

fix bug. is uninitialized.

Line 
1package Plagger::Plugin::Publish::Wassr;
2use strict;
3use base qw( Plagger::Plugin );
4
5use Encode;
6use Net::Wassr;
7use Time::HiRes qw(sleep);
8
9sub register {
10    my($self, $context) = @_;
11    $context->register_hook(
12        $self,
13        'publish.entry' => \&publish_entry,
14        'plugin.init'   => \&initialize,
15    );
16}
17
18sub initialize {
19    my($self, $context) = @_;
20    my %opt = (
21        user => $self->conf->{username},
22        passwd => $self->conf->{password},
23    );
24    for my $key (qw/ apihost apiurl apirealm/) {
25        $opt{$key} = $self->conf->{$key} if $self->conf->{$key};
26    }
27    $self->{wassr} = Net::Wassr->new(%opt);
28}
29
30sub publish_entry {
31    my($self, $context, $args) = @_;
32    my $body = $args->{entry}->body_text;
33
34    if ($self->conf->{templatize}) {
35        $body = $self->templatize('wassr.tt', $args);
36    }
37
38    # TODO: FIX when Summary configurable.
39    if ( length($body) > 159 ) {
40        $body = substr($body, 0, 159);
41    }
42    $context->log(info => "Updating Wassr status to '$body'");
43    if ($self->conf->{channel}) {
44        $self->{wassr}->channel_update( {name_en => $self->conf->{channel}, body => encode_utf8($body)} ) or $context->error("Can't update wassr status");
45    } else {
46        $self->{wassr}->update( {status => encode_utf8($body)} ) or $context->error("Can't update wassr status");
47    }
48    my $sleeping_time = $self->conf->{interval} || 15;
49    $context->log(info => "sleep $sleeping_time.");
50    sleep( $sleeping_time );
51}
52
531;
54__END__
55
56=head1 NAME
57
58Plagger::Plugin::Publish::Wassr - Update your status with feeds
59
60=head1 SYNOPSIS
61
62  - module: Publish::Wassr
63    config:
64      username: wassr-id
65      password: wassr-password
66      channel: name_en
67      templatize: 1
68
69=head1 DESCRIPTION
70
71This plugin sends feed entries summary to your Wassr account status.
72
73=head1 CONFIG
74
75=over 4
76
77=item username
78
79Wassr username. Required.
80
81=item password
82
83Wassr password. Required.
84
85=item interval
86
87Optional.
88
89=item apiurl
90
91OPTIONAL. The URL of the API for wassr.jp. This defaults to "http://wassr.jp/user/xxx/statuses" if not set.
92
93=item apihost
94
95=item apirealm
96
97Optional.
98If you do point to a different URL, you will also need to set "apihost" and "apirealm" so that the internal LWP can authenticate.
99
100    "apihost" defaults to "api.wassr.jp:80".
101    "apirealm" defaults to "API Authentication".
102
103=back
104
105=head1 AUTHOR
106
107Yasuhiro Matsumoto
108SHIBATA Hiroshi
109
110=head1 SEE ALSO
111
112L<Plagger>, L<Net::Wassr>
113
114=cut
Note: See TracBrowser for help on using the browser.