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

Revision 7 (checked in by miyagawa, 15 years ago)

Added no_sync_api mode to Subscription::Bloglines
Switch subscription.aggregate into aggregator.aggregate
Added dumb aggregator Aggregator::Simple
Added cache to URLBL
Date->parse fix
Renamed condition to "rule"
Gmail tempalte spacing fix

  • 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' => \&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(debug => "You have $count unread item(s) on Bloglines.");
65     $self->{bloglines_new} = $count;
66 }
67
68 sub sync {
69     my($self, $context) = @_;
70
71     return unless $self->{bloglines_new};
72
73     my @updates = $self->{bloglines}->getitems(0, $self->conf->{mark_read});
74     $context->log(debug => scalar(@updates) . " feed(s) updated.");
75
76     for my $update (@updates) {
77         my $source = $update->feed;
78
79         my $feed = Plagger::Feed->new;
80         $feed->title($source->{title});
81         $feed->link($source->{link});
82         $feed->image($source->{image});
83         $feed->description($source->{description});
84         $feed->language($source->{language});
85         $feed->author($source->{webmaster});
86         $feed->stash->{bloglines_id} = $source->{bloglines}->{siteid};
87
88         for my $item ( $update->items ) {
89             my $entry = Plagger::Entry->new;
90
91             $entry->title($item->{title});
92             $entry->author($item->{dc}->{creator});
93             $entry->tags([ $item->{dc}->{subject} ])
94                 if $item->{dc}->{subject};
95             $entry->date( Plagger::Date->parse('Mail', $item->{pubDate}) );
96             $entry->link($item->{link});
97             $entry->id($item->{guid});
98             $entry->body($item->{description});
99
100             $feed->add_entry($entry);
101         }
102
103         $context->update->add($feed);
104     }
105 }
106
107 1;
108
Note: See TracBrowser for help on using the browser.