root/trunk/plagger/lib/Plagger/Plugin/Subscription/Bloglines.pm

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

Added docs to some plugins

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Subscription::Bloglines;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 our $VERSION = '0.10';
6 use WebService::Bloglines;
7
8 sub register {
9     my($self, $context) = @_;
10
11     $self->init_bloglines();
12
13     if ($self->conf->{no_sync_api}) {
14         $context->register_hook(
15             $self,
16             'subscription.load' => \&getsubs,
17         );
18     } else {
19         $context->register_hook(
20             $self,
21             'subscription.load' => \&notifier,
22             'aggregator.aggregate.bloglines' => \&sync,
23         );
24     }
25 }
26
27 sub getsubs {
28     my($self, $context) = @_;
29     my $subscription = $self->{bloglines}->listsubs();
30
31     for my $folder ($subscription->folders) {
32         $self->add_subscription($context, $subscription, $folder->{BloglinesSubId}, $folder->{title});
33     }
34
35     $self->add_subscription($context, $subscription, 0);
36 }
37
38 sub add_subscription {
39     my($self, $context, $subscription, $subid, $title) = @_;
40
41     my @feeds = $subscription->feeds_in_folder($subid);
42     for my $source (@feeds) {
43         my $feed = Plagger::Feed->new;
44         $feed->title($source->{title});
45         $feed->link($source->{htmlUrl});
46         $feed->url($source->{xmlUrl} );
47         $feed->tags([ $title ]) if $title;
48         $context->subscription->add($feed);
49     }
50 }
51
52 sub init_bloglines {
53     my $self = shift;
54     $self->{bloglines} = WebService::Bloglines->new(
55         username => $self->conf->{username},
56         password => $self->conf->{password},
57     );
58 }
59
60 sub notifier {
61     my($self, $context) = @_;
62
63     my $count = $self->{bloglines}->notify();
64     $context->log(info => "You have $count unread item(s) on Bloglines.");
65     if ($count) {
66         my $feed = Plagger::Feed->new;
67         $feed->type('bloglines');
68         $context->subscription->add($feed);
69     }
70 }
71
72 sub sync {
73     my($self, $context, $args) = @_;
74
75     my $mark_read = $self->conf->{mark_read};
76        $mark_read = 1 unless defined $mark_read;
77
78     my @updates = $self->{bloglines}->getitems(0, $mark_read);
79     $context->log(dnfo => scalar(@updates) . " feed(s) updated.");
80
81     for my $update (@updates) {
82         my $source = $update->feed;
83
84         my $feed = Plagger::Feed->new;
85         $feed->type('bloglines');
86         $feed->title($source->{title});
87         $feed->link($source->{link});
88         $feed->image($source->{image});
89         $feed->description($source->{description});
90         $feed->language($source->{language});
91         $feed->author($source->{webmaster});
92         $feed->meta->{bloglines_id} = $source->{bloglines}->{siteid};
93         $feed->source_xml($update->{_xml});
94
95         for my $item ( $update->items ) {
96             my $entry = Plagger::Entry->new;
97
98             $entry->title($item->{title});
99             $entry->author($item->{dc}->{creator});
100             $entry->tags([ $item->{dc}->{subject} ])
101                 if $item->{dc}->{subject};
102             $entry->date( Plagger::Date->parse('Mail', $item->{pubDate}) );
103             $entry->link($item->{link});
104             $entry->id($item->{guid});
105
106             $entry->body($item->{description});
107
108             $feed->add_entry($entry);
109         }
110
111         $context->update->add($feed);
112     }
113 }
114
115 1;
116
117 __END__
118
119 =head1 NAME
120
121 Plagger::Plugin::Subscription::Bloglines - Bloglines Subscription
122
123 =head1 SYNOPSIS
124
125   - module: Subscription::Bloglines
126     config:
127       username: your-email@account
128       password: your-password
129       mark_read: 1
130
131 =head1 DESCRIPTION
132
133 This plugin allows you to synchronize your subscription using
134 Bloglines Web Services sync API.
135
136 =head1 CONFIGURATION
137
138 =over 4
139
140 =item username, password
141
142 Your username & password to use with Bloglines API.
143
144 =item mark_read
145
146 C<mark_read> specifies whether this plugin "marks as read" the items
147 you synchronize. Without this option, you will get the duplicated
148 updates everytime you run Plagger, until you mark them unread using
149 Bloglines browser interface. Defaults to 1.
150
151 Setting this to 0 is recommended only for testing, or users who don't
152 use Publish::Gmail plugin.
153
154 =back
155
156 =head1 AUTHOR
157
158 Tatsuhiko Miyagawa
159
160 =head1 SEE ALSO
161
162 L<Plagger>, L<WebService::Bloglines>, L<http://www.bloglines.com/>
163
164 =cut
165
Note: See TracBrowser for help on using the browser.