smsRuby 1.0.0-x86-linux
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.rdoc +20 -0
- data/ext/Makefile +157 -0
- data/ext/RecieveSMS.o +0 -0
- data/ext/SendSMS.o +0 -0
- data/ext/extconf.rb +6 -0
- data/ext/sms.i +8 -0
- data/ext/sms.o +0 -0
- data/ext/sms.so +0 -0
- data/ext/sms_wrap.c +3606 -0
- data/ext/sms_wrap.o +0 -0
- data/lib/sms.so +0 -0
- data/lib/smsruby.rb +199 -0
- data/lib/smsruby.rb~ +199 -0
- data/lib/smsruby/adm_connection.rb +539 -0
- data/lib/smsruby/adm_connection.rb~ +539 -0
- data/lib/smsruby/connection.rb +141 -0
- data/lib/smsruby/connection.rb~ +141 -0
- data/lib/smsruby/error.rb +40 -0
- data/lib/smsruby/receive.rb +97 -0
- data/lib/smsruby/receive.rb~ +97 -0
- data/lib/smsruby/send.rb +182 -0
- data/lib/smsruby/send.rb~ +182 -0
- metadata +84 -0
data/lib/smsruby/send.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'smsruby/adm_connection'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sqlite3'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
#
|
7
|
+
# The Sender class represent the send layer. Reference a set of strategys wich
|
8
|
+
# will perform the same function but in a diferent way, that is, gather all the
|
9
|
+
# information required and comunicate with the Admconnection layer. This class
|
10
|
+
# it's called the context class, an acts as the user of the strategys.
|
11
|
+
#
|
12
|
+
class Sender
|
13
|
+
|
14
|
+
# Reference an instance for the Connection Administrator
|
15
|
+
attr_reader :adm
|
16
|
+
# Specify the destination number(s) to deliver the sms
|
17
|
+
attr_reader :dst
|
18
|
+
# Specify the messaje that will be deliver to destiny
|
19
|
+
attr_reader :msj
|
20
|
+
# Specify whether a delivered report will be generated or not (1: yes, 0: no)
|
21
|
+
attr_reader :report
|
22
|
+
# Specify a particular number for the smsc. If not specifyed default number will be used
|
23
|
+
attr_reader :smsc
|
24
|
+
# Specify the time of validity in minutos of the delivered sms
|
25
|
+
attr_reader :validity
|
26
|
+
# Specify the location of the file used to read send configuration
|
27
|
+
attr_reader :location
|
28
|
+
# Reference the type of send that will be used to set the parameters and deliver the message
|
29
|
+
attr_accessor :sendtype
|
30
|
+
|
31
|
+
|
32
|
+
#
|
33
|
+
# Set methods for the options of a message. Including validations.
|
34
|
+
#
|
35
|
+
def report=(report)
|
36
|
+
report = report.to_i unless report.class == Fixnum
|
37
|
+
unless report == 0 or report == 1
|
38
|
+
raise ArgumentError.new('Report only could be 0 or 1')
|
39
|
+
end
|
40
|
+
@report = report
|
41
|
+
end
|
42
|
+
|
43
|
+
def smsc=(smsc)
|
44
|
+
|
45
|
+
@smsc = smsc
|
46
|
+
end
|
47
|
+
|
48
|
+
def validity=(validity)
|
49
|
+
validity = validity.to_s unless validity.class == String
|
50
|
+
@validity = validity
|
51
|
+
end
|
52
|
+
|
53
|
+
def dst=(dst)
|
54
|
+
unless dst.class == Array
|
55
|
+
raise 'The destinatary must be an Array'
|
56
|
+
end
|
57
|
+
@dst = dst
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Obtains an instance of the Connection Administrator to control all existing
|
62
|
+
# connections. Due to the use of a singleton in the administrator, the same
|
63
|
+
# created instance will be obtain, or will be created if an instance doesn't
|
64
|
+
# exist. It also establish the strategy to be use acording to the specified by
|
65
|
+
# the user. An Exception is thrown if the instance of Admconnection fail
|
66
|
+
#
|
67
|
+
def initialize(sendtype,location= 'config_sms.yml')
|
68
|
+
begin
|
69
|
+
@adm = AdmConnection.instance
|
70
|
+
@location=location
|
71
|
+
@sendtype=sendtype
|
72
|
+
@report = 0
|
73
|
+
@smsc = nil
|
74
|
+
@validity = '0'
|
75
|
+
@dst =[]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Establish the option values to be use for sending the SMS message
|
81
|
+
#
|
82
|
+
def setconfig(dst,smsc,report,validity)
|
83
|
+
@dst=dst
|
84
|
+
@smsc=smsc
|
85
|
+
@report=report
|
86
|
+
@validity=validity
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Combine all option values into a hash to relate them
|
91
|
+
#
|
92
|
+
def to_hash
|
93
|
+
{ :type => 'send',
|
94
|
+
:dst => self.dst,
|
95
|
+
:msj => self.msj,
|
96
|
+
:smsc => self.smsc,
|
97
|
+
:report => self.report,
|
98
|
+
:validity => self.validity}
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Represent the send method for the Send class. The message to be send is passed
|
103
|
+
# as the only parameter and depending on the choosen strategy the other option
|
104
|
+
# values will be obtain diferently. The instance of the context class will be
|
105
|
+
# passed to the strategy, and the send function will be executed only if an
|
106
|
+
# instance of the Connection Administrator exist.
|
107
|
+
#
|
108
|
+
def send(msj)
|
109
|
+
begin
|
110
|
+
@msj = msj
|
111
|
+
!@adm.avlconn ? (raise "There are no active connections") : t=Thread.new{@sendtype.send(self){|e| yield e if block_given?}}
|
112
|
+
t[:type]='sp'
|
113
|
+
rescue Exception => e
|
114
|
+
@adm.log.error "Error sending message :: #{e.message}" unless @adm.log.nil?
|
115
|
+
raise e.message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# The Plainsend class represent one of the strategys and will use the recieve
|
123
|
+
# instance of the context class to invoke the send function of the Connection
|
124
|
+
# Administrator and also for getting all option values previosly set in the
|
125
|
+
# context class
|
126
|
+
#
|
127
|
+
class Plainsend
|
128
|
+
|
129
|
+
def send(context)
|
130
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# The Configsend class represent a strategy wich will use the received context
|
137
|
+
# class to invoke the send function of the Connection Administrator. With this
|
138
|
+
# strategy the option values will be obtain from a configuration file previosly
|
139
|
+
# created by user.
|
140
|
+
#
|
141
|
+
class Configsend
|
142
|
+
def send(context)
|
143
|
+
begin
|
144
|
+
parse = YAML::parse(File.open(context.location))
|
145
|
+
config = parse.transform
|
146
|
+
dst = config['parameters']['dst'].split(',')
|
147
|
+
context.dst=dst
|
148
|
+
context.validity=(config['parameters']['validity']).to_s if !(config['parameters']['validity']=~/[0-9]*/)
|
149
|
+
context.report=config['parameters']['report'] if !(config['parameters']['report']== 0 or config['parameters']['report'] == 1)
|
150
|
+
context.smsc=config['parameters']['smsc'] if !(config['parameters']['smsc']=~/[0-9]*/)
|
151
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
152
|
+
rescue Exception=> e
|
153
|
+
context.adm.log.error "Configsend Exception: #{e.message}"
|
154
|
+
raise e.message
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# The BDsend class represent a strategy wich will use the context class to invoke
|
161
|
+
# the send function of the Connection Administrator. With this strategy the
|
162
|
+
# destination option value will be taken from a database specified in the configuration
|
163
|
+
# file, and the other option values will be taken from the context class
|
164
|
+
#
|
165
|
+
class BDsend
|
166
|
+
|
167
|
+
def send(context)
|
168
|
+
begin
|
169
|
+
parse = YAML::parse(File.open(context.location))
|
170
|
+
config = parse.transform
|
171
|
+
db = SQLite3::Database.new(config['database']['db']+'.s3db')
|
172
|
+
sql = "Select " + config['database']['field'] + " from " + config['database']['table']
|
173
|
+
a = db.execute(sql)
|
174
|
+
context.dst=a
|
175
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
176
|
+
rescue Exception=> e
|
177
|
+
context.adm.log.error "BDsend Exception: #{e.message}"
|
178
|
+
raise e.message
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'adm_connection'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sqlite3'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
#
|
7
|
+
# The Sender class represent the send layer. Reference a set of strategys wich
|
8
|
+
# will perform the same function but in a diferent way, that is, gather all the
|
9
|
+
# information required and comunicate with the Admconnection layer. This class
|
10
|
+
# it's called the context class, an acts as the user of the strategys.
|
11
|
+
#
|
12
|
+
class Sender
|
13
|
+
|
14
|
+
# Reference an instance for the Connection Administrator
|
15
|
+
attr_reader :adm
|
16
|
+
# Specify the destination number(s) to deliver the sms
|
17
|
+
attr_reader :dst
|
18
|
+
# Specify the messaje that will be deliver to destiny
|
19
|
+
attr_reader :msj
|
20
|
+
# Specify whether a delivered report will be generated or not (1: yes, 0: no)
|
21
|
+
attr_reader :report
|
22
|
+
# Specify a particular number for the smsc. If not specifyed default number will be used
|
23
|
+
attr_reader :smsc
|
24
|
+
# Specify the time of validity in minutos of the delivered sms
|
25
|
+
attr_reader :validity
|
26
|
+
# Specify the location of the file used to read send configuration
|
27
|
+
attr_reader :location
|
28
|
+
# Reference the type of send that will be used to set the parameters and deliver the message
|
29
|
+
attr_accessor :sendtype
|
30
|
+
|
31
|
+
|
32
|
+
#
|
33
|
+
# Set methods for the options of a message. Including validations.
|
34
|
+
#
|
35
|
+
def report=(report)
|
36
|
+
report = report.to_i unless report.class == Fixnum
|
37
|
+
unless report == 0 or report == 1
|
38
|
+
raise ArgumentError.new('Report only could be 0 or 1')
|
39
|
+
end
|
40
|
+
@report = report
|
41
|
+
end
|
42
|
+
|
43
|
+
def smsc=(smsc)
|
44
|
+
|
45
|
+
@smsc = smsc
|
46
|
+
end
|
47
|
+
|
48
|
+
def validity=(validity)
|
49
|
+
validity = validity.to_s unless validity.class == String
|
50
|
+
@validity = validity
|
51
|
+
end
|
52
|
+
|
53
|
+
def dst=(dst)
|
54
|
+
unless dst.class == Array
|
55
|
+
raise 'The destinatary must be an Array'
|
56
|
+
end
|
57
|
+
@dst = dst
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# Obtains an instance of the Connection Administrator to control all existing
|
62
|
+
# connections. Due to the use of a singleton in the administrator, the same
|
63
|
+
# created instance will be obtain, or will be created if an instance doesn't
|
64
|
+
# exist. It also establish the strategy to be use acording to the specified by
|
65
|
+
# the user. An Exception is thrown if the instance of Admconnection fail
|
66
|
+
#
|
67
|
+
def initialize(sendtype,location= 'config_sms.yml')
|
68
|
+
begin
|
69
|
+
@adm = AdmConnection.instance
|
70
|
+
@location=location
|
71
|
+
@sendtype=sendtype
|
72
|
+
@report = 0
|
73
|
+
@smsc = nil
|
74
|
+
@validity = '0'
|
75
|
+
@dst =[]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Establish the option values to be use for sending the SMS message
|
81
|
+
#
|
82
|
+
def setconfig(dst,smsc,report,validity)
|
83
|
+
@dst=dst
|
84
|
+
@smsc=smsc
|
85
|
+
@report=report
|
86
|
+
@validity=validity
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Combine all option values into a hash to relate them
|
91
|
+
#
|
92
|
+
def to_hash
|
93
|
+
{ :type => 'send',
|
94
|
+
:dst => self.dst,
|
95
|
+
:msj => self.msj,
|
96
|
+
:smsc => self.smsc,
|
97
|
+
:report => self.report,
|
98
|
+
:validity => self.validity}
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Represent the send method for the Send class. The message to be send is passed
|
103
|
+
# as the only parameter and depending on the choosen strategy the other option
|
104
|
+
# values will be obtain diferently. The instance of the context class will be
|
105
|
+
# passed to the strategy, and the send function will be executed only if an
|
106
|
+
# instance of the Connection Administrator exist.
|
107
|
+
#
|
108
|
+
def send(msj)
|
109
|
+
begin
|
110
|
+
@msj = msj
|
111
|
+
!@adm.avlconn ? (raise "There are no active connections") : t=Thread.new{@sendtype.send(self){|e| yield e if block_given?}}
|
112
|
+
t[:type]='sp'
|
113
|
+
rescue Exception => e
|
114
|
+
@adm.log.error "Error sending message :: #{e.message}" unless @adm.log.nil?
|
115
|
+
raise e.message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
#
|
122
|
+
# The Plainsend class represent one of the strategys and will use the recieve
|
123
|
+
# instance of the context class to invoke the send function of the Connection
|
124
|
+
# Administrator and also for getting all option values previosly set in the
|
125
|
+
# context class
|
126
|
+
#
|
127
|
+
class Plainsend
|
128
|
+
|
129
|
+
def send(context)
|
130
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
#
|
136
|
+
# The Configsend class represent a strategy wich will use the received context
|
137
|
+
# class to invoke the send function of the Connection Administrator. With this
|
138
|
+
# strategy the option values will be obtain from a configuration file previosly
|
139
|
+
# created by user.
|
140
|
+
#
|
141
|
+
class Configsend
|
142
|
+
def send(context)
|
143
|
+
begin
|
144
|
+
parse = YAML::parse(File.open(context.location))
|
145
|
+
config = parse.transform
|
146
|
+
dst = config['parameters']['dst'].split(',')
|
147
|
+
context.dst=dst
|
148
|
+
context.validity=(config['parameters']['validity']).to_s if !(config['parameters']['validity']=~/[0-9]*/)
|
149
|
+
context.report=config['parameters']['report'] if !(config['parameters']['report']== 0 or config['parameters']['report'] == 1)
|
150
|
+
context.smsc=config['parameters']['smsc'] if !(config['parameters']['smsc']=~/[0-9]*/)
|
151
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
152
|
+
rescue Exception=> e
|
153
|
+
context.adm.log.error "Configsend Exception: #{e.message}"
|
154
|
+
raise e.message
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# The BDsend class represent a strategy wich will use the context class to invoke
|
161
|
+
# the send function of the Connection Administrator. With this strategy the
|
162
|
+
# destination option value will be taken from a database specified in the configuration
|
163
|
+
# file, and the other option values will be taken from the context class
|
164
|
+
#
|
165
|
+
class BDsend
|
166
|
+
|
167
|
+
def send(context)
|
168
|
+
begin
|
169
|
+
parse = YAML::parse(File.open(context.location))
|
170
|
+
config = parse.transform
|
171
|
+
db = SQLite3::Database.new(config['database']['db']+'.s3db')
|
172
|
+
sql = "Select " + config['database']['field'] + " from " + config['database']['table']
|
173
|
+
a = db.execute(sql)
|
174
|
+
context.dst=a
|
175
|
+
context.adm.send(context.to_hash){|e| yield e if block_given?}
|
176
|
+
rescue Exception=> e
|
177
|
+
context.adm.log.error "BDsend Exception: #{e.message}"
|
178
|
+
raise e.message
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smsRuby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: x86-linux
|
6
|
+
authors:
|
7
|
+
- Alejandro Garcia Tome, Yennifer Chacon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-09-07 00:00:00 -04:30
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sqlite3-ruby
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.4
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: hewital@gmail.com, ychacon@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
34
|
+
- ext/sms_wrap.c
|
35
|
+
- ext/RecieveSMS.o
|
36
|
+
- ext/extconf.rb
|
37
|
+
- ext/sms_wrap.o
|
38
|
+
- ext/SendSMS.o
|
39
|
+
- ext/sms.i
|
40
|
+
- ext/sms.o
|
41
|
+
- ext/Makefile
|
42
|
+
- ext/sms.so
|
43
|
+
- lib/smsruby.rb
|
44
|
+
- lib/smsruby.rb~
|
45
|
+
- lib/smsruby
|
46
|
+
- lib/smsruby/send.rb~
|
47
|
+
- lib/smsruby/adm_connection.rb
|
48
|
+
- lib/smsruby/receive.rb
|
49
|
+
- lib/smsruby/receive.rb~
|
50
|
+
- lib/smsruby/connection.rb
|
51
|
+
- lib/smsruby/adm_connection.rb~
|
52
|
+
- lib/smsruby/connection.rb~
|
53
|
+
- lib/smsruby/error.rb
|
54
|
+
- lib/smsruby/send.rb
|
55
|
+
- lib/sms.so
|
56
|
+
- README.rdoc
|
57
|
+
has_rdoc: true
|
58
|
+
homepage:
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
requirements: []
|
77
|
+
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.3.1
|
80
|
+
signing_key:
|
81
|
+
specification_version: 2
|
82
|
+
summary: An easy way to send and receive SMS message.
|
83
|
+
test_files: []
|
84
|
+
|