libastag 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +7 -0
- data/MIT-LICENSE +19 -0
- data/README +65 -0
- data/Rakefile +276 -0
- data/TODO +7 -0
- data/doc/classes/Helpers/REXML/Attributes.html +179 -0
- data/doc/classes/Helpers/REXML.html +115 -0
- data/doc/classes/Helpers.html +181 -0
- data/doc/classes/Libastag/Rabbit.html +462 -0
- data/doc/classes/Libastag/RabitEar.html +120 -0
- data/doc/classes/Libastag/RabitLed.html +120 -0
- data/doc/classes/Libastag.html +141 -0
- data/doc/classes/Request/Action.html +213 -0
- data/doc/classes/Request/Base/Event.html +226 -0
- data/doc/classes/Request/Base/EventCollection.html +246 -0
- data/doc/classes/Request/Base.html +134 -0
- data/doc/classes/Request/GET_EARS_POSITION.html +151 -0
- data/doc/classes/Request/Query.html +244 -0
- data/doc/classes/Request/SetEarsPosition.html +213 -0
- data/doc/classes/Request/TtsMessage.html +235 -0
- data/doc/classes/Request.html +414 -0
- data/doc/classes/Response/AbuseSending.html +165 -0
- data/doc/classes/Response/Base/BadServerRsp.html +163 -0
- data/doc/classes/Response/Base/GoodServerRsp.html +161 -0
- data/doc/classes/Response/Base/ServerRsp.html +347 -0
- data/doc/classes/Response/Base.html +162 -0
- data/doc/classes/Response/Blacklist.html +165 -0
- data/doc/classes/Response/ChorNotSend.html +166 -0
- data/doc/classes/Response/ChorSend.html +165 -0
- data/doc/classes/Response/CommandSend.html +168 -0
- data/doc/classes/Response/EarPositionNotSend.html +165 -0
- data/doc/classes/Response/EarPositionSend.html +165 -0
- data/doc/classes/Response/EmptyServerRsp.html +161 -0
- data/doc/classes/Response/LangListUser.html +166 -0
- data/doc/classes/Response/LinkPreview.html +165 -0
- data/doc/classes/Response/ListFriend.html +165 -0
- data/doc/classes/Response/ListReceivedMsg.html +165 -0
- data/doc/classes/Response/MessageNotSend.html +165 -0
- data/doc/classes/Response/MessageSend.html +165 -0
- data/doc/classes/Response/NabCastNotSend.html +169 -0
- data/doc/classes/Response/NabCastSend.html +165 -0
- data/doc/classes/Response/NoCorrectParameters.html +165 -0
- data/doc/classes/Response/NoGoodTokenOrSerial.html +165 -0
- data/doc/classes/Response/NotV2Rabbit.html +165 -0
- data/doc/classes/Response/PositionEar.html +166 -0
- data/doc/classes/Response/ProtocolExcepion.html +164 -0
- data/doc/classes/Response/RabbitName.html +164 -0
- data/doc/classes/Response/RabbitSleep.html +164 -0
- data/doc/classes/Response/RabbitVersion.html +164 -0
- data/doc/classes/Response/Signature.html +164 -0
- data/doc/classes/Response/Timezone.html +164 -0
- data/doc/classes/Response/TtsNotSend.html +168 -0
- data/doc/classes/Response/TtsSend.html +165 -0
- data/doc/classes/Response/VoiceListTts.html +165 -0
- data/doc/classes/Response/WebRadioNotSend.html +165 -0
- data/doc/classes/Response/WebRadioSend.html +165 -0
- data/doc/classes/Response.html +337 -0
- data/doc/classes/VioletAPI.html +118 -0
- data/doc/created.rid +1 -0
- data/doc/dot/f_0.dot +14 -0
- data/doc/dot/f_0.png +0 -0
- data/doc/dot/f_4.dot +57 -0
- data/doc/dot/f_4.png +0 -0
- data/doc/dot/f_5.dot +489 -0
- data/doc/dot/f_5.png +0 -0
- data/doc/dot/f_6.dot +55 -0
- data/doc/dot/f_6.png +0 -0
- data/doc/dot/f_7.dot +30 -0
- data/doc/dot/f_7.png +0 -0
- data/doc/dot/f_8.dot +142 -0
- data/doc/dot/f_8.png +0 -0
- data/doc/files/CHANGES.html +126 -0
- data/doc/files/MIT-LICENSE.html +134 -0
- data/doc/files/README.html +192 -0
- data/doc/files/TODO.html +126 -0
- data/doc/files/lib/libastag_rb.html +116 -0
- data/doc/files/lib/violet/helpers_rb.html +123 -0
- data/doc/files/lib/violet/request_rb.html +133 -0
- data/doc/files/lib/violet/response_rb.html +220 -0
- data/doc/files/lib/violet/violetapi_rb.html +114 -0
- data/doc/fr_class_index.html +79 -0
- data/doc/fr_file_index.html +35 -0
- data/doc/fr_method_index.html +56 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/lib/libastag.rb +116 -0
- data/lib/violet/helpers.rb +48 -0
- data/lib/violet/request.rb +301 -0
- data/lib/violet/response.rb +412 -0
- data/lib/violet/violetapi.rb +14 -0
- data/test/fake_violet_srv.rb +94 -0
- data/test/test_helpers.rb +31 -0
- data/test/test_request.rb +20 -0
- data/test/test_response.rb +295 -0
- data/test/test_send.rb +137 -0
- metadata +264 -0
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
=begin rdoc
|
|
2
|
+
|
|
3
|
+
==violet/request.rb
|
|
4
|
+
contains events to send to the server. Action instances are constants, because they're always the same request,
|
|
5
|
+
but other Event derivated class are used to create objects.
|
|
6
|
+
|
|
7
|
+
=end
|
|
8
|
+
|
|
9
|
+
module Request
|
|
10
|
+
require File.join( File.dirname(__FILE__), 'response.rb' )
|
|
11
|
+
|
|
12
|
+
# the VioletAPI url where we send request.
|
|
13
|
+
API_URL = 'http://api.nabaztag.com/vl/FR/api.jsp'
|
|
14
|
+
|
|
15
|
+
# the VioletAPI url for stream request.
|
|
16
|
+
APISTREAM_URL = 'http://api.nabaztag.com/vl/FR/api_stream.jsp'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# contains some basic stuff, abstract class etc. they're used internaly and you should only use derivated class.
|
|
21
|
+
module Base
|
|
22
|
+
|
|
23
|
+
# superclass of message send to Violet.
|
|
24
|
+
class Event
|
|
25
|
+
# constructor has to be overrided
|
|
26
|
+
def initialize
|
|
27
|
+
raise NotImplementedError
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# it's possible to send multiples events on a single request.
|
|
31
|
+
def + other
|
|
32
|
+
EventCollection.new self, other
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# to_url has to be overrided
|
|
36
|
+
def to_url
|
|
37
|
+
raise NotImplementedError
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# combine many Event in a single request
|
|
43
|
+
class EventCollection < Event
|
|
44
|
+
include Enumerable
|
|
45
|
+
|
|
46
|
+
# create a new EventCollection with two childrens.
|
|
47
|
+
def initialize one, another
|
|
48
|
+
if one.respond_to?(:to_url) and another.respond_to?(:to_url) # \_o< Coin !
|
|
49
|
+
@childrens = [ one, another ]
|
|
50
|
+
else
|
|
51
|
+
raise ArgumentError.new('bad parameters')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# needed by Enumerable module.
|
|
56
|
+
# usage should be obvious :)
|
|
57
|
+
def each
|
|
58
|
+
@childrens.each do |e|
|
|
59
|
+
if e.kind_of? Enumerable
|
|
60
|
+
e.each { |i| yield i }
|
|
61
|
+
else
|
|
62
|
+
yield e
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# override Event#to_url.
|
|
68
|
+
def to_url
|
|
69
|
+
@childrens.collect { |e| e.to_url }.join('&')
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end # module Request::Base
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# this class is used to "translate" our Events into URLs.
|
|
78
|
+
# Examples:
|
|
79
|
+
# TODO
|
|
80
|
+
# see http://api.nabaztag.com/docs/home.html
|
|
81
|
+
class Query
|
|
82
|
+
require 'open-uri'
|
|
83
|
+
|
|
84
|
+
# create a new Query object with the give parameters. +serial+ and +token+ parameters should be checked at
|
|
85
|
+
# a higher level. +event+ parameter is usually an Event object, but you can give any Object that respond to
|
|
86
|
+
# to_url.
|
|
87
|
+
def initialize h
|
|
88
|
+
raise ArgumentError.new('event parameter has no "to_url" method or is empty') unless h[:event] and h[:event].respond_to?(:to_url)
|
|
89
|
+
raise ArgumentError.new('need a :serial') unless h[:serial]
|
|
90
|
+
raise ArgumentError.new('need a :token' ) unless h[:token]
|
|
91
|
+
|
|
92
|
+
@event, @serial, @token = h[:event], h[:serial], h[:token]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# return the complet url: API_URL with the +serial+, +token+ and options.
|
|
96
|
+
def to_url
|
|
97
|
+
API_URL+'?' << [ "token=#{@token}", "sn=#{@serial}", @event.to_url ].join('&')
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# TODO
|
|
101
|
+
def send! response_type=nil
|
|
102
|
+
# TODO: rescue ?
|
|
103
|
+
rsp = open(self.to_url) { |rsp| rsp.read }
|
|
104
|
+
if response_type == :xml then rsp else Response.parse(rsp) end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class SetEarsPosition < Base::Event
|
|
111
|
+
MIN_POS = 0
|
|
112
|
+
MAX_POS = 16
|
|
113
|
+
|
|
114
|
+
def initialize h
|
|
115
|
+
@h = h.dup
|
|
116
|
+
raise ArgumentError.new('at least :posright or :posleft must be set') unless @h[:posleft] or @h[:posright]
|
|
117
|
+
raise ArgumentError.new(":posright must be between #{MIN_POS} and #{MAX_POS}") if @h[:posright] and not @h[:posright].to_i.between?(MIN_POS,MAX_POS)
|
|
118
|
+
raise ArgumentError.new(":posleft must be between #{MIN_POS} and #{MAX_POS}") if @h[:posleft ] and not @h[:posleft ].to_i.between?(MIN_POS,MAX_POS)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def to_url
|
|
123
|
+
url = Array.new
|
|
124
|
+
url << "posleft=#{h[:posleft].to_i}" if h[:posleft]
|
|
125
|
+
url << "posright=#{h[:posright].to_i}" if h[:posright]
|
|
126
|
+
url.join('&')
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class TtsMessage < Base::Event
|
|
132
|
+
require 'cgi'
|
|
133
|
+
MIN_SPEED = 1
|
|
134
|
+
MAX_SPEED = 32000
|
|
135
|
+
|
|
136
|
+
MIN_PITCH = 1
|
|
137
|
+
MAX_PITCH = 32000
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def initialize h
|
|
141
|
+
raise ArgumentError.new('no text given') unless h[:tts]
|
|
142
|
+
@h = h.dup
|
|
143
|
+
|
|
144
|
+
[:speed,:pitch].each do |p|
|
|
145
|
+
min = Helpers.constantize("#{self.class}::MIN_#{p.to_s.upcase}")
|
|
146
|
+
max = Helpers.constantize("#{self.class}::MAX_#{p.to_s.upcase}")
|
|
147
|
+
|
|
148
|
+
unless @h[p].to_i.between?(min,max)
|
|
149
|
+
raise ArgumentError.new("#{p} values must be between #{min} and #{max}")
|
|
150
|
+
else
|
|
151
|
+
@h[p] = @h[p].to_i
|
|
152
|
+
end if @h[p]
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
@h[:tts] = CGI.escape @h[:tts]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def to_url
|
|
159
|
+
for p in [:tts,:voice,:speed,:pitch] do
|
|
160
|
+
(url ||= Array.new) << "#{p}=#{@h[p]}" if @h[p]
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
url.join('&')
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
#
|
|
169
|
+
# Actions list.
|
|
170
|
+
#
|
|
171
|
+
# see http://api.nabaztag.com/docs/home.html#getinfo
|
|
172
|
+
#
|
|
173
|
+
|
|
174
|
+
# actions are used to retrieve informations about the Nabaztag or the Nabaztag's owners.
|
|
175
|
+
# see constants of Request module, all Action are Request constant that begin with GET or
|
|
176
|
+
# SET. Request::GET_EARS_POSITION is not an Action in the violet API, but we implement it as it was.
|
|
177
|
+
#
|
|
178
|
+
# see http://api.nabaztag.com/docs/home.html#getinfo
|
|
179
|
+
class Action < Base::Event
|
|
180
|
+
# create a new Action with +id+
|
|
181
|
+
def initialize id
|
|
182
|
+
@id = id
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Action have only action= option.
|
|
186
|
+
def to_url
|
|
187
|
+
"action=#{@id}"
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# Preview the TTS or music (with music id) without sending it
|
|
193
|
+
# Examples:
|
|
194
|
+
# Query.new(:event => GET_LINKPREVIEW, :serial => my_serial, :token => my_token).send! # => #<Response::LinkPreview:0x2aaaab100f88 @xml=<UNDEFINED> ... </>>
|
|
195
|
+
# see Response::LinkPreview
|
|
196
|
+
GET_LINKPREVIEW = Action.new 1
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# Get a list of your friends
|
|
200
|
+
# Examples:
|
|
201
|
+
# Query.new(:event => GET_FRIENDS_LIST, :serial => my_serial, :token => my_token).send! # => #<Response::ListFriend:0x2af08fd53568 @xml=<UNDEFINED> ... </>>
|
|
202
|
+
# see Response::ListFriend
|
|
203
|
+
GET_FRIENDS_LIST = Action.new 2
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
# Get a count and the list of the messages in your inbox
|
|
207
|
+
# Examples:
|
|
208
|
+
# Query.new(:event => GET_INBOX_LIST, :serial => my_serial, :token => my_token).send! # => #<Response::ListReceivedMsg:0x2aaaab0e0be8 @xml=<UNDEFINED> ... </>>
|
|
209
|
+
# see Response::ListReceivedMsg
|
|
210
|
+
GET_INBOX_LIST = Action.new 3
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
# Get the timezone in which your Nabaztag is set
|
|
214
|
+
# Examples:
|
|
215
|
+
# Query.new(:event => GET_TIMEZONE, :serial => my_serial, :token => my_token).send! # => #<Response::Timezone:0x2af091e58f60 @xml=<UNDEFINED> ... </>>
|
|
216
|
+
# see Response::Timezone
|
|
217
|
+
GET_TIMEZONE = Action.new 4
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
# Get the signature defined for the Nabaztag
|
|
221
|
+
# Examples:
|
|
222
|
+
# Query.new(:event => GET_SIGNATURE, :serial => my_serial, :token => my_token).send! # => #<Response::Signature:0x2aaaab0c8c28 @xml=<UNDEFINED> ... </>>
|
|
223
|
+
# see Response::Signature
|
|
224
|
+
GET_SIGNATURE = Action.new 5
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
# Get a count and the list of people in your blacklist
|
|
228
|
+
# Examples:
|
|
229
|
+
# Query.new(:event => GET_BLACKLISTED, :serial => my_serial, :token => my_token).send! # => #<Response::Blacklist:0x2aaaab0b0ad8 @xml=<UNDEFINED> ... </>>
|
|
230
|
+
# see Response::Blacklist
|
|
231
|
+
GET_BLACKLISTED = Action.new 6
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# Get to know if the Nabaztag is sleeping (YES) or not (NO)
|
|
235
|
+
# Examples:
|
|
236
|
+
# Query.new(:event => GET_RABBIT_STATUS, :serial => my_serial, :token => my_token).send! # => #<Response::RabbitSleep:0x2aaaab092a88 @xml=<UNDEFINED> ... </>>
|
|
237
|
+
# see Response::RabbitSleep
|
|
238
|
+
GET_RABBIT_STATUS = Action.new 7
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
# Get to know if the Nabaztag is a Nabaztag (V1) or a Nabaztag/tag (V2)
|
|
242
|
+
# Examples:
|
|
243
|
+
# Query.new(:event => GET_RABBIT_VERSION, :serial => my_serial, :token => my_token).send! # => #<Response::RabbitVersion:0x2aaaab07c418 @xml=<UNDEFINED> ... </>>
|
|
244
|
+
# see Response::RabbitVersion
|
|
245
|
+
GET_RABBIT_VERSION = Action.new 8
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# Get a list of all supported languages/voices for TTS (text to speach) engine
|
|
249
|
+
# Examples:
|
|
250
|
+
# Query.new(:event => GET_LANG_VOICE, :serial => my_serial, :token => my_token).send! # => #<Response::VoiceListTts:0x2aaaab064368 @xml=<UNDEFINED> ... </>>
|
|
251
|
+
# see Response::VoiceListTts
|
|
252
|
+
GET_LANG_VOICE = Action.new 9
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# Get the name of the Nabaztag
|
|
256
|
+
# Examples:
|
|
257
|
+
# Query.new(:event => GET_RABBIT_NAME, :serial => my_serial, :token => my_token).send! # => #<Response::RabbitName:0x2aaaab0459b8 @xml=<UNDEFINED> ... </>>
|
|
258
|
+
# see Response::RabbitName
|
|
259
|
+
GET_RABBIT_NAME = Action.new 10
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
# Get the languages selected for the Nabaztag
|
|
263
|
+
# Examples:
|
|
264
|
+
# Query.new(:event => GET_SELECTED_LANG, :serial => my_serial, :token => my_token).send! # => #<Response::LangListUser:0x2aaaab02bfb8 @xml=<UNDEFINED> ... </>>
|
|
265
|
+
# see Response::LangListUser
|
|
266
|
+
GET_SELECTED_LANG = Action.new 11
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
# Get a preview of a message. This works only with the urlPlay parameter and URLs like broad/001/076/801/262.mp3
|
|
270
|
+
# Examples:
|
|
271
|
+
# Query.new(:event => GET_MESSAGE_PREVIEW, :serial => my_serial, :token => my_token).send! # => #<Response::LinkPreview:0x2aaaab011258 @xml=<UNDEFINED> ... </>>
|
|
272
|
+
# see Response::LinkPreview
|
|
273
|
+
GET_MESSAGE_PREVIEW = Action.new 12
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
# Get the position of the ears to your Nabaztag. this request is not an action in the Violet API but we do as
|
|
277
|
+
# if it was because it's make more sens (to me).
|
|
278
|
+
# Examples:
|
|
279
|
+
# Query.new(:event => GET_EARS_POSITION, :serial => my_serial, :token => my_token).send! # => #<Response::PositionEar:0x2aaaaaff6908 @xml=<UNDEFINED> ... </>>
|
|
280
|
+
# see Response::PositionEar
|
|
281
|
+
GET_EARS_POSITION = Action.new nil
|
|
282
|
+
|
|
283
|
+
def GET_EARS_POSITION.to_url
|
|
284
|
+
'ears=ok'
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
# Send your Rabbit to sleep
|
|
289
|
+
# Examples:
|
|
290
|
+
# Query.new(:event => SET_RABBIT_ASLEEP, :serial => my_serial, :token => my_token).send! # => #<Response::CommandSend:0x2aaaaafbf980 @xml=<UNDEFINED> ... </>>
|
|
291
|
+
# see Response::CommandSend
|
|
292
|
+
SET_RABBIT_ASLEEP = Action.new 13
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# Wake up your Rabbit
|
|
296
|
+
# Examples:
|
|
297
|
+
# Query.new(:event => SET_RABBIT_AWAKE, :serial => my_serial, :token => my_token).send! # => #<Response::CommandSend:0x2aaaaafa60c0 @xml=<UNDEFINED> ... </>>
|
|
298
|
+
# see Response::CommandSend
|
|
299
|
+
SET_RABBIT_AWAKE = Action.new 14
|
|
300
|
+
|
|
301
|
+
end # module Request
|