root/trunk/plagger/lib/Plagger/Plugin/Publish/Delicious.pm

Revision 647 (checked in by miyagawa, 14 years ago)

Publish::Delicious: Fix interval bug

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