lleidasms 1.0.0 → 1.0.2

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 ADDED
@@ -0,0 +1,83 @@
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)
data/bin/lleidasms ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path('../..', __FILE__)
4
+ require File.join(root, %w[lib lleidasms])
5
+
6
+ require "gateway"
7
+
8
+ class SMS < Lleidasms::Gateway
9
+ event :INCOMINGMO, :new_sms
10
+
11
+ def new_sms label, cmd, args
12
+ id = args.shift
13
+ time = args.shift
14
+ from = args.shift
15
+ to = args.shift
16
+ sms = args.join(' ')
17
+ puts " id #{id}"
18
+ puts " time #{time}"
19
+ puts " from #{from}"
20
+ puts " to #{to}"
21
+ puts " sms #{sms}"
22
+ # cmd_incomingmoack id, label
23
+ end
24
+ end
25
+
26
+
27
+ sms = SMS.new
28
+ sms.connect
29
+ sms.listener
30
+ sms.cmd_login ARGV[0], ARGV[1]
31
+
32
+ while sms.conected?
33
+ sleep 0.2
34
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path('../..', __FILE__)
4
+ require File.join(root, %w[lib lleidasms])
5
+
6
+ require "client"
7
+
8
+
9
+
10
+ sms = Lleidasms::Client.new
11
+ sms.connect ARGV[0], ARGV[1]
12
+ puts sms.saldo
13
+ sms.close
@@ -1,182 +1,182 @@
1
- require "thread"
2
- require "socket"
3
- require "io/wait"
4
-
5
- module Lleidasms
6
- class Gateway
7
- # Client
8
- def initialize(host = 'sms.lleida.net', port = 2048)
9
- @host = host
10
- @port = port
11
- @my_label = 0
12
-
13
- # prepare global (scriptable) data
14
- $conected = false
15
- $input_buffer = Queue.new
16
- $output_buffer = String.new
17
-
18
- $reader = lambda do |line|
19
- $input_buffer << line.strip
20
- parser
21
- end
22
- $writer = lambda do |buffer|
23
- $server.puts "#{buffer}\r\n"
24
- puts "<#{buffer}\r\n"
25
- buffer.replace("")
26
- end
27
- end
28
-
29
- def connect
30
- begin
31
- $server = TCPSocket.new(@host, @port)
32
- $conected = true
33
- rescue
34
- $conected = false
35
- puts "Unable to open a connection."
36
- exit
37
- end
38
- end
39
-
40
- def listener
41
- Thread.new($server) do |socket|
42
- while line = socket.gets
43
- $reader[line]
44
- end
45
- close!
46
- end
47
- end
48
-
49
- def conected?
50
- $conected
51
- end
52
-
53
- def close
54
- cmd_quit
55
- end
56
-
57
- def close!
58
- $server.close
59
- $conected = false
60
- end
61
- # Client end
62
-
63
- # Callbacks
64
- $callbacks = {}
65
-
66
- def self.event(name, method_name)
67
- $callbacks[name] = [] unless $callbacks[name]
68
- $callbacks[name] << method_name
69
- end
70
-
71
- def do_event(name)
72
- run_event name.to_sym, @label, @cmd, @args
73
- end
74
-
75
- def run_event(name, *args)
76
- run_event_for(name.to_sym, self, *args)
77
- end
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
88
- end
89
- # Callbacks end
90
-
91
- def new_label
92
- @my_label += 1
93
- @my_label.to_s
94
- end
95
-
96
- def last_label
97
- @my_label
98
- end
99
-
100
- # CMD Generales
101
- def cmd_login(user, password, label_response = new_label)
102
- $writer[label_response + " LOGIN #{user} #{password}"]
103
- end
104
-
105
- def cmd_ping(time = Time.now.to_i.to_s, label_response = new_label)
106
- $writer[label_response + " PING "+ time]
107
- end
108
-
109
- def cmd_pong(time = Time.now.to_i.to_s, label_response = new_label)
110
- $writer[label_response + " PONG "+ time]
111
- end
112
-
113
- def cmd_saldo(label_response = new_label)
114
- $writer[label_response + " SALDO"]
115
- end
116
-
117
- def cmd_infonum(numero, label_response = new_label)
118
- $writer[label_response + " INFONUM #{numero}"]
119
- end
120
-
121
- def cmd_tarifa(numero, label_response = new_label)
122
- $writer[label_response + " TARIFA #{numero}"]
123
- end
124
-
125
- def cmd_quit(label_response = new_label)
126
- $writer[label_response + " QUIT"]
127
- end
128
- # CMD Generales end
129
-
130
- # CMD Envios MT
131
- # CMD Envios MT end
132
-
133
- # CMD Recepcion SMS (no premium)
134
- def cmd_allowanswer(allow = true, label_response = new_label)
135
- $writer[label_response + " ALLOWANSWER " + (allow ? 'ON' : 'OFF')]
136
- end
137
-
138
- def cmd_incomingmoack(m_id, label_response = new_label)
139
- $writer[label_response + " INCOMINGMOACK #{m_id}"]
140
- end
141
- # CMD Recepcion SMS (no premium) end
142
-
143
- # CMD Recepcion SMS (premium)
144
- # CMD Recepcion SMS (premium) end
145
-
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!
167
- # CMD Envios MT
168
-
169
- # CMD Recepcion SMS (no premium)
170
- when 'INCOMINGMO'
171
-
172
- # CMD Recepcion SMS (premium)
173
-
174
- else
175
- # unknow
176
- end
177
- do_event(@cmd)
178
- do_event(:ALL)
179
- end
180
- end
181
- end
182
- end
1
+ require "thread"
2
+ require "socket"
3
+ require "io/wait"
4
+
5
+ module Lleidasms
6
+ class Gateway
7
+ # Client
8
+ def initialize(host = 'sms.lleida.net', port = 2048)
9
+ @host = host
10
+ @port = port
11
+ @my_label = 0
12
+
13
+ # prepare global (scriptable) data
14
+ $conected = false
15
+ $input_buffer = Queue.new
16
+ $output_buffer = String.new
17
+
18
+ $reader = lambda do |line|
19
+ $input_buffer << line.strip
20
+ parser
21
+ end
22
+ $writer = lambda do |buffer|
23
+ $server.puts "#{buffer}\r\n"
24
+ puts "<#{buffer}\r\n"
25
+ buffer.replace("")
26
+ end
27
+ end
28
+
29
+ def connect
30
+ begin
31
+ $server = TCPSocket.new(@host, @port)
32
+ $conected = true
33
+ rescue
34
+ $conected = false
35
+ puts "Unable to open a connection."
36
+ exit
37
+ end
38
+ end
39
+
40
+ def listener
41
+ Thread.new($server) do |socket|
42
+ while line = socket.gets
43
+ $reader[line]
44
+ end
45
+ close!
46
+ end
47
+ end
48
+
49
+ def conected?
50
+ $conected
51
+ end
52
+
53
+ def close
54
+ cmd_quit
55
+ end
56
+
57
+ def close!
58
+ $server.close
59
+ $conected = false
60
+ end
61
+ # Client end
62
+
63
+ # Callbacks
64
+ $callbacks = {}
65
+
66
+ def self.event(name, method_name)
67
+ $callbacks[name] = [] unless $callbacks[name]
68
+ $callbacks[name] << method_name
69
+ end
70
+
71
+ def do_event(name)
72
+ run_event name.to_sym, @label, @cmd, @args
73
+ end
74
+
75
+ def run_event(name, *args)
76
+ run_event_for(name.to_sym, self, *args)
77
+ end
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
88
+ end
89
+ # Callbacks end
90
+
91
+ def new_label
92
+ @my_label += 1
93
+ @my_label.to_s
94
+ end
95
+
96
+ def last_label
97
+ @my_label
98
+ end
99
+
100
+ # CMD Generales
101
+ def cmd_login(user, password, label_response = new_label)
102
+ $writer[label_response + " LOGIN #{user} #{password}"]
103
+ end
104
+
105
+ def cmd_ping(time = Time.now.to_i.to_s, label_response = new_label)
106
+ $writer[label_response + " PING "+ time]
107
+ end
108
+
109
+ def cmd_pong(time = Time.now.to_i.to_s, label_response = new_label)
110
+ $writer[label_response + " PONG "+ time]
111
+ end
112
+
113
+ def cmd_saldo(label_response = new_label)
114
+ $writer[label_response + " SALDO"]
115
+ end
116
+
117
+ def cmd_infonum(numero, label_response = new_label)
118
+ $writer[label_response + " INFONUM #{numero}"]
119
+ end
120
+
121
+ def cmd_tarifa(numero, label_response = new_label)
122
+ $writer[label_response + " TARIFA #{numero}"]
123
+ end
124
+
125
+ def cmd_quit(label_response = new_label)
126
+ $writer[label_response + " QUIT"]
127
+ end
128
+ # CMD Generales end
129
+
130
+ # CMD Envios MT
131
+ # CMD Envios MT end
132
+
133
+ # CMD Recepcion SMS (no premium)
134
+ def cmd_allowanswer(allow = true, label_response = new_label)
135
+ $writer[label_response + " ALLOWANSWER " + (allow ? 'ON' : 'OFF')]
136
+ end
137
+
138
+ def cmd_incomingmoack(m_id, label_response = new_label)
139
+ $writer[label_response + " INCOMINGMOACK #{m_id}"]
140
+ end
141
+ # CMD Recepcion SMS (no premium) end
142
+
143
+ # CMD Recepcion SMS (premium)
144
+ # CMD Recepcion SMS (premium) end
145
+
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!
167
+ # CMD Envios MT
168
+
169
+ # CMD Recepcion SMS (no premium)
170
+ when 'INCOMINGMO'
171
+
172
+ # CMD Recepcion SMS (premium)
173
+
174
+ else
175
+ # unknow
176
+ end
177
+ do_event(@cmd)
178
+ do_event(:all)
179
+ end
180
+ end
181
+ end
182
+ end
@@ -1,3 +1,3 @@
1
1
  module Lleidasms
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
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.0
4
+ version: 1.0.2
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-05 00:00:00.000000000Z
12
+ date: 2012-02-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &19028940 !ruby/object:Gem::Requirement
16
+ requirement: &15864760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,11 +21,13 @@ dependencies:
21
21
  version: 2.7.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *19028940
24
+ version_requirements: *15864760
25
25
  description: Receive and send standar and premium SMS/MMS using Lleida.net services.
26
26
  email:
27
27
  - mabarroso@mabarroso.com
28
- executables: []
28
+ executables:
29
+ - lleidasms
30
+ - lleidasms_client
29
31
  extensions: []
30
32
  extra_rdoc_files: []
31
33
  files:
@@ -35,9 +37,11 @@ files:
35
37
  - lib/lleidasms/gateway.rb
36
38
  - MIT-LICENSE
37
39
  - Rakefile
38
- - README.rdoc
40
+ - README.md
39
41
  - test/lleidasms_test.rb
40
42
  - test/test_helper.rb
43
+ - bin/lleidasms
44
+ - bin/lleidasms_client
41
45
  homepage: https://github.com/mabarroso/lleidasms
42
46
  licenses: []
43
47
  post_install_message:
data/README.rdoc DELETED
@@ -1,63 +0,0 @@
1
- = Lleidasms
2
-
3
- This project rocks and uses MIT-LICENSE.
4
-
5
- `Lleida.net` SMS gateway for Ruby
6
-
7
- Features
8
- --------
9
-
10
- Enhancements
11
- - client class
12
- - gateway superclass for new client implementations
13
-
14
- Examples
15
- --------
16
-
17
- sms = Lleidasms::Client.new
18
- sms.connect(<YOUR USER>, <YOUR PASSWORD>)
19
- puts sms.saldo
20
- sms.close
21
-
22
-
23
- Requirements
24
- ------------
25
-
26
- none
27
-
28
- Install
29
- -------
30
-
31
- gem install lleidasms
32
-
33
- Author
34
- ------
35
-
36
- Original author: Miguel Adolfo Barroso
37
-
38
-
39
- License
40
- -------
41
-
42
- (The MIT License)
43
-
44
- Copyright (c) 2012 Miguel Adolfo Barroso
45
-
46
- Permission is hereby granted, free of charge, to any person obtaining
47
- a copy of this software and associated documentation files (the
48
- 'Software'), to deal in the Software without restriction, including
49
- without limitation the rights to use, copy, modify, merge, publish,
50
- distribute, sublicense, and/or sell copies of the Software, and to
51
- permit persons to whom the Software is furnished to do so, subject to
52
- the following conditions:
53
-
54
- The above copyright notice and this permission notice shall be
55
- included in all copies or substantial portions of the Software.
56
-
57
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.