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

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

Oops, [122] broke the FeedBurnerPermalink? plugin. Revert it and add $e->id_safe

  • 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(debug => "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(debug => 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
94         for my $item ( $update->items ) {
95             my $entry = Plagger::Entry->new;
96
97             $entry->title($item->{title});
98             $entry->author($item->{dc}->{creator});
99             $entry->tags([ $item->{dc}->{subject} ])
100                 if $item->{dc}->{subject};
101             $entry->date( Plagger::Date->parse('Mail', $item->{pubDate}) );
102             $entry->link($item->{link});
103             $entry->id($item->{guid});
104
105             $entry->body($item->{description});
106
107             $feed->add_entry($entry);
108         }
109
110         $context->update->add($feed);
111     }
112 }
113
114 1;
115
Note: See TracBrowser for help on using the browser.