line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nabaztag; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23699
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use base qw/Class::AutoAccess/ ; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
1008
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
589
|
use Carp ; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2738
|
use LWP::UserAgent ; |
|
1
|
|
|
|
|
301401
|
|
|
1
|
|
|
|
|
35
|
|
11
|
1
|
|
|
1
|
|
11
|
use URI::Escape ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1971
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Nabaztag - A module to interface your nabaztag! |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.03 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ABOUT |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Nabaztag.pm complies with nabaztag API V1 from violet company. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
old APIV01 :http://www.nabaztag.com/vl/FR/nabaztag_api_version01.pdf |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
API V1 WILL BE SOON PUBLISHED. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
See api mailing list at http://fr.groups.yahoo.com/group/nabaztag_api/ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
See help at http://www.nabaztag.com/ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
36
|
|
|
|
|
|
|
our $BASE_URL = "http://www.nabaztag.com/vl/FR/api.jsp" ; |
37
|
|
|
|
|
|
|
our $ID_APP = 11 ; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 DESCRIPTION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This module is designed to allow you to control a nabaztag with perl programming language. |
42
|
|
|
|
|
|
|
See ABOUT section to know which api it fits. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
It has been tested with my own nabaztag and seems to work perfectly. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
It also provide a simple command line tool to try your nabaztag: nabaztry (see SYNOPSIS). |
47
|
|
|
|
|
|
|
This tool is install in /usr/bin/ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
It makes great use of LWP::Simple to interact with the rabbit. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
PROXY issues: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
If you're behind a proxy, see LWP::Simple proxy issues to know how to deal with that. |
54
|
|
|
|
|
|
|
Basically, set env variable HTTP_PROXY to your proxi url in order to make it work. |
55
|
|
|
|
|
|
|
For instance : export HTTP_PROXY=http://my.proxy.company:8080/ |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Commandline: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$ nabaztry.pl MAC TOKEN POSLEFT POSRIGHT |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Perl code: |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
use Nabaztag ; # OR |
68
|
|
|
|
|
|
|
# use Nabaztag { 'debug' => 1 } ; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $nab = Nabaztag->new(); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# MANDATORY |
74
|
|
|
|
|
|
|
$nab->mac($mac); |
75
|
|
|
|
|
|
|
$nab->token($tok); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# See new function to have details about how to get these properties. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$nab->leftEarPos($left); |
80
|
|
|
|
|
|
|
$nab->rightEarPos($right); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$nab->syncState(); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
$nab->sayThis("Demain, il pleuvra des grillons jusqu'a extinction totale de la race humaine."); |
85
|
|
|
|
|
|
|
..... |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
See detailled methods for full possibilities. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Gory details : |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
You can access or modify BASE_URL by accessing: |
92
|
|
|
|
|
|
|
$Nabaztag::BASE_URL ; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
For application id : |
95
|
|
|
|
|
|
|
$Nabaztag::ID_APP ; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 FUNCTIONS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 new |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns a new software nabaztag with ears position fetched from the hardware one if the mac and token is given. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
It has following properties: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
mac : MAC Adress of nabaztag - equivalent to Serial Number ( SN ). Written at the back |
107
|
|
|
|
|
|
|
of your nabaztag !! |
108
|
|
|
|
|
|
|
token : TOKEN Given by nabaztag.com to allow interaction with you nabaztag. See |
109
|
|
|
|
|
|
|
http://www.nabaztag.com/vl/FR/api_prefs.jsp to obtain yours !! |
110
|
|
|
|
|
|
|
leftEarPos : position of left ear. |
111
|
|
|
|
|
|
|
rightEarPos : position of right ear. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
usage: |
114
|
|
|
|
|
|
|
my $nab = Nabaztag->new($mac , $token ); |
115
|
|
|
|
|
|
|
print $nab->leftEarPos(); |
116
|
|
|
|
|
|
|
print $nab->rightEarPos(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
OR: |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $nab = Nabaztag->new(); |
121
|
|
|
|
|
|
|
$nab->mac($mac); |
122
|
|
|
|
|
|
|
$nab->token($token); |
123
|
|
|
|
|
|
|
$nab->fetchEars(); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
print $nab->leftEarPos(); |
126
|
|
|
|
|
|
|
print $nab->rightEarPos(); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $debug = undef ; |
131
|
|
|
|
|
|
|
sub import{ |
132
|
|
|
|
|
|
|
#my $callerPack = caller ; |
133
|
1
|
|
|
1
|
|
11
|
my ($class, $options) = @_ ; |
134
|
1
|
50
|
|
|
|
6
|
if( ! defined $debug ){ |
135
|
1
|
|
50
|
|
|
11
|
$debug = $options->{'debug'} || 0 ; |
136
|
|
|
|
|
|
|
} |
137
|
1
|
50
|
|
|
|
16
|
print "\n\nDebug option : $debug \n\n" if ($debug); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub new { |
142
|
0
|
|
|
0
|
1
|
|
my ($class , $mac, $token ) = @_ ; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $self = { |
145
|
|
|
|
|
|
|
'mac' => undef , # MAC Adress of nabaztag - equivalent to Serial Number ( SN ) |
146
|
|
|
|
|
|
|
'token' => undef , # TOKEN Given by nabaztag.com to allow interaction with you nabaztag |
147
|
|
|
|
|
|
|
'leftEarPos' => undef , # Position of left ear |
148
|
|
|
|
|
|
|
'rightEarPos' => undef # Position of right ear |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$self = bless $self, $class ; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
$self->mac($mac) ; |
154
|
0
|
|
|
|
|
|
$self->token($token); |
155
|
0
|
0
|
0
|
|
|
|
if( $self->mac() && $self->token() ){ |
156
|
0
|
0
|
|
|
|
|
print "Trying to fetch ears position" if ( $debug ); |
157
|
0
|
|
|
|
|
|
$self->fetchEars(); |
158
|
|
|
|
|
|
|
} |
159
|
0
|
|
|
|
|
|
return $self ; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 leftEarPos |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Get/Sets the left ear position of the nabaztag. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Usage: |
167
|
|
|
|
|
|
|
$nab->leftEarPos($newPos); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
The new position has to be between 0 (vertical ear) and 16 included |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub leftEarPos{ |
174
|
0
|
|
|
0
|
1
|
|
my ($self, $pos) = @_ ; |
175
|
0
|
0
|
|
|
|
|
if( defined $pos ){ |
176
|
0
|
0
|
0
|
|
|
|
if ( ( $pos >= 0 ) && ( $pos <= 16 )){ |
177
|
0
|
|
|
|
|
|
return $self->{'leftEarPos'} = $pos ; |
178
|
|
|
|
|
|
|
}else{ |
179
|
0
|
|
|
|
|
|
confess("Position has to be between 0 and 16"); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
0
|
|
|
|
|
|
return $self->{'leftEarPos'} ; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 rightEarPos |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
See leftEarPos. Same but for right. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub rightEarPos{ |
193
|
0
|
|
|
0
|
1
|
|
my ($self, $pos) = @_ ; |
194
|
0
|
0
|
|
|
|
|
if( defined $pos ){ |
195
|
0
|
0
|
0
|
|
|
|
if ( ( $pos >= 0 ) && ( $pos <= 16 )){ |
196
|
0
|
|
|
|
|
|
return $self->{'rightEarPos'} = $pos ; |
197
|
|
|
|
|
|
|
}else{ |
198
|
0
|
|
|
|
|
|
confess("Position has to be between 0 and 16"); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
0
|
|
|
|
|
|
return $self->{'rightEarPos'} ; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 sendMessageNumber |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Given a message number, sends this message to this nabaztag. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
To obtain message numbers, go to http://www.nabaztag.com/vl/FR/messages-disco.jsp and |
210
|
|
|
|
|
|
|
choose a message !! |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Usage: |
213
|
|
|
|
|
|
|
$nab->sendMessageNumber($num); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub sendMessageNumber{ |
218
|
0
|
|
|
0
|
1
|
|
my ($self, $num ) = @_ ; |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
221
|
0
|
0
|
|
|
|
|
unless( defined $num ){ |
222
|
0
|
|
|
|
|
|
confess("No message number given"); |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
$url .= '&idmessage='.$num ; |
226
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
|
print "Accessing URL : $url\n" if ($debug); |
228
|
|
|
|
|
|
|
|
229
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent->()->get($url)->content(); |
230
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
print "content :".$content."\n" if ($debug); |
232
|
0
|
0
|
|
|
|
|
unless( defined $content ){ |
233
|
0
|
|
|
|
|
|
confess("An error occured while processing request"); |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 syncState |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Synchronise the current state of the soft nabaztag with the hardware one. |
241
|
|
|
|
|
|
|
Actually sends the state to the hardware nabaztag. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Usage: |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
$nab->syncState(); |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub syncState{ |
250
|
0
|
|
|
0
|
1
|
|
my ($self) = @_ ; |
251
|
|
|
|
|
|
|
|
252
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
253
|
|
|
|
|
|
|
|
254
|
0
|
0
|
|
|
|
|
if( defined $self->leftEarPos() ){ |
255
|
0
|
|
|
|
|
|
$url .= '&posleft='.$self->leftEarPos() ; |
256
|
|
|
|
|
|
|
} |
257
|
0
|
0
|
|
|
|
|
if( defined $self->rightEarPos() ){ |
258
|
0
|
|
|
|
|
|
$url .= '&posright='.$self->rightEarPos(); |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
|
261
|
0
|
0
|
|
|
|
|
print "Getting url:".$url."\n" if ($debug); |
262
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
263
|
0
|
0
|
|
|
|
|
print "Content:".$content."\n" if ($debug); |
264
|
0
|
0
|
|
|
|
|
unless( defined $content ){ |
265
|
0
|
|
|
|
|
|
confess("An error occured while processing request"); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 fetchEars |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Fetches the real position of ear from the device and fill |
273
|
|
|
|
|
|
|
the leftEarPos and the rightEarPos properties. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=cut |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
sub fetchEars{ |
278
|
0
|
|
|
0
|
1
|
|
my ($self) = @_ ; |
279
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
281
|
0
|
|
|
|
|
|
$url .= '&ears=ok' ; |
282
|
|
|
|
|
|
|
|
283
|
0
|
0
|
|
|
|
|
print "Accessing: ".$url."\n" if ($debug); |
284
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
285
|
0
|
0
|
|
|
|
|
print "Ear content \n".$content."\n" if ($debug); |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
my ($left , $right) = $content =~ /([0-9]+)/g ; |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
#print "Left :".$left."\n"; |
290
|
|
|
|
|
|
|
#print "Right:".$right."\n"; |
291
|
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
$self->leftEarPos($left); |
293
|
0
|
|
|
|
|
|
$self->rightEarPos($right); |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head2 sayThis |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
Makes the rabbit tell the sentence you give as parameter |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Usage: |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
$nab->sayThis("Demain, il pleuvra des grillons jusqu'a extinction totale de la race humaine."); # (example) |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=cut |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub sayThis{ |
308
|
0
|
|
|
0
|
1
|
|
my ($self, $text ) = @_ ; |
309
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
310
|
0
|
|
|
|
|
|
$url .= '&tts='.uri_escape($text) ; |
311
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
312
|
0
|
0
|
|
|
|
|
print "TTS: ".$content."\n" if ($debug); |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head2 danceThis |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
Sends a choregraphy to the rabbit, with the optionnaly given title |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Please refer to the APIV1 documentation to know how to compose your choregraphy |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Usage: |
322
|
|
|
|
|
|
|
my $chor = '10,0,motor,1,20,0,0,0,led,2,0,238,0,2,led,1,250,0,0,3,led,2,0,0,0' ; |
323
|
|
|
|
|
|
|
my $title = 'example' ; |
324
|
|
|
|
|
|
|
$nab->danceThis($chor, $title); |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=cut |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub danceThis{ |
329
|
0
|
|
|
0
|
1
|
|
my ($self, $chor, $title) = @_ ; |
330
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
331
|
0
|
|
|
|
|
|
$url .= '&chor='.uri_escape($chor) ; |
332
|
0
|
0
|
|
|
|
|
$url .= '&chortitle='.uri_escape($title) if (defined $title); |
333
|
0
|
0
|
|
|
|
|
print "Getting url:".$url."\n" if ($debug); |
334
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
335
|
0
|
0
|
|
|
|
|
print "Content :".$content."\n" if ($debug); |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head2 nabcastMessage |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Sends the given message id to the given nabcast id with given title |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
Please refer to nabaztag website to get these identifiers. |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
usage: |
345
|
|
|
|
|
|
|
$nab->nabcastMessage($nabcastId, $title, $idMessage); |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=cut |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
sub nabcastMessage{ |
350
|
0
|
|
|
0
|
1
|
|
my ($self, $nabcastID, $title, $idmessage) = @_ ; |
351
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
352
|
|
|
|
|
|
|
|
353
|
0
|
|
|
|
|
|
$url .= '&nabcast='.$nabcastID ; |
354
|
0
|
|
|
|
|
|
$url .= '&nabcasttitle='.$title ; |
355
|
0
|
|
|
|
|
|
$url .= '&idmessage='.$idmessage ; |
356
|
|
|
|
|
|
|
|
357
|
0
|
0
|
|
|
|
|
print "Accessing :".$url."\n" if ($debug); |
358
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
359
|
0
|
0
|
|
|
|
|
print "Content:".$content."\n" if ($debug) ; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
=head2 nabcastText |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
Sends the given texttosay to the given nabcast id with given title |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
Please refer to nabaztag website to get these identifiers. |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
usage: |
369
|
|
|
|
|
|
|
$nab->nabcastText($nabcastId, $title, $texttosay); |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
=cut |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
sub nabcastText{ |
375
|
0
|
|
|
0
|
1
|
|
my ($self, $nabcastID, $title, $text) = @_ ; |
376
|
0
|
|
|
|
|
|
my $url = $self->_cookUrl(); |
377
|
|
|
|
|
|
|
|
378
|
0
|
|
|
|
|
|
$url .= '&nabcast='.$nabcastID ; |
379
|
0
|
|
|
|
|
|
$url .= '&nabcasttitle='.$title ; |
380
|
0
|
|
|
|
|
|
$url .= '&tts='.uri_escape($text) ; |
381
|
|
|
|
|
|
|
|
382
|
0
|
0
|
|
|
|
|
print "Getting url.".$url."\n" if ($debug); |
383
|
0
|
|
|
|
|
|
my $content = $self->_getUserAgent()->get($url)->content(); |
384
|
0
|
0
|
|
|
|
|
print "Content:".$content."\n" if ($debug) ; |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=head2 _cookUrl |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
Returns a cooked url ready for sending something usefull |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
Usage: |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
my $url = $this->_cookUtl(); |
394
|
|
|
|
|
|
|
|
395
|
|
|
|
|
|
|
=cut |
396
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
sub _cookUrl{ |
398
|
0
|
|
|
0
|
|
|
my ($self) = @_ ; |
399
|
0
|
|
|
|
|
|
my $url = $BASE_URL.'?idapp='.$ID_APP ; |
400
|
|
|
|
|
|
|
|
401
|
0
|
|
|
|
|
|
$self->_assume('mac'); |
402
|
0
|
|
|
|
|
|
$self->_assume('token'); |
403
|
|
|
|
|
|
|
|
404
|
0
|
|
|
|
|
|
$url .= '&sn='.$self->mac() ; |
405
|
0
|
|
|
|
|
|
$url .= '&token='.$self->token() ; |
406
|
|
|
|
|
|
|
|
407
|
0
|
|
|
|
|
|
return $url ; |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
sub _getUserAgent{ |
411
|
0
|
|
|
0
|
|
|
my ($self) = @_ ; |
412
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
413
|
0
|
|
|
|
|
|
$ua->timeout(60); |
414
|
0
|
|
|
|
|
|
$ua->env_proxy; |
415
|
0
|
|
|
|
|
|
$ua->default_headers->push_header('Accept-Language' => "fr"); |
416
|
0
|
|
|
|
|
|
return $ua ; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
sub _assume{ |
421
|
0
|
|
|
0
|
|
|
my ($self, $propertie ) = @_ ; |
422
|
0
|
0
|
|
|
|
|
unless( defined $self->$propertie() ){ |
423
|
0
|
|
|
|
|
|
confess($propertie." is not set in $self\n Please set it first !"); |
424
|
|
|
|
|
|
|
} |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
=head1 AUTHOR |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
Jerome Eteve, C<< >> |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=head1 BUGS |
432
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
434
|
|
|
|
|
|
|
C, or through the web interface at |
435
|
|
|
|
|
|
|
L. |
436
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
437
|
|
|
|
|
|
|
your bug as I make changes. |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
Copyright 2005 Jerome Eteve, all rights reserved. |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
446
|
|
|
|
|
|
|
under the same terms as Perl itself. |
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
=cut |
449
|
|
|
|
|
|
|
|
450
|
|
|
|
|
|
|
1; # End of Nabaztag |