line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Maisha::Plugin::Identica; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
39785
|
use strict; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
193
|
|
4
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
385
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.19'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
9
|
|
|
|
|
|
|
# Library Modules |
10
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
28
|
use base qw(App::Maisha::Plugin::Base); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
1200
|
|
12
|
5
|
|
|
5
|
|
33
|
use base qw(Class::Accessor::Fast); |
|
5
|
|
|
|
|
32
|
|
|
5
|
|
|
|
|
1168
|
|
13
|
5
|
|
|
5
|
|
4998
|
use File::Path; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
330
|
|
14
|
5
|
|
|
5
|
|
4158
|
use Net::Twitter; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Storable; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
18
|
|
|
|
|
|
|
# Accessors |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors($_) for qw(api users); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#---------------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
# Public API |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#http://identi.ca/settings/oauthapps/show/185 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
|
|
|
|
|
|
my $class = shift; |
29
|
|
|
|
|
|
|
my $self = { |
30
|
|
|
|
|
|
|
consumer_key => 'fb8163dcdb32e6c8e60734e961187553', |
31
|
|
|
|
|
|
|
consumer_secret => '8251970fb08ea39a90f6b494e3a2aabc', |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
bless $self, $class; |
35
|
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub login { |
39
|
|
|
|
|
|
|
my ($self,$config) = @_; |
40
|
|
|
|
|
|
|
my $api; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
unless($config->{username}) { warn "No username supplied\n"; return } |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
eval { |
45
|
|
|
|
|
|
|
$api = Net::Twitter->new( |
46
|
|
|
|
|
|
|
traits => [qw/API::Search API::REST OAuth/], |
47
|
|
|
|
|
|
|
consumer_key => $self->{consumer_key}, |
48
|
|
|
|
|
|
|
consumer_secret => $self->{consumer_secret}, |
49
|
|
|
|
|
|
|
identica => 1, |
50
|
|
|
|
|
|
|
ssl => 1 |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
}; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
unless($api) { |
55
|
|
|
|
|
|
|
warn "Unable to establish connection to Identica API\n"; |
56
|
|
|
|
|
|
|
return 0; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# for testing purposes we don't want to login |
60
|
|
|
|
|
|
|
if(!$config->{test}) { |
61
|
|
|
|
|
|
|
eval { |
62
|
|
|
|
|
|
|
my $datafile = $config->{home} . '/.maisha/identica.dat'; |
63
|
|
|
|
|
|
|
my $access_tokens = eval { retrieve($datafile) } || {}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ( $access_tokens && $access_tokens->{$config->{username}}) { |
66
|
|
|
|
|
|
|
$api->access_token($access_tokens->{$config->{username}}->[0]); |
67
|
|
|
|
|
|
|
$api->access_token_secret($access_tokens->{$config->{username}}->[1]); |
68
|
|
|
|
|
|
|
} else { |
69
|
|
|
|
|
|
|
my $auth_url = $api->get_authorization_url; |
70
|
|
|
|
|
|
|
print " Authorize this application at: $auth_url\nThen, enter the PIN# provided to continue: "; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $pin = <STDIN>; # wait for input |
73
|
|
|
|
|
|
|
chomp $pin; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
unless($pin) { |
76
|
|
|
|
|
|
|
warn "No PIN provided, Maisha will not be able to access Identica account until authorized to do so\n"; |
77
|
|
|
|
|
|
|
return 0; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# request_access_token stores the tokens in $nt AND returns them |
81
|
|
|
|
|
|
|
my $access_tokens = {}; |
82
|
|
|
|
|
|
|
my @access_tokens; |
83
|
|
|
|
|
|
|
eval { @access_tokens = $api->request_access_token(verifier => $pin) }; |
84
|
|
|
|
|
|
|
unless(@access_tokens) { |
85
|
|
|
|
|
|
|
warn "Invalid PIN provided, Maisha will not be able to access your Identica account until authorized to do so\n"; |
86
|
|
|
|
|
|
|
return 0; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
$access_tokens->{$config->{username}} = \@access_tokens; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
mkpath( $config->{home} . '/.maisha' ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# save the access tokens |
93
|
|
|
|
|
|
|
store $access_tokens, $datafile; |
94
|
|
|
|
|
|
|
chmod 0640, $datafile; # make sure it has reasonable permissions |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if($@) { |
99
|
|
|
|
|
|
|
warn "Unable to login to Identica\n"; |
100
|
|
|
|
|
|
|
return 0; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$self->api($api); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if(!$config->{test}) { |
107
|
|
|
|
|
|
|
print "...building user cache for Identica\n"; |
108
|
|
|
|
|
|
|
$self->_build_users(); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _build_users { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my %users; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
eval { |
119
|
|
|
|
|
|
|
my $f = $self->api->friends(); |
120
|
|
|
|
|
|
|
if($f && @$f) { for(@$f) { next unless($_); $users{$_->{screen_name}} = 1 } } |
121
|
|
|
|
|
|
|
$f = $self->api->followers(); |
122
|
|
|
|
|
|
|
if($f && @$f) { for(@$f) { next unless($_); $users{$_->{screen_name}} = 1 } } |
123
|
|
|
|
|
|
|
}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$self->users(\%users); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub api_reauthorize { |
129
|
|
|
|
|
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
my $config = $self->config; |
131
|
|
|
|
|
|
|
my $api = $self->api; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# for testing purposes we don't want to login |
134
|
|
|
|
|
|
|
if(!$config->{test}) { |
135
|
|
|
|
|
|
|
eval { |
136
|
|
|
|
|
|
|
my $datafile = $config->{home} . '/.maisha/identica.dat'; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $auth_url = $api->get_authorization_url; |
139
|
|
|
|
|
|
|
print "Please re-authorize this application at: $auth_url\nThen, enter the PIN# provided to continue: "; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $pin = <STDIN>; # wait for input |
142
|
|
|
|
|
|
|
chomp $pin; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
unless($pin) { |
145
|
|
|
|
|
|
|
warn "No PIN provided, Maisha will not be able to access direct messages until reauthorization is completed\n"; |
146
|
|
|
|
|
|
|
return 0; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# request_access_token stores the tokens in $nt AND returns them |
150
|
|
|
|
|
|
|
my $access_tokens = {}; |
151
|
|
|
|
|
|
|
my @access_tokens; |
152
|
|
|
|
|
|
|
eval { @access_tokens = $api->request_access_token(verifier => $pin) }; |
153
|
|
|
|
|
|
|
unless(@access_tokens) { |
154
|
|
|
|
|
|
|
warn "Invalid PIN provided, Maisha will not be able to access direct messages until reauthorization is completed\n"; |
155
|
|
|
|
|
|
|
return 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
$access_tokens->{$config->{username}} = \@access_tokens; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
unlink $datafile; |
160
|
|
|
|
|
|
|
mkpath( $config->{home} . '/.maisha' ); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# save the access tokens |
163
|
|
|
|
|
|
|
store $access_tokens, $datafile; |
164
|
|
|
|
|
|
|
chmod 0640, $datafile; # make sure it has reasonable permissions |
165
|
|
|
|
|
|
|
}; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
if($@) { |
168
|
|
|
|
|
|
|
warn "Unable to login to Identica\n"; |
169
|
|
|
|
|
|
|
return 0; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
return 1; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub api_user { |
177
|
|
|
|
|
|
|
my $self = shift; |
178
|
|
|
|
|
|
|
$self->api->show_user(@_); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub api_user_timeline { |
182
|
|
|
|
|
|
|
my $self = shift; |
183
|
|
|
|
|
|
|
$self->api->user_timeline(@_); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub api_friends { |
187
|
|
|
|
|
|
|
my $self = shift; |
188
|
|
|
|
|
|
|
$self->api->following(@_); |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub api_friends_timeline { |
192
|
|
|
|
|
|
|
my $self = shift; |
193
|
|
|
|
|
|
|
$self->api->following_timeline(@_); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub api_public_timeline { |
197
|
|
|
|
|
|
|
my $self = shift; |
198
|
|
|
|
|
|
|
$self->api->public_timeline(@_); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub api_followers { |
202
|
|
|
|
|
|
|
my $self = shift; |
203
|
|
|
|
|
|
|
$self->api->followers(@_); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub api_update { |
207
|
|
|
|
|
|
|
my $self = shift; |
208
|
|
|
|
|
|
|
$self->api->update(@_); |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub api_replies { |
212
|
|
|
|
|
|
|
my $self = shift; |
213
|
|
|
|
|
|
|
$self->api->replies(@_); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub api_send_message { |
217
|
|
|
|
|
|
|
my $self = shift; |
218
|
|
|
|
|
|
|
$self->api->new_direct_message(@_); |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub api_direct_messages_to { |
222
|
|
|
|
|
|
|
my $self = shift; |
223
|
|
|
|
|
|
|
$self->api->direct_messages(@_); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub api_direct_messages_from { |
227
|
|
|
|
|
|
|
my $self = shift; |
228
|
|
|
|
|
|
|
$self->api->sent_direct_messages(@_); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub api_search { |
232
|
|
|
|
|
|
|
my $self = shift; |
233
|
|
|
|
|
|
|
$self->api->search(@_); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 NAME |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
App::Maisha::Plugin::Identica - Maisha interface to Identi.ca |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 SYNOPSIS |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
maisha |
247
|
|
|
|
|
|
|
maisha> use Identica |
248
|
|
|
|
|
|
|
use ok |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 DESCRIPTION |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
App::Maisha::Plugin::Identica is the gateway for Maisha to access the Identi.ca |
253
|
|
|
|
|
|
|
API. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=head1 METHODS |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=head2 Constructor |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=over 4 |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=item * new |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=back |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 Process Methods |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=over 4 |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * login |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
Login to the service. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=back |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 API Methods |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
The API methods are used to interface to with the Identica API. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=over 4 |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * api_reauthorize |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=item * api_user |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * api_user_timeline |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=item * api_friends |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item * api_friends_timeline |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=item * api_public_timeline |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * api_followers |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=item * api_update |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * api_replies |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=item * api_send_message |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item * api_direct_messages_to |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item * api_direct_messages_from |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=item * api_search |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=back |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head1 AUTHENTICATION |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
As Twitter has now disabled Basic Authentication to access their API, to be |
312
|
|
|
|
|
|
|
consistent Maisha now requires that access to both Twitter and Identica uses |
313
|
|
|
|
|
|
|
OAuth. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
With this new method of authentication, the application will provide a URL, |
316
|
|
|
|
|
|
|
which the user needs to cut-n-paste into a browser to logging in to the |
317
|
|
|
|
|
|
|
service, using your regular username/password, then 'Allow' Maisha to access |
318
|
|
|
|
|
|
|
your account. This will then allow Maisha to post to your account. You will |
319
|
|
|
|
|
|
|
then be given a PIN, which should then be entered at the prompt on the Maisha |
320
|
|
|
|
|
|
|
command line. |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Once you have completed authentication, the application will then store your |
323
|
|
|
|
|
|
|
access tokens permanently under your profile on your computer. Then when you |
324
|
|
|
|
|
|
|
next use the application it will retrieve these access tokens automatically and |
325
|
|
|
|
|
|
|
you will no longer need to register the application. |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
For further information please see the Identica FAQ - |
328
|
|
|
|
|
|
|
L<http://status.net/wiki/TwitterCompatibleAPI> |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=head1 SEE ALSO |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
For further information regarding the commands and configuration, please see |
333
|
|
|
|
|
|
|
the 'maisha' script included with this distribution. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
L<App::Maisha> |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
L<Net::Identica> |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head1 WEBSITES |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=over 4 |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
=item * Main Site: L<http://maisha.grango.org> |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=item * Git Repo: L<http://github.com/barbie/maisha/tree/master> |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=item * RT Queue: L<RT: http://rt.cpan.org/Public/Dist/Display.html?Name=App-Maisha> |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
=back |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head1 AUTHOR |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Barbie, <barbie@cpan.org> |
354
|
|
|
|
|
|
|
for Miss Barbell Productions <http://www.missbarbell.co.uk>. |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
Copyright (C) 2009-2014 by Barbie |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
This distribution is free software; you can redistribute it and/or |
361
|
|
|
|
|
|
|
modify it under the Artistic License v2. |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
=cut |