lleidasms 1.1.0 → 1.1.6
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 +51 -0
- data/lib/lleidasms/client.rb +32 -9
- data/lib/lleidasms/gateway.rb +39 -25
- data/lib/lleidasms/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -48,6 +48,8 @@ gem 'lleidasms'
|
|
48
48
|
|
49
49
|
# Examples
|
50
50
|
## Demo
|
51
|
+
From the command line
|
52
|
+
|
51
53
|
```shell
|
52
54
|
lleidasms YOUR_USER YOUR_PASSWORD
|
53
55
|
```
|
@@ -96,5 +98,54 @@ or
|
|
96
98
|
end
|
97
99
|
```
|
98
100
|
|
101
|
+
### Special method raw command
|
102
|
+
Allow you to send to server any command not implemented.
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
cmd_raw 'PING', time
|
106
|
+
```
|
107
|
+
|
108
|
+
### Special event :unknow
|
109
|
+
To detect unknow commands.
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
event :unknow, :new_unknow
|
113
|
+
|
114
|
+
def new_unknow label, cmd, args
|
115
|
+
end
|
116
|
+
```
|
117
|
+
|
118
|
+
### Enabling debug
|
119
|
+
Use debug to capture debug events at :in, :out or :all messages
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class SMS < Lleidasms::Gateway
|
123
|
+
debug :all, :debugger
|
124
|
+
debug :in, :debugger_in
|
125
|
+
debug :out, :debugger_out
|
126
|
+
|
127
|
+
def debugger line
|
128
|
+
puts line
|
129
|
+
end
|
130
|
+
|
131
|
+
def debugger_in line
|
132
|
+
puts line
|
133
|
+
end
|
134
|
+
|
135
|
+
def debugger_out line
|
136
|
+
puts line
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
sms = SMS.new
|
141
|
+
sms.connect
|
142
|
+
sms.listener
|
143
|
+
sms.cmd_login <YOUR_USER>, <YOUR_PASSWORD>
|
144
|
+
|
145
|
+
while sms.conected?
|
146
|
+
# Some tasks
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
99
150
|
# License
|
100
151
|
Released under the MIT license: [http://www.opensource.org/licenses/MIT](http://www.opensource.org/licenses/MIT)
|
data/lib/lleidasms/client.rb
CHANGED
@@ -6,8 +6,10 @@ module Lleidasms
|
|
6
6
|
event :all, :new_event
|
7
7
|
event :acuse, :new_acuse
|
8
8
|
event :incomingmo, :new_incomingmo
|
9
|
+
event :unknow, :new_unknow
|
10
|
+
debug :all, :debugger
|
9
11
|
|
10
|
-
attr_accessor :timeout
|
12
|
+
attr_accessor :timeout, :debug
|
11
13
|
|
12
14
|
def connect user, password, timeout = 2.4
|
13
15
|
super()
|
@@ -16,6 +18,12 @@ module Lleidasms
|
|
16
18
|
self.timeout= timeout
|
17
19
|
@acuse = []
|
18
20
|
@incomingmo = []
|
21
|
+
@unknow = []
|
22
|
+
@debug = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def debugger line
|
26
|
+
puts line
|
19
27
|
end
|
20
28
|
|
21
29
|
def saldo
|
@@ -24,7 +32,7 @@ module Lleidasms
|
|
24
32
|
return @response_args[0]
|
25
33
|
end
|
26
34
|
|
27
|
-
#
|
35
|
+
# number
|
28
36
|
# The telephone number
|
29
37
|
def tarifa number
|
30
38
|
cmd_tarifa number
|
@@ -32,11 +40,11 @@ module Lleidasms
|
|
32
40
|
return @response_args
|
33
41
|
end
|
34
42
|
|
35
|
-
#
|
43
|
+
# number
|
36
44
|
# The telephone number
|
37
|
-
#
|
45
|
+
# message
|
38
46
|
# The string to send
|
39
|
-
#
|
47
|
+
# opts
|
40
48
|
# - nowait: (default false) no wait for response
|
41
49
|
# - sender: The sender telephone number
|
42
50
|
# - date: Date and time to send message in format YYYYMMDDhhmm[+-]ZZzz
|
@@ -83,11 +91,11 @@ module Lleidasms
|
|
83
91
|
end
|
84
92
|
end
|
85
93
|
|
86
|
-
#
|
94
|
+
# number
|
87
95
|
# The telephone number
|
88
|
-
#
|
96
|
+
# url
|
89
97
|
# The URL to content. Usually a image, tone or application
|
90
|
-
#
|
98
|
+
# message
|
91
99
|
# Information text before downloading content
|
92
100
|
def send_waplink number, url, message
|
93
101
|
cmd_waplink number, url, message
|
@@ -136,7 +144,7 @@ module Lleidasms
|
|
136
144
|
end
|
137
145
|
|
138
146
|
# Set file content (base64 encded) as message for the massive send list
|
139
|
-
#
|
147
|
+
# data file contenten base64 encoded
|
140
148
|
# Available types:
|
141
149
|
# * :jpeg image JPEG
|
142
150
|
# * :gif image GIF
|
@@ -224,6 +232,10 @@ module Lleidasms
|
|
224
232
|
@incomingmo.count > 0
|
225
233
|
end
|
226
234
|
|
235
|
+
def unknow?
|
236
|
+
@unknow.count > 0
|
237
|
+
end
|
238
|
+
|
227
239
|
# Return hash or false
|
228
240
|
# - :id
|
229
241
|
# - :destino
|
@@ -248,6 +260,12 @@ module Lleidasms
|
|
248
260
|
}
|
249
261
|
end
|
250
262
|
|
263
|
+
# Return array or false
|
264
|
+
def unknow
|
265
|
+
return false unless unknow?
|
266
|
+
@unknow.shift
|
267
|
+
end
|
268
|
+
|
251
269
|
# - wait: (default false) no wait for response
|
252
270
|
# - action
|
253
271
|
# * :begin
|
@@ -343,5 +361,10 @@ module Lleidasms
|
|
343
361
|
cmd_incomingmoack args[0]
|
344
362
|
end
|
345
363
|
|
364
|
+
def new_unknow label, cmd, args
|
365
|
+
args.unshift cmd
|
366
|
+
@unknow << args
|
367
|
+
end
|
368
|
+
|
346
369
|
end
|
347
370
|
end
|
data/lib/lleidasms/gateway.rb
CHANGED
@@ -4,6 +4,8 @@ require "io/wait"
|
|
4
4
|
|
5
5
|
module Lleidasms
|
6
6
|
class Gateway
|
7
|
+
$callbacks = {}
|
8
|
+
|
7
9
|
# Client
|
8
10
|
def initialize host = 'sms.lleida.net', port = 2048
|
9
11
|
@host = host
|
@@ -21,7 +23,7 @@ module Lleidasms
|
|
21
23
|
end
|
22
24
|
$writer = lambda do |buffer|
|
23
25
|
$server.puts "#{buffer}\r\n"
|
24
|
-
|
26
|
+
do_debug :out, "<#{buffer}"
|
25
27
|
buffer.replace ''
|
26
28
|
end
|
27
29
|
end
|
@@ -60,33 +62,20 @@ module Lleidasms
|
|
60
62
|
end
|
61
63
|
# Client end
|
62
64
|
|
63
|
-
|
64
|
-
$callbacks = {}
|
65
|
-
|
66
|
-
def self.event name, method_name
|
65
|
+
def self.event name, method_name
|
67
66
|
$callbacks[name] = [] unless $callbacks[name]
|
68
67
|
$callbacks[name] << method_name
|
69
68
|
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
def
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def run_event_for name, scope, *args
|
80
|
-
return unless $callbacks[name.to_sym]
|
81
|
-
$callbacks[name.to_sym].each do |callback|
|
82
|
-
if callback.kind_of? Symbol
|
83
|
-
scope.send callback, *args
|
84
|
-
else
|
85
|
-
scope.instance_exec *args, &callback
|
86
|
-
end
|
87
|
-
end
|
70
|
+
# Available types:
|
71
|
+
# * :in
|
72
|
+
# * :out
|
73
|
+
# * :all
|
74
|
+
def self.debug type, method_name
|
75
|
+
name = "debug_#{type.to_s}".to_sym
|
76
|
+
$callbacks[name] = [] unless $callbacks[name]
|
77
|
+
$callbacks[name] << method_name
|
88
78
|
end
|
89
|
-
# Callbacks end
|
90
79
|
|
91
80
|
def new_label
|
92
81
|
@my_label += 1
|
@@ -273,7 +262,7 @@ module Lleidasms
|
|
273
262
|
def parser
|
274
263
|
until $input_buffer.empty?
|
275
264
|
line = $input_buffer.shift
|
276
|
-
|
265
|
+
do_debug :in, ">#{line}"
|
277
266
|
@args = line.split ' '
|
278
267
|
@label = @args.shift
|
279
268
|
@cmd = @args.shift
|
@@ -308,7 +297,7 @@ module Lleidasms
|
|
308
297
|
# CMD Recepcion SMS (premium)
|
309
298
|
|
310
299
|
else
|
311
|
-
|
300
|
+
do_event :unknow
|
312
301
|
end
|
313
302
|
do_event @cmd.downcase
|
314
303
|
do_event :all
|
@@ -316,6 +305,31 @@ module Lleidasms
|
|
316
305
|
end
|
317
306
|
|
318
307
|
private
|
308
|
+
def do_debug type, line
|
309
|
+
name = "debug_#{type.to_s}".to_sym
|
310
|
+
run_event_for name, self, line
|
311
|
+
run_event_for 'debug_all', self, line
|
312
|
+
end
|
313
|
+
|
314
|
+
def do_event name
|
315
|
+
run_event name.to_sym, @label, @cmd, @args
|
316
|
+
end
|
317
|
+
|
318
|
+
def run_event name, *args
|
319
|
+
run_event_for name.to_sym, self, *args
|
320
|
+
end
|
321
|
+
|
322
|
+
def run_event_for name, scope, *args
|
323
|
+
return unless $callbacks[name.to_sym]
|
324
|
+
$callbacks[name.to_sym].each do |callback|
|
325
|
+
if callback.kind_of? Symbol
|
326
|
+
scope.send callback, *args
|
327
|
+
else
|
328
|
+
scope.instance_exec *args, &callback
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
319
333
|
def mimetype type
|
320
334
|
case type
|
321
335
|
when :jpeg
|
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.1.
|
4
|
+
version: 1.1.6
|
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-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &17953140 !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: *17953140
|
25
25
|
description: Receive and send standar and premium SMS/MMS using Lleida.net services.
|
26
26
|
email:
|
27
27
|
- mabarroso@mabarroso.com
|