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

Revision 16904, 2.1 kB (checked in by mattn, 11 months ago)

not content! it's summary!

Line 
1package Plagger::Plugin::Publish::MixiDiary;
2use strict;
3use base qw( Plagger::Plugin );
4
5use Encode;
6use Atompub::Client;
7use XML::Atom::Entry;
8use Time::HiRes qw(sleep);
9
10sub register {
11    my($self, $context) = @_;
12    $context->register_hook(
13        $self,
14        'publish.entry' => \&publish_entry,
15        'plugin.init'   => \&initialize,
16    );
17}
18
19sub initialize {
20    my($self, $context) = @_;
21    unless ($self->{client}) {
22        my $client = Atompub::Client->new;
23        $client->username($self->conf->{username});
24        $client->password($self->conf->{password});
25        my $service = $client->getService('http://mixi.jp/atom/diary/');
26        my @workspaces = $service->workspaces;
27        my @collections = $workspaces[0]->collections;
28        $self->{client} = $client;
29        $self->{PostURI} = $collections[0]->href;
30    }
31    1;
32}
33
34sub publish_entry {
35    my($self, $context, $args) = @_;
36
37    $context->log(info => "updating mixi diary");
38
39    my $entry = XML::Atom::Entry->new;
40    $entry->title( encode_utf8( $args->{entry}->title ) );
41
42    my $link  = XML::Atom::Link->new;
43    $link->rel('related');
44    $link->type('text/html');
45    $link->href($args->{entry}->link);
46    $entry->add_link($link);
47    $entry->summary( encode_utf8( $args->{entry}->body_text ) );
48
49    $self->{client}->createEntry($self->{PostURI}, $entry)
50            or $context->log(info => "can't submit: " . $self->{client}->errstr);
51
52    my $sleeping_time = $self->conf->{interval} || 3;
53    $context->log(info => "sleep $sleeping_time.");
54    sleep( $sleeping_time );
55}
56
571;
58__END__
59
60=head1 NAME
61
62Plagger::Plugin::Publish::MixiDiary - Update your mixi diary with feeds
63
64=head1 SYNOPSIS
65
66  - module: Publish::MixiDiary
67    config:
68      username: mixi-id
69      password: mixi-password
70
71=head1 DESCRIPTION
72
73This plugin sends feed entries summary to your mixi diary.
74
75=head1 CONFIG
76
77=over 4
78
79=item username
80
81mixi username. Required.
82
83=item password
84
85mixi password. Required.
86
87=item interval
88
89=back
90
91=head1 AUTHOR
92
93Yasuhiro Matsumoto
94
95=head1 SEE ALSO
96
97L<Plagger>, L<Atompub::Client>, L<XML::Atom::Entry>
98
99=cut
Note: See TracBrowser for help on using the browser.