P::P::Publish::MixiDiary
Posted at 2006-08-18T13:14+09:00 in Development |
|
| ![]()
初めてのPlaggerプラグイン。
package Plagger::Plugin::Publish::MixiDiary;
use strict;
use base qw ( Plagger::Plugin );
use WWW::Mixi;
use Encode;
sub register {
my($self, $context) = @_;
$context->register_hook(
$self,
'publish.init' => \&initialize,
'publish.entry' => \&post_diary,
);
}
sub initialize {
my($self, $context, $args) = @_;
my $cookie_jar = $self->cookie_jar;
if (ref($cookie_jar) ne 'HTTP::Cookies') {
$self->conf->{username} ||= 'email@example.com',
$self->conf->{password} ||= 'p4ssw0rd',
}
$self->{mixi} = WWW::Mixi->new(
$self->conf->{username},
$self->conf->{password},
-log => 0,
);
$self->{mixi}->cookie_jar($cookie_jar);
unless ($self->{mixi}->login) {
$context->log(error => "Login failed.");
} else {
$context->log(info => "Login Successed.");
}
}
sub post_diary {
my($self, $context, $args) = @_;
my $title = $args->{entry}->title;
my $body = $args->{entry}->body_text;
my %diary = (
diary_title => encode('euc-jp', $title),
diary_body => encode('euc-jp', $body),
);
if ($self->{mixi}->get_add_diary_confirm(%diary)) {
$context->log(info => "Making diary succeeded.");
} else {
$context->log(error => "Making diary failed.");
}
}
1;
__END__
=hea1 NAME
Plagger::Plugin::Publish::MixiDiary - publish mixi diary
=head1 SYNOPSIS
- module: Publish::MixiDiary
config:
username: email@example.com
password: p4ssw0rd
=head1 DESCRIPTION
This plugin posts entry to mixi diary.
=over 4
=item username, password
Your e-mail and password for logging in mixi
=back
=cut
=head1 AUTHOR
Tsuyoshi Maekawa
=head1 SEE ALSO
L<Plagger>, L<WWW::Mixi>, L<http://mixi.jp/>
=cut
P::P::CustomFeed::ChangeLogを使って mixi 日記をつけたいな、とか思ったのがきっかけ。