Plagger::Plugin::Publish::Delicious - Post to del.icio.us automatically


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Publish::Delicious - Post to del.icio.us automatically

SYNOPSIS

Top

  - module: Publish::Delicious
    config:
      username: your-username
      password: your-password
      interval: 2
      post_body: 1

DESCRIPTION

Top

This plugin posts feed updates to del.icio.us, using its REST API.

CONFIGURATION

Top

username, password

Your login and password for logging in del.icio.us.

interval

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

post_body

A flag to post entry's body as extended field for del.icio.us. Defaults to 0.

AUTHOR

Top

Tsutomu Koyachi

SEE ALSO

Top

Plagger, Net::Delicious, http://del.icio.us/


Plagger documentation Contained in the Plagger distribution.
package Plagger::Plugin::Publish::Delicious;
use strict;
use base qw( Plagger::Plugin );

use Encode;
use Net::Delicious;

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->{delicious} = Net::Delicious->new({
        user => $self->conf->{username},
        pswd => $self->conf->{password},
    });
}

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

    my @tags = @{$args->{entry}->tags};
    my $tag_string = @tags ? join(' ', @tags) : '';

    my $params = {
        url         => $args->{entry}->link,
        description => encode('utf-8', $args->{entry}->title),
        tags        => encode('utf-8', $tag_string),
    };

    if ($self->conf->{post_body}) {
        $params->{extended} = encode('utf-8', $args->{entry}->body_text),
    }

    $self->{delicious}->add_post($params);

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

1;

__END__