lleidasms 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +100 -83
- data/Rakefile +5 -0
- data/lib/lleidasms/client.rb +318 -30
- data/lib/lleidasms/gateway.rb +228 -66
- data/lib/lleidasms/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,83 +1,100 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
-
|
10
|
-
|
11
|
-
|
12
|
-
##
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
```
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
|
1
|
+
|
2
|
+
#Lleidasms
|
3
|
+
A [Lleida.net](http://lleida.net/) SMS gateway for Ruby.
|
4
|
+
|
5
|
+
#Description
|
6
|
+
Receive and send standar and premium SMS/MMS using [Lleida.net](http://lleida.net/) services.
|
7
|
+
|
8
|
+
##Features
|
9
|
+
- client class
|
10
|
+
- gateway superclass for new client implementations
|
11
|
+
|
12
|
+
##Protocol implementation (78%)
|
13
|
+
- Comandos Generales (100%)
|
14
|
+
* implemented: saldo, ping, pong, infonum, tarifa, quit
|
15
|
+
- Comandos para el envíıo de MT simples (100%)
|
16
|
+
* implemented: submit, bsubmit, usubmit, fsubmit, fbsubmit, fusubmit, dsubmit, dbsubmit, dusubmit, dfsubmit, dbfsubmit, dfusubmit, waplink, dst, msg, filemsg, mmsmsg, envia, acuseon, acuseoff, acuse, acuseack, trans
|
17
|
+
- Comandos para la recepcion de SMS (NO Premium) (100%)
|
18
|
+
* implemented: allowanswer, incomingmo, incomingmoack
|
19
|
+
- Comandos para la recepcion de SMS (Premium) (0%)
|
20
|
+
* implemented: none
|
21
|
+
* TODO: deliver, resp, bresp, waplinkresp
|
22
|
+
- Comandos para la resolucion de MSIDSN (0%)
|
23
|
+
* implemented: none
|
24
|
+
* TODO: checkall, rcheckall, checknetwork, rchecknetwork
|
25
|
+
|
26
|
+
More info in [Lleida.net Developers Network](http://soporte.lleida.net/?p=35)
|
27
|
+
|
28
|
+
#Installation
|
29
|
+
##From the command line
|
30
|
+
|
31
|
+
```shell
|
32
|
+
gem install lleidasms
|
33
|
+
```
|
34
|
+
|
35
|
+
##Using Gemfile
|
36
|
+
|
37
|
+
1 Add to your application Gemfile
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
gem 'lleidasms'
|
41
|
+
```
|
42
|
+
|
43
|
+
2 Type
|
44
|
+
|
45
|
+
```shell
|
46
|
+
bundle install
|
47
|
+
```
|
48
|
+
|
49
|
+
# Examples
|
50
|
+
## Demo
|
51
|
+
```shell
|
52
|
+
lleidasms YOUR_USER YOUR_PASSWORD
|
53
|
+
```
|
54
|
+
|
55
|
+
or
|
56
|
+
|
57
|
+
```shell
|
58
|
+
lleidasms_client YOUR_USER YOUR_PASSWORD
|
59
|
+
```
|
60
|
+
|
61
|
+
## Using default client class
|
62
|
+
```ruby
|
63
|
+
sms = Lleidasms::Client.new
|
64
|
+
sms.connect <YOUR_USER>, <YOUR_PASSWORD>
|
65
|
+
puts sms.saldo
|
66
|
+
sms.close
|
67
|
+
```
|
68
|
+
|
69
|
+
## Creating a new client
|
70
|
+
```ruby
|
71
|
+
class SMS < Lleidasms::Gateway
|
72
|
+
event :INCOMINGMO, :new_sms
|
73
|
+
|
74
|
+
def new_sms label, cmd, args
|
75
|
+
id = args.shift
|
76
|
+
time = args.shift
|
77
|
+
from = args.shift
|
78
|
+
to = args.shift
|
79
|
+
sms = args.join(' ')
|
80
|
+
puts " id #{id}"
|
81
|
+
puts " time #{time}"
|
82
|
+
puts " from #{from}"
|
83
|
+
puts " to #{to}"
|
84
|
+
puts " sms #{sms}"
|
85
|
+
cmd_incomingmoack id, label
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
sms = SMS.new
|
90
|
+
sms.connect
|
91
|
+
sms.listener
|
92
|
+
sms.cmd_login <YOUR_USER>, <YOUR_PASSWORD>
|
93
|
+
|
94
|
+
while sms.conected?
|
95
|
+
# Some tasks
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
# License
|
100
|
+
Released under the MIT license: [http://www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT)
|
data/Rakefile
CHANGED
data/lib/lleidasms/client.rb
CHANGED
@@ -3,56 +3,344 @@ require "gateway"
|
|
3
3
|
|
4
4
|
module Lleidasms
|
5
5
|
class Client < Lleidasms::Gateway
|
6
|
-
|
6
|
+
event :all, :new_event
|
7
|
+
event :acuse, :new_acuse
|
8
|
+
event :incomingmo, :new_incomingmo
|
7
9
|
|
8
10
|
attr_accessor :timeout
|
9
11
|
|
10
|
-
def connect
|
11
|
-
|
12
|
-
|
13
|
-
cmd_login
|
12
|
+
def connect user, password, timeout = 2.4
|
13
|
+
super()
|
14
|
+
listener
|
15
|
+
cmd_login user, password
|
14
16
|
self.timeout= timeout
|
17
|
+
@acuse = []
|
18
|
+
@incomingmo = []
|
15
19
|
end
|
16
20
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
def saldo
|
22
|
+
cmd_saldo
|
23
|
+
return false unless wait_for last_label
|
24
|
+
return @response_args[0]
|
25
|
+
end
|
26
|
+
|
27
|
+
# *number*
|
28
|
+
# The telephone number
|
29
|
+
def tarifa number
|
30
|
+
cmd_tarifa number
|
31
|
+
return false unless wait_for last_label
|
32
|
+
return @response_args
|
33
|
+
end
|
34
|
+
|
35
|
+
# *number*
|
36
|
+
# The telephone number
|
37
|
+
# *message*
|
38
|
+
# The string to send
|
39
|
+
# *opts*
|
40
|
+
# - nowait: (default false) no wait for response
|
41
|
+
# - sender: The sender telephone number
|
42
|
+
# - date: Date and time to send message in format YYYYMMDDhhmm[+-]ZZzz
|
43
|
+
# - encode
|
44
|
+
# * :ascii (default)
|
45
|
+
# * :binary message is in base64 encoded
|
46
|
+
# * :base64 message is in base64 encoded
|
47
|
+
# * :unicode message is in unicode and base64 encoded
|
48
|
+
def send_sms number, message, opts={}
|
49
|
+
wait =!(opts[:nowait] || false)
|
50
|
+
encode = opts[:encode] || :ascii
|
51
|
+
sender = opts[:sender] || false
|
52
|
+
datetime = opts[:date] || false
|
53
|
+
|
54
|
+
case encode
|
55
|
+
when :binary || :base64
|
56
|
+
encode = 'B'
|
57
|
+
when :unicode
|
58
|
+
encode = 'U'
|
59
|
+
else # :ascii
|
60
|
+
encode = ''
|
61
|
+
end
|
62
|
+
|
63
|
+
if sender
|
64
|
+
sender = "#{sender} "
|
65
|
+
custom = 'F'
|
66
|
+
else
|
67
|
+
custom = ''
|
68
|
+
end
|
69
|
+
|
70
|
+
if datetime
|
71
|
+
datetime = "#{datetime} "
|
72
|
+
date = 'D'
|
73
|
+
else
|
74
|
+
date = ''
|
75
|
+
end
|
76
|
+
|
77
|
+
cmd_raw "#{date}#{custom}#{encode}SUBMIT", "#{datetime}#{sender}#{number} #{message}"
|
78
|
+
|
79
|
+
if wait
|
80
|
+
wait_for last_label
|
81
|
+
return false if @response_cmd.eql? 'NOOK'
|
82
|
+
return "#{@response_args[0]}.#{@response_args[1]}".to_f
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# *number*
|
87
|
+
# The telephone number
|
88
|
+
# *url*
|
89
|
+
# The URL to content. Usually a image, tone or application
|
90
|
+
# *message*
|
91
|
+
# Information text before downloading content
|
92
|
+
def send_waplink number, url, message
|
93
|
+
cmd_waplink number, url, message
|
94
|
+
|
95
|
+
if wait
|
96
|
+
wait_for last_label
|
97
|
+
return false if @response_cmd.eql? 'NOOK'
|
98
|
+
return "#{@response_args[0]}.#{@response_args[1]}".to_f
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Add telephone numbers into the massive send list.
|
103
|
+
# It is recommended not to send more than 50 in each call
|
104
|
+
#
|
105
|
+
# Return TRUE if ok
|
106
|
+
# - see accepted in *last_addressees_accepted*
|
107
|
+
# - see rejected in *last_addressees_rejected*
|
108
|
+
def add_addressee addressees, wait = true
|
109
|
+
@addressees_accepted = false
|
110
|
+
@addressees_rejected = false
|
111
|
+
if addressees.kind_of?(Array)
|
112
|
+
addressees = addressees.join ' '
|
113
|
+
end
|
114
|
+
|
115
|
+
cmd_dst addressees
|
116
|
+
|
117
|
+
while wait && !@addressees_accepted
|
118
|
+
wait_for last_label
|
119
|
+
return false if !add_addressee_results
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def last_addressees_accepted
|
124
|
+
return @addressees_accepted
|
125
|
+
end
|
126
|
+
|
127
|
+
def last_addressees_rejected
|
128
|
+
return @addressees_rejected
|
129
|
+
end
|
130
|
+
|
131
|
+
# Set the message for the massive send list
|
132
|
+
def msg message, wait = true
|
133
|
+
cmd_msg message
|
134
|
+
return false unless wait_for(last_label) if wait
|
135
|
+
return @response_args
|
136
|
+
end
|
137
|
+
|
138
|
+
# Set file content (base64 encded) as message for the massive send list
|
139
|
+
# *data* file contenten base64 encoded
|
140
|
+
# Available types:
|
141
|
+
# * :jpeg image JPEG
|
142
|
+
# * :gif image GIF
|
143
|
+
# * :midi polyfonic melody MIDI
|
144
|
+
# * :sp_midi polyfonic melody SP-MIDI
|
145
|
+
# * :amr sound AMR
|
146
|
+
# * :mp3 sound MP3
|
147
|
+
# * :gpp video 3GP
|
148
|
+
# * :java application JAVA
|
149
|
+
# * :symbian application Symbian
|
150
|
+
def filemsg type, data, wait = true
|
151
|
+
cmd_filemsg type, data
|
152
|
+
return false unless wait_for(last_label) if wait
|
153
|
+
return @response_args
|
154
|
+
end
|
155
|
+
|
156
|
+
# Set file content (base64 encded) as message for the massive send list
|
157
|
+
# *data* file contenten base64 encoded
|
158
|
+
# *title* Information title before downloading content
|
159
|
+
# *message* Information text before downloading content
|
160
|
+
# Available types:
|
161
|
+
# * :jpeg image JPEG
|
162
|
+
# * :gif image GIF
|
163
|
+
# * :midi polyfonic melody MIDI
|
164
|
+
# * :sp_midi polyfonic melody SP-MIDI
|
165
|
+
# * :amr sound AMR
|
166
|
+
# * :mp3 sound MP3
|
167
|
+
# * :gpp video 3GP
|
168
|
+
# * :java application JAVA
|
169
|
+
# * :symbian application Symbian
|
170
|
+
def mmsmsg type, data, title, message, wait = true
|
171
|
+
cmd_mmsmsg type, data, title, message
|
172
|
+
return false unless wait_for(last_label) if wait
|
173
|
+
return @response_args
|
174
|
+
end
|
22
175
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
return @response_args
|
27
|
-
end
|
176
|
+
# Send message/file to the massive send list
|
177
|
+
def send_all wait = true
|
178
|
+
cmd_envia
|
28
179
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
180
|
+
if wait
|
181
|
+
wait_for last_label
|
182
|
+
return false if @response_cmd.eql? 'NOOK'
|
183
|
+
return "#{@response_args[0]}.#{@response_args[1]}".to_f
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# *opts*
|
188
|
+
# - nowait: (default false) no wait for response
|
189
|
+
# - cert: true/false (default false) use certificated confirmations
|
190
|
+
# - lang
|
191
|
+
# * :es Spanish (default)
|
192
|
+
# * :ca Catalan
|
193
|
+
# * :en English
|
194
|
+
# * :fr French
|
195
|
+
# * :de German
|
196
|
+
# * :it Italian
|
197
|
+
# * :nl Dutch
|
198
|
+
# * :pt Portuguese
|
199
|
+
# * :pl Polish
|
200
|
+
# * :se Swedish
|
201
|
+
def acuseon opts={}
|
202
|
+
wait =!(opts[:nowait] || false)
|
203
|
+
lang = opts[:lang] || false
|
204
|
+
cert = opts[:cert] || false
|
205
|
+
email = opts[:email] || 'INTERNAL'
|
206
|
+
|
207
|
+
cmd_acuseon lang, cert ? 'D' : false, email
|
208
|
+
|
209
|
+
return false unless wait_for(last_label) if wait
|
210
|
+
true
|
211
|
+
end
|
212
|
+
|
213
|
+
def acuseoff wait = true
|
214
|
+
cmd_acuseoff
|
215
|
+
return false unless wait_for(last_label) if wait
|
216
|
+
true
|
217
|
+
end
|
218
|
+
|
219
|
+
def acuse?
|
220
|
+
@acuse.count > 0
|
221
|
+
end
|
222
|
+
|
223
|
+
def incomingmo?
|
224
|
+
@incomingmo.count > 0
|
225
|
+
end
|
226
|
+
|
227
|
+
# Return hash or false
|
228
|
+
# - :id
|
229
|
+
# - :destino
|
230
|
+
# - :timestamp_acuse
|
231
|
+
# - :estado
|
232
|
+
# * :acked Entregado a la operadora correctamente
|
233
|
+
# * :buffred Telefono apagado o fuera de cobertura
|
234
|
+
# * :failed El mensaje no se puede entregar en destino
|
235
|
+
# * :delivrd El mesaje ha sido entregado en destino
|
236
|
+
# - :timestamp_envio
|
237
|
+
# - :texto
|
238
|
+
def acuse
|
239
|
+
return false unless acuse?
|
240
|
+
row = @acuse.shift
|
241
|
+
return {
|
242
|
+
id: row[0],
|
243
|
+
destino: row[1],
|
244
|
+
timestamp_acuse: row[2],
|
245
|
+
estado: row[3].to_sym,
|
246
|
+
timestamp_envio: row[4],
|
247
|
+
texto: row[5] || ''
|
248
|
+
}
|
249
|
+
end
|
250
|
+
|
251
|
+
# - wait: (default false) no wait for response
|
252
|
+
# - action
|
253
|
+
# * :begin
|
254
|
+
# * :end
|
255
|
+
# * :abort
|
256
|
+
def trans action, wait = true
|
257
|
+
return false unless cmd_trans action
|
258
|
+
if wait
|
259
|
+
wait_for last_label
|
260
|
+
return false if @response_cmd.eql? 'NOOK'
|
261
|
+
return false if @response_args[1].eql? 'NOOK'
|
262
|
+
return true if @response_args[0].eql? 'INICIAR'
|
263
|
+
return true if @response_args[0].eql? 'ABORTAR'
|
264
|
+
return "#{@response_args[2]}.#{@response_args[3]}".to_f
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
def trans_begin wait = true
|
269
|
+
trans :begin, wait
|
270
|
+
end
|
271
|
+
|
272
|
+
def trans_end wait = true
|
273
|
+
trans :end, wait
|
274
|
+
end
|
275
|
+
|
276
|
+
def trans_abort wait = true
|
277
|
+
trans :abort, wait
|
278
|
+
end
|
279
|
+
|
280
|
+
def allowanswer on = true, wait = true
|
281
|
+
cmd_allowanswer on
|
282
|
+
wait_for last_label if wait
|
283
|
+
end
|
284
|
+
|
285
|
+
# Return hash or false
|
286
|
+
# - :id
|
287
|
+
# - :timestamp
|
288
|
+
# - :remitente
|
289
|
+
# - :destino
|
290
|
+
# - :texto
|
291
|
+
def incomingmo
|
292
|
+
return false unless incomingmo?
|
293
|
+
row = @incomingmo.shift
|
294
|
+
return {
|
295
|
+
id: row.shift,
|
296
|
+
timestamp: row.shift,
|
297
|
+
remitente: row.shift,
|
298
|
+
destino: row.shift,
|
299
|
+
texto: row.join(' ')
|
300
|
+
}
|
301
|
+
end
|
33
302
|
|
34
303
|
private
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
304
|
+
def add_addressee_results
|
305
|
+
@addressees_rejected = @response_cmd_hash['REJDST'] if @response_cmd_hash['REJDST']
|
306
|
+
@addressees_accepted = @response_cmd_hash['OK'] if @response_cmd_hash['OK']
|
307
|
+
return false if @response_cmd.eql? 'NOOK'
|
308
|
+
return true
|
309
|
+
end
|
310
|
+
|
311
|
+
def new_event label, cmd, args
|
312
|
+
@event_label = label
|
313
|
+
@event_cmd = cmd
|
314
|
+
@event_args = args
|
39
315
|
if @wait_for_label.eql? @event_label
|
40
316
|
@wait = false
|
41
|
-
|
42
|
-
|
43
|
-
|
317
|
+
@response_label = label
|
318
|
+
@response_cmd = cmd
|
319
|
+
@response_args = args
|
320
|
+
@response_cmd_hash[cmd] = args
|
44
321
|
end
|
45
322
|
end
|
46
323
|
|
47
|
-
def wait_for
|
324
|
+
def wait_for label
|
325
|
+
@response_cmd_hash = {}
|
48
326
|
@wait_for_label = label.to_s
|
49
327
|
@wait = true
|
50
328
|
t = Time.new
|
51
|
-
|
329
|
+
while @wait do
|
52
330
|
sleep 0.2
|
53
331
|
return false if @timeout < (Time.new - t)
|
54
|
-
|
55
|
-
|
332
|
+
end
|
333
|
+
return true
|
334
|
+
end
|
335
|
+
|
336
|
+
def new_acuse label, cmd, args
|
337
|
+
@acuse << args
|
338
|
+
cmd_acuseack args[0]
|
339
|
+
end
|
340
|
+
|
341
|
+
def new_incomingmo label, cmd, args
|
342
|
+
@incomingmo << args
|
343
|
+
cmd_incomingmoack args[0]
|
56
344
|
end
|
57
345
|
|
58
346
|
end
|
data/lib/lleidasms/gateway.rb
CHANGED
@@ -5,7 +5,7 @@ require "io/wait"
|
|
5
5
|
module Lleidasms
|
6
6
|
class Gateway
|
7
7
|
# Client
|
8
|
-
def initialize
|
8
|
+
def initialize host = 'sms.lleida.net', port = 2048
|
9
9
|
@host = host
|
10
10
|
@port = port
|
11
11
|
@my_label = 0
|
@@ -16,33 +16,33 @@ module Lleidasms
|
|
16
16
|
$output_buffer = String.new
|
17
17
|
|
18
18
|
$reader = lambda do |line|
|
19
|
-
|
20
|
-
|
19
|
+
$input_buffer << line.strip
|
20
|
+
parser
|
21
21
|
end
|
22
22
|
$writer = lambda do |buffer|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
$server.puts "#{buffer}\r\n"
|
24
|
+
puts "<#{buffer}\r\n"
|
25
|
+
buffer.replace ''
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
def connect
|
30
30
|
begin
|
31
|
-
|
32
|
-
|
31
|
+
$server = TCPSocket.new @host, @port
|
32
|
+
$conected = true
|
33
33
|
rescue
|
34
34
|
$conected = false
|
35
|
-
|
36
|
-
|
35
|
+
puts "Unable to open a connection."
|
36
|
+
exit
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def listener
|
41
|
-
Thread.new
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
Thread.new $server do |socket|
|
42
|
+
while line = socket.gets
|
43
|
+
$reader[line]
|
44
|
+
end
|
45
|
+
close!
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -63,26 +63,26 @@ module Lleidasms
|
|
63
63
|
# Callbacks
|
64
64
|
$callbacks = {}
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
def self.event name, method_name
|
67
|
+
$callbacks[name] = [] unless $callbacks[name]
|
68
68
|
$callbacks[name] << method_name
|
69
|
-
|
69
|
+
end
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
def do_event name
|
72
|
+
run_event name.to_sym, @label, @cmd, @args
|
73
|
+
end
|
74
74
|
|
75
|
-
|
76
|
-
run_event_for
|
75
|
+
def run_event name, *args
|
76
|
+
run_event_for name.to_sym, self, *args
|
77
77
|
end
|
78
78
|
|
79
|
-
def run_event_for
|
80
|
-
|
79
|
+
def run_event_for name, scope, *args
|
80
|
+
return unless $callbacks[name.to_sym]
|
81
81
|
$callbacks[name.to_sym].each do |callback|
|
82
82
|
if callback.kind_of? Symbol
|
83
|
-
scope.send
|
83
|
+
scope.send callback, *args
|
84
84
|
else
|
85
|
-
scope.instance_exec
|
85
|
+
scope.instance_exec *args, &callback
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -97,86 +97,248 @@ module Lleidasms
|
|
97
97
|
@my_label
|
98
98
|
end
|
99
99
|
|
100
|
+
def cmd_raw cmd, args, label_response = new_label
|
101
|
+
$writer[label_response + " #{cmd} #{args}"]
|
102
|
+
end
|
103
|
+
|
100
104
|
# CMD Generales
|
101
|
-
def cmd_login
|
105
|
+
def cmd_login user, password, label_response = new_label
|
102
106
|
$writer[label_response + " LOGIN #{user} #{password}"]
|
103
107
|
end
|
104
108
|
|
105
|
-
def cmd_ping
|
109
|
+
def cmd_ping time = Time.now.to_i.to_s, label_response = new_label
|
106
110
|
$writer[label_response + " PING "+ time]
|
107
111
|
end
|
108
112
|
|
109
|
-
def cmd_pong
|
113
|
+
def cmd_pong time = Time.now.to_i.to_s, label_response = new_label
|
110
114
|
$writer[label_response + " PONG "+ time]
|
111
115
|
end
|
112
116
|
|
113
|
-
def cmd_saldo
|
117
|
+
def cmd_saldo label_response = new_label
|
114
118
|
$writer[label_response + " SALDO"]
|
115
119
|
end
|
116
120
|
|
117
|
-
def cmd_infonum
|
118
|
-
$writer[label_response + " INFONUM #{
|
121
|
+
def cmd_infonum number, label_response = new_label
|
122
|
+
$writer[label_response + " INFONUM #{number}"]
|
119
123
|
end
|
120
124
|
|
121
|
-
def cmd_tarifa
|
122
|
-
$writer[label_response + " TARIFA #{
|
125
|
+
def cmd_tarifa number, label_response = new_label
|
126
|
+
$writer[label_response + " TARIFA #{number}"]
|
123
127
|
end
|
124
128
|
|
125
|
-
def cmd_quit
|
129
|
+
def cmd_quit label_response = new_label
|
126
130
|
$writer[label_response + " QUIT"]
|
127
131
|
end
|
128
132
|
# CMD Generales end
|
129
133
|
|
130
134
|
# CMD Envios MT
|
135
|
+
def cmd_submit number, message, label_response = new_label
|
136
|
+
$writer[label_response + " SUBMIT #{number} #{message}"]
|
137
|
+
end
|
138
|
+
|
139
|
+
def cmd_bsubmit number, message, label_response = new_label
|
140
|
+
$writer[label_response + " BSUBMIT #{number} #{message}"]
|
141
|
+
end
|
142
|
+
|
143
|
+
def cmd_usubmit number, message, label_response = new_label
|
144
|
+
$writer[label_response + " USUBMIT #{number} #{message}"]
|
145
|
+
end
|
146
|
+
|
147
|
+
def cmd_fsubmit number, message, label_response = new_label
|
148
|
+
$writer[label_response + " FSUBMIT #{number} #{message}"]
|
149
|
+
end
|
150
|
+
|
151
|
+
def cmd_fbsubmit number, message, label_response = new_label
|
152
|
+
$writer[label_response + " FBSUBMIT #{number} #{message}"]
|
153
|
+
end
|
154
|
+
|
155
|
+
def cmd_fusubmit number, message, label_response = new_label
|
156
|
+
$writer[label_response + " FUSUBMIT #{number} #{message}"]
|
157
|
+
end
|
158
|
+
|
159
|
+
def cmd_waplink number, message, label_response = new_label
|
160
|
+
$writer[label_response + " WAPLINK #{number} #{message}"]
|
161
|
+
end
|
162
|
+
|
163
|
+
def cmd_dst numbers, label_response = new_label
|
164
|
+
$writer[label_response + " DST #{numbers}"]
|
165
|
+
end
|
166
|
+
|
167
|
+
def cmd_msg message, label_response = new_label
|
168
|
+
$writer[label_response + " MSG #{message}"]
|
169
|
+
end
|
170
|
+
|
171
|
+
# *data* file contenten base64 encoded
|
172
|
+
# Available types:
|
173
|
+
# * :jpeg image JPEG
|
174
|
+
# * :gif image GIF
|
175
|
+
# * :midi polyfonic melody MIDI
|
176
|
+
# * :sp_midi polyfonic melody SP-MIDI
|
177
|
+
# * :amr sound AMR
|
178
|
+
# * :mp3 sound MP3
|
179
|
+
# * :gpp video 3GP
|
180
|
+
# * :java application JAVA
|
181
|
+
# * :symbian application Symbian
|
182
|
+
def cmd_filemsg type, data, label_response = new_label
|
183
|
+
mime = mimetype type
|
184
|
+
$writer[label_response + " FILEMSG #{mime} #{data}"] if mime
|
185
|
+
end
|
186
|
+
|
187
|
+
# *data* file contenten base64 encoded
|
188
|
+
# *title* Information title before downloading content
|
189
|
+
# *message* Information text before downloading content
|
190
|
+
# Available types:
|
191
|
+
# * :jpeg image JPEG
|
192
|
+
# * :gif image GIF
|
193
|
+
# * :midi polyfonic melody MIDI
|
194
|
+
# * :sp_midi polyfonic melody SP-MIDI
|
195
|
+
# * :amr sound AMR
|
196
|
+
# * :mp3 sound MP3
|
197
|
+
# * :gpp video 3GP
|
198
|
+
# * :java application JAVA
|
199
|
+
# * :symbian application Symbian
|
200
|
+
def cmd_mmsmsg type, data, title, message, label_response = new_label
|
201
|
+
mime = mimetype type
|
202
|
+
$writer[label_response + " MMSMSG #{mime} #{data} #{title}|#{message}"] if mime
|
203
|
+
end
|
204
|
+
|
205
|
+
def cmd_envia label_response = new_label
|
206
|
+
$writer[label_response + " ENVIA"]
|
207
|
+
end
|
131
208
|
# CMD Envios MT end
|
132
209
|
|
133
210
|
# CMD Recepcion SMS (no premium)
|
134
|
-
def cmd_allowanswer
|
211
|
+
def cmd_allowanswer allow = true, label_response = new_label
|
135
212
|
$writer[label_response + " ALLOWANSWER " + (allow ? 'ON' : 'OFF')]
|
136
213
|
end
|
137
214
|
|
138
|
-
def cmd_incomingmoack
|
215
|
+
def cmd_incomingmoack m_id, label_response = new_label
|
139
216
|
$writer[label_response + " INCOMINGMOACK #{m_id}"]
|
140
217
|
end
|
218
|
+
|
219
|
+
# *opts*
|
220
|
+
# - cert: true/false (default false) use certificated confirmations
|
221
|
+
# * false (default)
|
222
|
+
# * :d Default Service
|
223
|
+
# - lang
|
224
|
+
# * :es Spanish (default)
|
225
|
+
# * :ca Catalan
|
226
|
+
# * :en English
|
227
|
+
# * :fr French
|
228
|
+
# * :de German
|
229
|
+
# * :it Italian
|
230
|
+
# * :nl Dutch
|
231
|
+
# * :pt Portuguese
|
232
|
+
# * :pl Polish
|
233
|
+
# * :se Swedish
|
234
|
+
# - mode
|
235
|
+
# * email to send notification
|
236
|
+
# * INTERNAL to use ACUSE
|
237
|
+
def cmd_acuseon lang=false, cert=false, mode = 'INTERNAL', label_response = new_label
|
238
|
+
l = lang ? "lang=#{lang.to_s.upcase} " : ''
|
239
|
+
c = cert ? "cert_type=#{cert.to_s.upcase} " : ''
|
240
|
+
$writer[label_response + " ACUSEON #{l}#{c}#{mode}"]
|
241
|
+
end
|
242
|
+
|
243
|
+
def cmd_acuseoff label_response = new_label
|
244
|
+
$writer[label_response + " ACUSEOFF"]
|
245
|
+
end
|
246
|
+
|
247
|
+
def cmd_acuseack id, label_response = new_label
|
248
|
+
$writer[label_response + " ACUSEACK #{id}"]
|
249
|
+
end
|
250
|
+
|
251
|
+
# - action
|
252
|
+
# * :begin
|
253
|
+
# * :end
|
254
|
+
# * :abort
|
255
|
+
def cmd_trans action, label_response = new_label
|
256
|
+
type = case action
|
257
|
+
when :begin
|
258
|
+
'INICIAR'
|
259
|
+
when :end
|
260
|
+
'FIN'
|
261
|
+
when :abort
|
262
|
+
'ABORTAR'
|
263
|
+
else
|
264
|
+
return false
|
265
|
+
end
|
266
|
+
$writer[label_response + " TRANS #{type}"]
|
267
|
+
end
|
141
268
|
# CMD Recepcion SMS (no premium) end
|
142
269
|
|
143
270
|
# CMD Recepcion SMS (premium)
|
144
271
|
# CMD Recepcion SMS (premium) end
|
145
272
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
close!
|
273
|
+
def parser
|
274
|
+
until $input_buffer.empty?
|
275
|
+
line = $input_buffer.shift
|
276
|
+
puts ">#{line}\r\n"
|
277
|
+
@args = line.split ' '
|
278
|
+
@label = @args.shift
|
279
|
+
@cmd = @args.shift
|
280
|
+
case @cmd
|
281
|
+
# CMD Generales
|
282
|
+
when 'OK'
|
283
|
+
when 'NOOK'
|
284
|
+
when 'RSALDO'
|
285
|
+
when 'PING'
|
286
|
+
cmd_pong @args[0], @label
|
287
|
+
when 'PONG'
|
288
|
+
cmd_ping @args[0], @label
|
289
|
+
when 'RINFONUM'
|
290
|
+
when 'RTARIFA'
|
291
|
+
when 'BYE'
|
292
|
+
close!
|
167
293
|
# CMD Envios MT
|
168
|
-
|
294
|
+
when 'SUBMITOK'
|
295
|
+
when 'BSUBMITOK'
|
296
|
+
when 'USUBMITOK'
|
297
|
+
when 'FSUBMITOK'
|
298
|
+
when 'FBSUBMITOK'
|
299
|
+
when 'FUSUBMITOK'
|
300
|
+
when 'WAPLINKOK'
|
301
|
+
when 'REJDST'
|
302
|
+
when 'ACUSE'
|
303
|
+
when 'ACUSEACKR'
|
304
|
+
when 'RTRANS'
|
169
305
|
# CMD Recepcion SMS (no premium)
|
170
306
|
when 'INCOMINGMO'
|
171
307
|
|
172
308
|
# CMD Recepcion SMS (premium)
|
173
309
|
|
174
|
-
|
310
|
+
else
|
175
311
|
# unknow
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
312
|
+
end
|
313
|
+
do_event @cmd.downcase
|
314
|
+
do_event :all
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
private
|
319
|
+
def mimetype type
|
320
|
+
case type
|
321
|
+
when :jpeg
|
322
|
+
'image/jpg'
|
323
|
+
when :gif
|
324
|
+
'image/gif'
|
325
|
+
when :midi
|
326
|
+
'audio/midi'
|
327
|
+
when :sp_midi
|
328
|
+
'audio/sp-midi'
|
329
|
+
when :amr
|
330
|
+
'audio/amr'
|
331
|
+
when :mp3
|
332
|
+
'audio/mpeg'
|
333
|
+
when :gpp
|
334
|
+
'video/3gpp'
|
335
|
+
when :java
|
336
|
+
'application/java-archive'
|
337
|
+
when :symbian
|
338
|
+
'application/vnd.symbian.instal'
|
339
|
+
else
|
340
|
+
false
|
341
|
+
end
|
342
|
+
end
|
181
343
|
end
|
182
344
|
end
|
data/lib/lleidasms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lleidasms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &17522540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 2.7.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17522540
|
25
25
|
description: Receive and send standar and premium SMS/MMS using Lleida.net services.
|
26
26
|
email:
|
27
27
|
- mabarroso@mabarroso.com
|