| 1 | package Plagger::Plugin::Publish::Wassr; |
|---|
| 2 | use strict; |
|---|
| 3 | use base qw( Plagger::Plugin ); |
|---|
| 4 | |
|---|
| 5 | use Encode; |
|---|
| 6 | use Net::Wassr; |
|---|
| 7 | use Time::HiRes qw(sleep); |
|---|
| 8 | |
|---|
| 9 | sub register { |
|---|
| 10 | my($self, $context) = @_; |
|---|
| 11 | $context->register_hook( |
|---|
| 12 | $self, |
|---|
| 13 | 'publish.entry' => \&publish_entry, |
|---|
| 14 | 'plugin.init' => \&initialize, |
|---|
| 15 | ); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | sub 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 | |
|---|
| 30 | sub 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 | |
|---|
| 53 | 1; |
|---|
| 54 | __END__ |
|---|
| 55 | |
|---|
| 56 | =head1 NAME |
|---|
| 57 | |
|---|
| 58 | Plagger::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 | |
|---|
| 71 | This plugin sends feed entries summary to your Wassr account status. |
|---|
| 72 | |
|---|
| 73 | =head1 CONFIG |
|---|
| 74 | |
|---|
| 75 | =over 4 |
|---|
| 76 | |
|---|
| 77 | =item username |
|---|
| 78 | |
|---|
| 79 | Wassr username. Required. |
|---|
| 80 | |
|---|
| 81 | =item password |
|---|
| 82 | |
|---|
| 83 | Wassr password. Required. |
|---|
| 84 | |
|---|
| 85 | =item interval |
|---|
| 86 | |
|---|
| 87 | Optional. |
|---|
| 88 | |
|---|
| 89 | =item apiurl |
|---|
| 90 | |
|---|
| 91 | OPTIONAL. 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 | |
|---|
| 97 | Optional. |
|---|
| 98 | If 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 | |
|---|
| 107 | Yasuhiro Matsumoto |
|---|
| 108 | SHIBATA Hiroshi |
|---|
| 109 | |
|---|
| 110 | =head1 SEE ALSO |
|---|
| 111 | |
|---|
| 112 | L<Plagger>, L<Net::Wassr> |
|---|
| 113 | |
|---|
| 114 | =cut |
|---|