line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Bloglines; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
105578
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
155
|
|
4
|
4
|
|
|
4
|
|
53
|
use 5.8.1; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
227
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
4347
|
use LWP::UserAgent; |
|
4
|
|
|
|
|
238845
|
|
|
4
|
|
|
|
|
138
|
|
8
|
4
|
|
|
4
|
|
40
|
use URI; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
96
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
2564
|
use WebService::Bloglines::Entries; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use WebService::Bloglines::Subscriptions; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
|
|
|
|
|
|
my($class, %p) = @_; |
15
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
16
|
|
|
|
|
|
|
$ua->env_proxy; |
17
|
|
|
|
|
|
|
$ua->agent("WebService::Bloglines/$VERSION"); |
18
|
|
|
|
|
|
|
$ua->credentials("rpc.bloglines.com:80", "Bloglines RPC", |
19
|
|
|
|
|
|
|
$p{username}, $p{password}); |
20
|
|
|
|
|
|
|
bless { %p, ua => $ua }, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub username { shift->_var('username', @_) } |
24
|
|
|
|
|
|
|
sub password { shift->_var('password', @_) } |
25
|
|
|
|
|
|
|
sub use_liberal { shift->_var('use_liberal', @_) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _var { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
my $key = shift; |
30
|
|
|
|
|
|
|
$self->{$key} = shift if @_; |
31
|
|
|
|
|
|
|
$self->{$key}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _die { |
35
|
|
|
|
|
|
|
my($self, $message) = @_; |
36
|
|
|
|
|
|
|
require Carp; |
37
|
|
|
|
|
|
|
Carp::croak($message); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _request { |
41
|
|
|
|
|
|
|
my($self, $url, %param) = @_; |
42
|
|
|
|
|
|
|
my $uri = URI->new($url); |
43
|
|
|
|
|
|
|
$uri->query_form(%param); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $request = HTTP::Request->new(GET => $uri); |
46
|
|
|
|
|
|
|
return $self->{ua}->request($request); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# http://www.bloglines.com/services/api/notifier |
50
|
|
|
|
|
|
|
sub notify { |
51
|
|
|
|
|
|
|
my $self = shift; |
52
|
|
|
|
|
|
|
my $res = $self->_request("http://rpc.bloglines.com/update", |
53
|
|
|
|
|
|
|
user => $self->{username}, |
54
|
|
|
|
|
|
|
ver => 1); |
55
|
|
|
|
|
|
|
my $content = $res->content; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |A|B| where A is the number of unread items |
58
|
|
|
|
|
|
|
$content =~ /\|([\-\d]+)|(.*)|/ |
59
|
|
|
|
|
|
|
or $self->_die("Bad Response: $content"); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my($unread, $url) = ($1, $2); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# A is -1 if the user email address is wrong. |
64
|
|
|
|
|
|
|
if ($unread == -1) { |
65
|
|
|
|
|
|
|
$self->_die("Bad username: $self->{username}"); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# XXX should check $url? |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $unread; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# http://www.bloglines.com/services/api/listsubs |
74
|
|
|
|
|
|
|
sub listsubs { |
75
|
|
|
|
|
|
|
my $self = shift; |
76
|
|
|
|
|
|
|
my $res = $self->_request("http://rpc.bloglines.com/listsubs"); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
if ($res->code == 401) { |
79
|
|
|
|
|
|
|
$self->_die($res->status_line); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return WebService::Bloglines::Subscriptions->new($res->content); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# http://www.bloglines.com/services/api/getitems |
86
|
|
|
|
|
|
|
sub getitems { |
87
|
|
|
|
|
|
|
my($self, $subid, $mark_read, $time) = @_; |
88
|
|
|
|
|
|
|
my %param = (s => $subid, n => $mark_read, d => $time); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# normalize to defined parameters |
91
|
|
|
|
|
|
|
%param = map { defined($param{$_}) ? ($_ => $param{$_}) : () } keys %param; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $res = $self->_request("http://rpc.bloglines.com/getitems", %param); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# 304 means no updates |
96
|
|
|
|
|
|
|
return if $res->code == 304; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# otherwise, something bad is happened |
99
|
|
|
|
|
|
|
unless ($res->code == 200) { |
100
|
|
|
|
|
|
|
$self->_die($res->status_line); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return WebService::Bloglines::Entries->parse($res->content, $self->use_liberal); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |