line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::Plurk; |
2
|
|
|
|
|
|
|
our $VERSION = "0.12"; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
75550
|
use 5.008; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
91
|
|
5
|
2
|
|
|
2
|
|
10
|
use common::sense 2.02; |
|
2
|
|
|
|
|
40
|
|
|
2
|
|
|
|
|
14
|
|
6
|
2
|
|
|
2
|
|
2137
|
use parent 0.223 "Object::Event"; |
|
2
|
|
|
|
|
802
|
|
|
2
|
|
|
|
|
14
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
104905
|
use AnyEvent 5.202; |
|
2
|
|
|
|
|
109
|
|
|
2
|
|
|
|
|
63
|
|
9
|
2
|
|
|
2
|
|
2668
|
use AnyEvent::HTTP 1.44; |
|
2
|
|
|
|
|
57361
|
|
|
2
|
|
|
|
|
241
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
2530
|
use JSON 2.15 qw(to_json from_json); |
|
2
|
|
|
|
|
72591
|
|
|
2
|
|
|
|
|
20
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
2584
|
use URI; |
|
2
|
|
|
|
|
11661
|
|
|
2
|
|
|
|
|
89
|
|
14
|
2
|
|
|
2
|
|
86
|
use Carp "croak"; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
156
|
|
15
|
2
|
|
|
2
|
|
2482
|
use POSIX qw(strftime); |
|
2
|
|
|
|
|
17225
|
|
|
2
|
|
|
|
|
17
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Sub |
18
|
|
|
|
|
|
|
sub current_time_offset() { |
19
|
0
|
|
|
0
|
0
|
|
my @t = gmtime; |
20
|
0
|
|
|
|
|
|
return strftime('%Y-%m-%dT%H:%M:%S', @t); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub plurk_api_uri { |
24
|
0
|
|
|
0
|
0
|
|
my ($x, %form) = @_; |
25
|
0
|
0
|
|
|
|
|
$x = "/$x" unless index($x, "/Users/") == 0; |
26
|
0
|
|
|
|
|
|
my $u = URI->new("http://www.plurk.com"); |
27
|
0
|
0
|
|
|
|
|
$u->scheme("https") if index($x, "/Users/") == 0; |
28
|
0
|
|
|
|
|
|
$u->path("/API$x"); |
29
|
0
|
|
|
|
|
|
$u->query_form(%form); |
30
|
0
|
|
|
|
|
|
return $u |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Method |
34
|
|
|
|
|
|
|
sub send_request { |
35
|
0
|
|
|
0
|
0
|
|
my ($self, $path, $form, $cb) = @_; |
36
|
0
|
|
|
|
|
|
$form->{api_key} = $self->{api_key}; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $v = AE::cv; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my ($data, $header); |
41
|
|
|
|
|
|
|
$self->{__current_request} = http_request( |
42
|
|
|
|
|
|
|
GET => plurk_api_uri($path, %$form), |
43
|
|
|
|
|
|
|
cookie_jar => $self->{__cookie_jar}, |
44
|
|
|
|
|
|
|
$cb || sub { |
45
|
0
|
|
|
0
|
|
|
($data, $header) = @_; |
46
|
0
|
|
|
|
|
|
$data = from_json($data); |
47
|
0
|
|
|
|
|
|
$v->send; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
0
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
$v->recv if !$cb; |
52
|
0
|
0
|
|
|
|
|
return wantarray ? ($data, $header) : $data; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
57
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
58
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(@_); |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
unless (defined $self->{api_key}) { |
61
|
0
|
|
|
|
|
|
croak "no 'api_key' given to AnyEvent::Plurk\n"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
unless (defined $self->{username}) { |
65
|
0
|
|
|
|
|
|
croak "no 'username' given to AnyEvent::Plurk\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
unless (defined $self->{password}) { |
69
|
0
|
|
|
|
|
|
croak "no 'password' given to AnyEvent::Plurk\n"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
$self->{__cookie_jar} = {}; |
73
|
0
|
|
|
|
|
|
return $self |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub login { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $cb = shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->send_request( |
81
|
|
|
|
|
|
|
"Users/login", { |
82
|
|
|
|
|
|
|
username => $self->{username}, |
83
|
|
|
|
|
|
|
password => $self->{password} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
) |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _start_polling { |
89
|
0
|
|
|
0
|
|
|
my $self = shift; |
90
|
0
|
|
0
|
|
|
|
$self->{__polling_time_offset} ||= current_time_offset; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$self->send_request( |
93
|
|
|
|
|
|
|
"Polling/getPlurks", |
94
|
|
|
|
|
|
|
{ |
95
|
|
|
|
|
|
|
offset => $self->{__polling_time_offset} |
96
|
|
|
|
|
|
|
}, |
97
|
|
|
|
|
|
|
sub { |
98
|
0
|
|
|
0
|
|
|
my ($data, $header) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if ($header->{Status} == 400) { |
101
|
|
|
|
|
|
|
# say $data; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
$data = from_json($data); |
105
|
0
|
|
|
|
|
|
my $unread_plurks = $data->{plurks}; |
106
|
0
|
0
|
|
|
|
|
if (@$unread_plurks) { |
107
|
0
|
|
|
|
|
|
my $users = $data->{plurk_users}; |
108
|
0
|
|
|
|
|
|
for my $pu (@$unread_plurks) { |
109
|
0
|
0
|
|
|
|
|
$pu->{owner} = $users->{$pu->{owner_id}} if $users->{$pu->{owner_id}}; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->event("unread_plurks" => $unread_plurks); |
113
|
0
|
|
|
|
|
|
$self->{__polling_time_offset} = current_time_offset; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$self->{__polling_timer} = AE::timer 60, 0, sub { |
118
|
0
|
|
|
|
|
|
undef $self->{__polling_timer}; |
119
|
0
|
|
|
|
|
|
$self->_start_polling; |
120
|
|
|
|
|
|
|
} |
121
|
0
|
|
|
|
|
|
} |
122
|
0
|
|
|
|
|
|
); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub start { |
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$self->login; |
129
|
0
|
|
|
|
|
|
$self->_start_polling; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub add_plurk { |
133
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
134
|
0
|
|
|
|
|
|
my $content = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$self->send_request("Timeline/plurkAdd", {qualifier => ":", content => $content}); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub delete_plurk { |
140
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $id = shift; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
$self->send_request("Timeline/plurkDelete", {plurk_id => $id}); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
1; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |