otsune's SnakeOil RSSフィード

python -c "print''.join([chr(x) for x in 111&1101,110+~-~11,10^11*11,110+~-~11,-~101,-~11^11*11,~-110,111&11*11,11+11+10,11|~-0110,1-~11^11*11,10^11*11,-~11^11*11,110,101])"

2007-05-16

CPANモジュール使ったPublish::Buzzurlを書いた

| CPANモジュール使ったPublish::Buzzurlを書いた - otsune's SnakeOil  を含むブックマーク はてなブックマーク - CPANモジュール使ったPublish::Buzzurlを書いた - otsune's SnakeOil  CPANモジュール使ったPublish::Buzzurlを書いた - otsune's SnakeOil  のブックマークコメント

Publish::Buzzurl試し(メモ) - otsune's SnakeOil - subtechの続き。WebService::BuzzurlAPIを使った版。

余談だけど、Mac OS X 10.4.9のシステム標準がperl5.8.6なのでMacユーザーだと使えないという問題が。

(オレはmacportsからlang/perl5.8入れているから良いけど、それは酷だよな)

lib/Plagger/Plugin/Publish/Buzzurl.pm

package Plagger::Plugin::Publish::Buzzurl;
use strict;
use base qw( Plagger::Plugin );

use WebService::BuzzurlAPI;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'plugin.init'   => \&initialize,
        'publish.entry' => \&add_entry,
    );
}

sub rule_hook { 'publish.entry' }

sub initialize {
    my ($self, $context, $args) = @_;
    $self->{buzzurl} = WebService::BuzzurlAPI->new(
        email    => $self->conf->{usermail},
        password => $self->conf->{password},
    );
}

sub add_entry {
    my($self, $context, $args) = @_;

    my $params = {
        url     => $args->{entry}->link,
        title   => $args->{entry}->title,
        keyword => $args->{entry}->tags,
    };

    if ($self->conf->{post_body}) {
        $params->{comment} = $args->{entry}->body_text,
    }

    my $res = $self->{buzzurl}->add(%{$params});

    if ($res->is_success) {
        $context->log(info  => "Post entry success :" . $res->json->{status});
    }else{
        $context->log(error => $res->errstr);
    }

    my $sleeping_time = $self->conf->{interval} || 2;
    $context->log(info => "Post entry success. sleep $sleeping_time.");
    sleep( $sleeping_time );
}

1;

__END__

=head1 NAME

Plagger::Plugin::Publish::Buzzurl - Post to Buzzurl automatically

=head1 SYNOPSIS

  - module: Publish::Buzzurl
    config:
      usermail: your-email
      password: your-password
      interval: 2
      post_body: 1

=head1 DESCRIPTION

This plugin posts feed updates to Buzzurl, using its REST API.

=head1 CONFIGURATION

=over 4

=item usermail, password

Your login and password for logging in Buzzurl

=item interval

Interval (as seconds) to sleep after posting each bookmark. Defaults to 2.

=item post_body

A flag to post entry's body as extended field for Buzzurl. Defaults to 0.

=back

=cut

=head1 AUTHOR

Masafumi Otsune

=head1 SEE ALSO

L<Plagger>, L<WebService::BuzzurlAPI>, L<http://buzzurl.jp/>,
L<http://labs.ecnavi.jp/developer/buzzurl/api/>

=cut

deps/Publish-Buzzurl.yaml

name: Publish::Buzzurl
author: Masafumi Otsune
depends: 
  WebServie::BuzzurlAPI: 0

t/plugins/Publish-Buzzurl/base.t

use strict;
use t::TestPlagger;

test_plugin_deps;
plan 'no_plan';
run_eval_expected;

__END__

=== Loading Publish::Buzzurl
--- input config
plugins:
  - module: Publish::Buzzurl
--- expected
ok 1, $block->name;
トラックバック - http://subtech.g.hatena.ne.jp/otsune/20070516