line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FireEagle; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Client library for FireEagle |
4
|
2
|
|
|
2
|
|
31144
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
96
|
|
5
|
2
|
|
|
2
|
|
15
|
use base qw(Net::OAuth::Simple); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2319
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.6'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# FireEagle Endpoint URLs |
10
|
|
|
|
|
|
|
our $REQUEST_TOKEN_URL = 'https://fireeagle.yahooapis.com/oauth/request_token'; |
11
|
|
|
|
|
|
|
our $AUTHORIZATION_URL = 'https://fireeagle.yahoo.net/oauth/authorize'; |
12
|
|
|
|
|
|
|
our $ACCESS_TOKEN_URL = 'https://fireeagle.yahooapis.com/oauth/access_token'; |
13
|
|
|
|
|
|
|
our $QUERY_API_URL = 'https://fireeagle.yahooapis.com/api/0.1/user'; |
14
|
|
|
|
|
|
|
our $UPDATE_API_URL = 'https://fireeagle.yahooapis.com/api/0.1/update'; |
15
|
|
|
|
|
|
|
our $LOOKUP_API_URL = 'https://fireeagle.yahooapis.com/api/0.1/lookup'; |
16
|
|
|
|
|
|
|
our $WITHIN_API_URL = 'https://fireeagle.yahooapis.com/api/0.1/within'; |
17
|
|
|
|
|
|
|
our $RECENT_API_URL = 'https://fireeagle.yahooapis.com/api/0.1/recent'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Net::FireEagle - access Yahoo's new FireEagle location service |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Set up Fire Eagle oauth |
27
|
|
|
|
|
|
|
my $fe = Net::FireEagle->new( consumer_key => $consumer_key, |
28
|
|
|
|
|
|
|
consumer_secret => $consumer_secret ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Resume previous Fire Eagle oauth, feed access token and secret |
31
|
|
|
|
|
|
|
my $fe2 = Net::FireEagle->new( consumer_key => $consumer_key, |
32
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
33
|
|
|
|
|
|
|
access_token => $access_token, |
34
|
|
|
|
|
|
|
access_token_secret => $access_token_secret ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Send this to user to grant authorization for this app |
37
|
|
|
|
|
|
|
my $auth_url = $fe->get_authorization_url; |
38
|
|
|
|
|
|
|
# ... and request an access token |
39
|
|
|
|
|
|
|
# Note: you can save these in DB to restore previous Fire Eagle oauth session |
40
|
|
|
|
|
|
|
my ($access_token, $access_token_secret) = $fe->request_access_token; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Get them back |
43
|
|
|
|
|
|
|
my $access_token = $fe->access_token; |
44
|
|
|
|
|
|
|
my $access_token_secret = $fe->access_token_secret; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# in the case of a web app, you want to save the request tokens |
47
|
|
|
|
|
|
|
# (and/or set them) |
48
|
|
|
|
|
|
|
my $request_token = $fe->request_token; |
49
|
|
|
|
|
|
|
my $request_token_secret = $fe->request_token_secret; |
50
|
|
|
|
|
|
|
$fe->request_token( $request_token ); |
51
|
|
|
|
|
|
|
$fe->request_token_secret( $request_token_secret ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Can't query or update location without authorization |
54
|
|
|
|
|
|
|
my $loc = $fe->location; # returns xml |
55
|
|
|
|
|
|
|
my $loc = $fe->location( format => 'xml' ); # returns xml |
56
|
|
|
|
|
|
|
my $loc = $fe->location( format => 'json' ); # returns json |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# returns result on success. dies or returns undef on failure |
59
|
|
|
|
|
|
|
my $return = $fe->update_location( "500 Third St., San Francisco, CA" ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Find a location. Returns either xml or json |
62
|
|
|
|
|
|
|
my $return = $fe->lookup_location( "Pensacola" ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 ABOUT |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Fire Eagle is a site that stores information about your location. With |
67
|
|
|
|
|
|
|
your permission, other services and devices can either update that |
68
|
|
|
|
|
|
|
information or access it. By helping applications respond to your |
69
|
|
|
|
|
|
|
location, Fire Eagle is designed to make the world around you more |
70
|
|
|
|
|
|
|
interesting! Use your location to power friend-finders, games, local |
71
|
|
|
|
|
|
|
information services, blog badges and stuff like that... |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
For more information see http://fireeagle.yahoo.net/ |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHENTICATION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
For more information read this |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
http://fireeagle.yahoo.net/developer/documentation/getting_started |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
but, in short you have to first get an API key from the FireEagle site. |
82
|
|
|
|
|
|
|
Then using this consumer key and consumer secret you have to |
83
|
|
|
|
|
|
|
authenticate the relationship between you and your user. See the script |
84
|
|
|
|
|
|
|
C packaged with this module for an example of how to do this. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SIMPLE DAILY USAGE AND EXAMPLE CODE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The script C shipped with this module gives you really |
89
|
|
|
|
|
|
|
quick access to your FireEagle account - you can use it to simply |
90
|
|
|
|
|
|
|
query and update your location. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
It also serves as a pretty good example of how to do desktop app |
93
|
|
|
|
|
|
|
authentication and how to use the API. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 METHODS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 new |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Create a new FireEagle object. This must have the options |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over 4 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item consumer_key |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item consumer_secret |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
which you can get at http://fireeagle.yahoo.net/developer/manage |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
then, when you have your per-user authentication tokens (see above) you |
114
|
|
|
|
|
|
|
can supply |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=over 4 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item access_token |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item access_token_secret |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Alternatively when you create a new web-based application, a general-purpose |
125
|
|
|
|
|
|
|
access token is issued to you along with your application key and secret. You |
126
|
|
|
|
|
|
|
can get them at http://fireeagle.yahoo.net/developer/manage. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
They are tied to your application and allow your application to make |
129
|
|
|
|
|
|
|
general-purpose API method calls (often batch-style) to Fire Eagle. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
You can read about them at |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
http://fireagle.yahoo.net/developer/documentation/using_oauth#feaccesstokens |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
You can pass them in using the param |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 4 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item general_token |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item general_token_secret |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub new { |
150
|
1
|
|
|
1
|
1
|
217
|
my $proto = shift; |
151
|
1
|
|
33
|
|
|
9
|
my $class = ref $proto || $proto; |
152
|
1
|
|
|
|
|
6
|
my %tokens = @_; |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
24
|
return $class->SUPER::new( tokens => \%tokens, |
155
|
|
|
|
|
|
|
urls => { |
156
|
|
|
|
|
|
|
authorization_url => $AUTHORIZATION_URL, |
157
|
|
|
|
|
|
|
request_token_url => $REQUEST_TOKEN_URL, |
158
|
|
|
|
|
|
|
access_token_url => $ACCESS_TOKEN_URL, |
159
|
|
|
|
|
|
|
}); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 location [opt[s] |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Get the user's current location. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Options are passed in as a hash and may be one of |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item format |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Either 'xml' or 'json'. Defaults to 'xml'. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=back |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub location { |
180
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
181
|
0
|
|
|
|
|
|
my %opts = @_; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
my $url = $QUERY_API_URL; |
184
|
0
|
0
|
|
|
|
|
$url .= '.'.$opts{format} if defined $opts{format}; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $self->_make_restricted_request($url, 'GET'); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 update_location |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Takes a free form string with the new location. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Return the result of the update in either xml or json |
194
|
|
|
|
|
|
|
depending on C. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The location can either be a plain string or a hash reference containing |
197
|
|
|
|
|
|
|
location parameters as described in |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
http://fireeagle.yahoo.net/developer/documentation/location#locparams |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub update_location { |
204
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
205
|
0
|
|
|
|
|
|
my $location = shift; |
206
|
0
|
|
|
|
|
|
my %opts = @_; |
207
|
|
|
|
|
|
|
|
208
|
0
|
|
|
|
|
|
my %extras = $self->_munge('address', $location); |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
my $url = $UPDATE_API_URL; |
211
|
0
|
0
|
|
|
|
|
$url .= '.'.$opts{format} if defined $opts{format}; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
return $self->_make_restricted_request($url, 'POST', %extras); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head2 lookup_location |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Disambiguates potential values for update. Results from lookup can be |
219
|
|
|
|
|
|
|
passed to update to ensure that Fire Eagle will understand how to parse |
220
|
|
|
|
|
|
|
the location parameter. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Return the result of the update in either xml or json |
223
|
|
|
|
|
|
|
depending on C. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
The query can either be a plain string or a hash reference containing |
226
|
|
|
|
|
|
|
location parameters as described in |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
http://fireeagle.yahoo.net/developer/documentation/location#locparams |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub lookup_location { |
233
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
234
|
0
|
|
|
|
|
|
my $location = shift; |
235
|
0
|
|
|
|
|
|
my %opts = @_; |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
my %extras = $self->_munge('address', $location); |
238
|
0
|
|
|
|
|
|
my $url = $LOOKUP_API_URL; |
239
|
0
|
0
|
|
|
|
|
$url .= '.'.$opts{format} if defined $opts{format}; |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
return $self->_make_restricted_request($url, 'GET', %extras); |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 within |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Takes a Place ID or a WoE ID and returns a list of users using your |
247
|
|
|
|
|
|
|
application who are within the bounding box of that location. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Return the result of the update in either xml or json |
250
|
|
|
|
|
|
|
depending on C. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
The query can either be a plain string or a hash reference containing |
253
|
|
|
|
|
|
|
location parameters as described in |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
http://fireeagle.yahoo.net/developer/documentation/location#locparams |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub within { |
260
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
261
|
0
|
|
|
|
|
|
my $location = shift; |
262
|
0
|
|
|
|
|
|
my %opts = @_; |
263
|
|
|
|
|
|
|
|
264
|
0
|
|
|
|
|
|
my %extras = $self->_munge('address', $location); |
265
|
0
|
|
|
|
|
|
my $url = $WITHIN_API_URL; |
266
|
0
|
0
|
|
|
|
|
$url .= '.'.$opts{format} if defined $opts{format}; |
267
|
|
|
|
|
|
|
|
268
|
0
|
|
|
|
|
|
return $self->_make_restricted_request_general($url, 'GET', %extras); |
269
|
|
|
|
|
|
|
} |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 recent [opt[s]] |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Query for users of an Application who have updated their locations recently. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Return the result of the update in either xml or json |
277
|
|
|
|
|
|
|
depending on C. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Query is either a number representing a unix time stamp, to |
280
|
|
|
|
|
|
|
specify the earliest update to return, or a hash reference containing |
281
|
|
|
|
|
|
|
parameters as described in |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
http://fireagle.yahoo.net/developer/documentation/querying#recent |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub recent { |
288
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
289
|
0
|
|
|
|
|
|
my $time = shift; |
290
|
0
|
|
|
|
|
|
my %opts = @_; |
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
my %extras = $self->_munge('time', $time); |
293
|
0
|
|
|
|
|
|
my $url = $RECENT_API_URL; |
294
|
0
|
0
|
|
|
|
|
$url .= '.'.$opts{format} if defined $opts{format}; |
295
|
|
|
|
|
|
|
|
296
|
0
|
|
|
|
|
|
return $self->_make_restricted_request_general($url, 'GET', %extras); |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub _make_restricted_request_general { |
300
|
0
|
|
|
0
|
|
|
my $self = shift; |
301
|
0
|
|
|
|
|
|
my $response = $self->make_general_request(@_); |
302
|
0
|
|
|
|
|
|
return $response->content; |
303
|
|
|
|
|
|
|
} |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
sub _make_restricted_request { |
306
|
0
|
|
|
0
|
|
|
my $self = shift; |
307
|
0
|
|
|
|
|
|
my $response = $self->make_restricted_request(@_); |
308
|
0
|
|
|
|
|
|
return $response->content; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
sub _munge { |
312
|
0
|
|
|
0
|
|
|
my $self = shift; |
313
|
0
|
|
|
|
|
|
my $key = shift; |
314
|
0
|
|
0
|
|
|
|
my $item = shift || return (); |
315
|
0
|
|
|
|
|
|
my $ref = ref($item); |
316
|
0
|
0
|
0
|
|
|
|
return ( $key => $item ) if !defined $ref or "" eq $ref; |
317
|
0
|
0
|
|
|
|
|
return %$item if 'HASH' eq $ref; |
318
|
0
|
|
|
|
|
|
die "Can't understand $key parameter in the form of a $ref ref"; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=head1 BUGS |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
Non known |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=head1 DEVELOPERS |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
The latest code for this module can be found at |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
https://svn.unixbeard.net/simon/Net-FireEagle |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head1 AUTHOR |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
Original code by Yahoo! Brickhouse. |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
Additional code from Aaron Straup Cope |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
Rewritten and packaged by Simon Wistow |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=head1 COPYRIGHT |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
Copyright 2008 - Simon Wistow and Yahoo! Brickhouse |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
Distributed under the same terms as Perl itself. |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
See L and L. |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head1 SEE ALSO |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
L |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=cut |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
1; |