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

Revision 1950 (checked in by otsune, 2 years ago)

opps. fix constractor parameter and add method ref

Line 
1 package Plagger::Plugin::Publish::Buzzurl;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use WebService::BuzzurlAPI;
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'plugin.init'   => \&initialize,
12         'publish.entry' => \&add_entry,
13     );
14 }
15
16 sub rule_hook { 'publish.entry' }
17
18 sub initialize {
19     my ($self, $context, $args) = @_;
20     $self->{buzzurl} = WebService::BuzzurlAPI->new(
21         email    => $self->conf->{usermail},
22         password => $self->conf->{password},
23     );
24 }
25
26 sub add_entry {
27     my($self, $context, $args) = @_;
28
29     my $params = {
30         url     => $args->{entry}->link,
31         title   => $args->{entry}->title,
32         keyword => $args->{entry}->tags,
33     };
34
35     if ($self->conf->{post_body}) {
36         $params->{comment} = $args->{entry}->body_text,
37     }
38
39     my $res = $self->{buzzurl}->add(%{$params});
40
41     if ($res->is_success) {
42         $context->log(info  => "Post entry success :" . $res->json->{status});
43     }else{
44         $context->log(error => $res->errstr);
45     }
46
47     my $sleeping_time = $self->conf->{interval} || 2;
48     $context->log(info => "Post entry success. sleep $sleeping_time.");
49     sleep( $sleeping_time );
50 }
51
52 1;
53
54 __END__
55
56 =head1 NAME
57
58 Plagger::Plugin::Publish::Buzzurl - Post to Buzzurl automatically
59
60 =head1 SYNOPSIS
61
62   - module: Publish::Buzzurl
63     config:
64       usermail: your-email
65       password: your-password
66       interval: 2
67       post_body: 1
68
69 =head1 DESCRIPTION
70
71 This plugin posts feed updates to Buzzurl, using its REST API.
72
73 =head1 CONFIGURATION
74
75 =over 4
76
77 =item usermail, password
78
79 Your login and password for logging in Buzzurl
80
81 =item interval
82
83 Interval (as seconds) to sleep after posting each bookmark. Defaults to 2.
84
85 =item post_body
86
87 A flag to post entry's body as extended field for Buzzurl. Defaults to 0.
88
89 =back
90
91 =cut
92
93 =head1 AUTHOR
94
95 Masafumi Otsune
96
97 =head1 SEE ALSO
98
99 L<Plagger>, L<WebService::BuzzurlAPI>, L<http://buzzurl.jp/>,
100 L<http://labs.ecnavi.jp/developer/buzzurl/api/>
101
102 =cut
Note: See TracBrowser for help on using the browser.