Weblog

« 目障りなはてなの犬め、消え去るがいい!!

Posted at 2006-08-18T13:14+09:00 in Development | livedoor clip で "P::P::Publish::MixiDiary" をクリップ | "P::P::Publish::MixiDiary" を含むはてなブックマークを表示 | del.icio.us で "P::P::Publish::MixiDiary" をブックマーク

初めての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 日記をつけたいな、とか思ったのがきっかけ。

P::P::Publish::MixiDiary #2 »

Recent entries from same category

同じカテゴリに分類された最近10件のエントリです。

  1. JavaScript を使って、クリックで展開するメニューを作ってみた
  2. 現在の環境
  3. Development Environment Conference 行ってきた
  4. keyconfig 拡張で del.icio.us にポストをハック
  5. keyconfig 拡張で Bloglines と Livedoor Reader にフィードを登録
  6. Subversionメモ #3
  7. Subversionメモ #2
  8. asin_plusプラグインの作り直し
  9. del.icio.usの見た目を変えるモンチッチ用ユーザスクリプト
  10. TrackBack pingを送信してみようかな、と。
Weblog archives
by Month