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

Revision 177 (checked in by miyagawa, 14 years ago)
  • Fixed tDiaryComment to strictly match with tDiary's feed, and strips comment entry rather than rating it
  • Added $feed->source_xml to get the raw XML
  • 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
Note: See TracBrowser for help on using the browser.