lleidasms 1.0.2 → 1.1.0

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/README.md CHANGED
@@ -1,83 +1,100 @@
1
- # Lleidasms
2
- A [Lleida.net](http://lleida.net/) SMS gateway for Ruby.
3
-
4
- # Description
5
- Receive and send standar and premium SMS/MMS using [Lleida.net](http://lleida.net/) services.
6
-
7
- #Features
8
- - client class
9
- - gateway superclass for new client implementations
10
-
11
- #Installation
12
- ##From the command line.
13
-
14
- ```shell
15
- gem install lleidasms
16
- ```
17
-
18
- ##Using Gemfile.
19
-
20
- 1 Add to your application Gemfile
21
-
22
- ```ruby
23
- gem 'lleidasms'
24
- ```
25
-
26
- 2 Type
27
-
28
- ```shell
29
- bundle install
30
- ```
31
-
32
- # Examples
33
- ## Demo
34
- ```shell
35
- lleidasms YOUR_USER YOUR_PASSWORD
36
- ```
37
-
38
- or
39
-
40
- ```shell
41
- lleidasms_client YOUR_USER YOUR_PASSWORD
42
- ```
43
-
44
- ## Using default client class
45
- ```ruby
46
- sms = Lleidasms::Client.new
47
- sms.connect <YOUR_USER>, <YOUR_PASSWORD>
48
- puts sms.saldo
49
- sms.close
50
- ```
51
-
52
- ## Creating a new client
53
- ```ruby
54
- class SMS < Lleidasms::Gateway
55
- event :INCOMINGMO, :new_sms
56
-
57
- def new_sms label, cmd, args
58
- id = args.shift
59
- time = args.shift
60
- from = args.shift
61
- to = args.shift
62
- sms = args.join(' ')
63
- puts " id #{id}"
64
- puts " time #{time}"
65
- puts " from #{from}"
66
- puts " to #{to}"
67
- puts " sms #{sms}"
68
- cmd_incomingmoack id, label
69
- end
70
- end
71
-
72
- sms = SMS.new
73
- sms.connect
74
- sms.listener
75
- sms.cmd_login <YOUR_USER>, <YOUR_PASSWORD>
76
-
77
- while sms.conected?
78
- # Some tasks
79
- end
80
- ```
81
-
82
- # License
83
- Released under the MIT license: [http://www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT)
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
@@ -7,3 +7,8 @@ desc "Run all tests"
7
7
  task :test do
8
8
  exec "rspec --color"
9
9
  end
10
+
11
+ desc "Generate docs"
12
+ task :rdoc do
13
+ exec "rdoc --all"
14
+ end
@@ -3,56 +3,344 @@ require "gateway"
3
3
 
4
4
  module Lleidasms
5
5
  class Client < Lleidasms::Gateway
6
- event :ALL, :new_event
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(user, password, timeout = 2.4)
11
- super()
12
- listener
13
- cmd_login(user, password)
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
- def saldo()
18
- cmd_saldo
19
- return false unless wait_for(last_label)
20
- return @response_args[0]
21
- end
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
- def tarifa(numero)
24
- cmd_tarifa numero
25
- return false unless wait_for(last_label)
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
- def send_sms(wait = true)
30
- saldo
31
- wait_for(last_label) if wait
32
- end
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 new_event(label, cmd, args)
36
- @event_label = label
37
- @event_cmd = cmd
38
- @event_args = args
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
- @response_label = label
42
- @response_cmd = cmd
43
- @response_args = args
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(label)
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
- while @wait do
329
+ while @wait do
52
330
  sleep 0.2
53
331
  return false if @timeout < (Time.new - t)
54
- end
55
- return true
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
@@ -5,7 +5,7 @@ require "io/wait"
5
5
  module Lleidasms
6
6
  class Gateway
7
7
  # Client
8
- def initialize(host = 'sms.lleida.net', port = 2048)
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
- $input_buffer << line.strip
20
- parser
19
+ $input_buffer << line.strip
20
+ parser
21
21
  end
22
22
  $writer = lambda do |buffer|
23
- $server.puts "#{buffer}\r\n"
24
- puts "<#{buffer}\r\n"
25
- buffer.replace("")
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
- $server = TCPSocket.new(@host, @port)
32
- $conected = true
31
+ $server = TCPSocket.new @host, @port
32
+ $conected = true
33
33
  rescue
34
34
  $conected = false
35
- puts "Unable to open a connection."
36
- exit
35
+ puts "Unable to open a connection."
36
+ exit
37
37
  end
38
38
  end
39
39
 
40
40
  def listener
41
- Thread.new($server) do |socket|
42
- while line = socket.gets
43
- $reader[line]
44
- end
45
- close!
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
- def self.event(name, method_name)
67
- $callbacks[name] = [] unless $callbacks[name]
66
+ def self.event name, method_name
67
+ $callbacks[name] = [] unless $callbacks[name]
68
68
  $callbacks[name] << method_name
69
- end
69
+ end
70
70
 
71
- def do_event(name)
72
- run_event name.to_sym, @label, @cmd, @args
73
- end
71
+ def do_event name
72
+ run_event name.to_sym, @label, @cmd, @args
73
+ end
74
74
 
75
- def run_event(name, *args)
76
- run_event_for(name.to_sym, self, *args)
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(name, scope, *args)
80
- return unless $callbacks[name.to_sym]
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(callback, *args)
83
+ scope.send callback, *args
84
84
  else
85
- scope.instance_exec(*args, &callback)
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(user, password, label_response = new_label)
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(time = Time.now.to_i.to_s, label_response = new_label)
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(time = Time.now.to_i.to_s, label_response = new_label)
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(label_response = new_label)
117
+ def cmd_saldo label_response = new_label
114
118
  $writer[label_response + " SALDO"]
115
119
  end
116
120
 
117
- def cmd_infonum(numero, label_response = new_label)
118
- $writer[label_response + " INFONUM #{numero}"]
121
+ def cmd_infonum number, label_response = new_label
122
+ $writer[label_response + " INFONUM #{number}"]
119
123
  end
120
124
 
121
- def cmd_tarifa(numero, label_response = new_label)
122
- $writer[label_response + " TARIFA #{numero}"]
125
+ def cmd_tarifa number, label_response = new_label
126
+ $writer[label_response + " TARIFA #{number}"]
123
127
  end
124
128
 
125
- def cmd_quit(label_response = new_label)
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(allow = true, label_response = new_label)
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(m_id, label_response = new_label)
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
- def parser
147
- until $input_buffer.empty?
148
- line = $input_buffer.shift
149
- puts ">#{line}\r\n"
150
- @args = line.split(' ')
151
- @label = @args.shift
152
- @cmd = @args.shift
153
-
154
- case @cmd
155
- # CMD Generales
156
- when 'OK'
157
- when 'NOOK'
158
- when 'RSALDO'
159
- when 'PING'
160
- cmd_pong @args[0], @label
161
- when 'PONG'
162
- cmd_ping @args[0], @label
163
- when 'RINFONUM'
164
- when 'RTARIFA'
165
- when 'BYE'
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
- else
310
+ else
175
311
  # unknow
176
- end
177
- do_event(@cmd)
178
- do_event(:all)
179
- end
180
- end
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
@@ -1,3 +1,3 @@
1
1
  module Lleidasms
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
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.2
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-21 00:00:00.000000000Z
12
+ date: 2012-02-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &15864760 !ruby/object:Gem::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: *15864760
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