| 1 |
package Plagger::Plugin::Publish::Delicious; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Encode; |
|---|
| 6 |
use Net::Delicious; |
|---|
| 7 |
|
|---|
| 8 |
sub register { |
|---|
| 9 |
my($self, $context) = @_; |
|---|
| 10 |
$context->register_hook( |
|---|
| 11 |
$self, |
|---|
| 12 |
'plugin.init' => \&initialize, |
|---|
| 13 |
'publish.entry' => \&add_entry, |
|---|
| 14 |
); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
sub rule_hook { 'publish.entry' } |
|---|
| 18 |
|
|---|
| 19 |
sub initialize { |
|---|
| 20 |
my ($self, $context, $args) = @_; |
|---|
| 21 |
$self->{delicious} = Net::Delicious->new({ |
|---|
| 22 |
user => $self->conf->{username}, |
|---|
| 23 |
pswd => $self->conf->{password}, |
|---|
| 24 |
}); |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
sub add_entry { |
|---|
| 28 |
my($self, $context, $args) = @_; |
|---|
| 29 |
|
|---|
| 30 |
my @tags = @{$args->{entry}->tags}; |
|---|
| 31 |
my $tag_string = @tags ? join(' ', @tags) : ''; |
|---|
| 32 |
|
|---|
| 33 |
my $params = { |
|---|
| 34 |
url => $args->{entry}->link, |
|---|
| 35 |
description => encode('utf-8', $args->{entry}->title), |
|---|
| 36 |
tags => encode('utf-8', $tag_string), |
|---|
| 37 |
}; |
|---|
| 38 |
|
|---|
| 39 |
if ($self->conf->{post_body}) { |
|---|
| 40 |
$params->{extended} = encode('utf-8', $args->{entry}->body_text), |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
$self->{delicious}->add_post($params); |
|---|
| 44 |
|
|---|
| 45 |
my $sleeping_time = $self->conf->{interval} || 3; |
|---|
| 46 |
$context->log(info => "Post entry success. sleep $sleeping_time."); |
|---|
| 47 |
sleep( $sleeping_time ); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
1; |
|---|
| 51 |
|
|---|
| 52 |
__END__ |
|---|
| 53 |
|
|---|
| 54 |
=head1 NAME |
|---|
| 55 |
|
|---|
| 56 |
Plagger::Plugin::Publish::Delicious - Post to del.icio.us automatically |
|---|
| 57 |
|
|---|
| 58 |
=head1 SYNOPSIS |
|---|
| 59 |
|
|---|
| 60 |
- module: Publish::Delicious |
|---|
| 61 |
config: |
|---|
| 62 |
username: your-username |
|---|
| 63 |
password: your-password |
|---|
| 64 |
interval: 2 |
|---|
| 65 |
post_body: 1 |
|---|
| 66 |
|
|---|
| 67 |
=head1 DESCRIPTION |
|---|
| 68 |
|
|---|
| 69 |
This plugin posts feed updates to del.icio.us, using its REST API. |
|---|
| 70 |
|
|---|
| 71 |
=head1 CONFIGURATION |
|---|
| 72 |
|
|---|
| 73 |
=over 4 |
|---|
| 74 |
|
|---|
| 75 |
=item username, password |
|---|
| 76 |
|
|---|
| 77 |
Your login and password for logging in del.icio.us. |
|---|
| 78 |
|
|---|
| 79 |
=item interval |
|---|
| 80 |
|
|---|
| 81 |
Interval (as seconds) to sleep after posting each bookmark. Defaults to 3. |
|---|
| 82 |
|
|---|
| 83 |
=item post_body |
|---|
| 84 |
|
|---|
| 85 |
A flag to post entry's body as extended field for del.icio.us. Defaults to 0. |
|---|
| 86 |
|
|---|
| 87 |
=back |
|---|
| 88 |
|
|---|
| 89 |
=cut |
|---|
| 90 |
|
|---|
| 91 |
=head1 AUTHOR |
|---|
| 92 |
|
|---|
| 93 |
Tsutomu Koyachi |
|---|
| 94 |
|
|---|
| 95 |
=head1 SEE ALSO |
|---|
| 96 |
|
|---|
| 97 |
L<Plagger>, L<Net::Delicious>, L<http://del.icio.us/> |
|---|
| 98 |
|
|---|
| 99 |
=cut |
|---|