mfms 0.6.1 → 0.7.1
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.
- checksums.yaml +4 -4
- data/lib/mfms/sms.rb +60 -27
- data/lib/mfms/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a304a95be4ad312b2af17ad65f5743c26d2d729d
|
4
|
+
data.tar.gz: 748d3e4f8c6057f1df51557688bae7c77a747ce8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bd97ba74f429ee224f42b5cb73370a4489093b7f3577a4cfca98214ba3e218bc0e6715c6422146f7d670855db78f8aa273d59cefa74ebbca27660750895d5cd
|
7
|
+
data.tar.gz: 6b32d1e99bc74fa2d1d5b8daf0290f11f81b4cd4379e0ca377aef6d660330918f6a9a4b1249e7d768b6ebcf1cdb6a95ea9456d93f325fd36afb3b02009c01518
|
data/lib/mfms/sms.rb
CHANGED
@@ -10,26 +10,33 @@ module Mfms
|
|
10
10
|
attr_accessor :phone, :subject, :message, :account, :login, :password, :server, :cert, :port, :ssl_port, :ssl
|
11
11
|
attr_reader :id, :status, :errors
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@phone = phone
|
15
|
-
@subject = subject
|
16
|
-
@message = message
|
13
|
+
def initialize(data)
|
14
|
+
@phone = data.fetch(:phone, nil)
|
15
|
+
@subject = data.fetch(:subject, nil)
|
16
|
+
@message = data.fetch(:message, nil)
|
17
17
|
@status = 'not-sent'
|
18
|
-
|
19
|
-
account_variable = if
|
20
|
-
|
18
|
+
account_name = data[:account]
|
19
|
+
account_variable = if account_name.present?
|
20
|
+
var_name = "@@#{account_name}".to_sym
|
21
|
+
if self.class.class_variables.include?(var_name)
|
22
|
+
var_name
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Account with name '#{account_name}' is not defined"
|
25
|
+
end
|
21
26
|
else
|
22
|
-
self.class.
|
27
|
+
self.class.default_account
|
23
28
|
end
|
24
|
-
account_settings =
|
29
|
+
account_settings = self.class.class_variable_get(account_variable)
|
25
30
|
@login = account_settings[:login]
|
31
|
+
@connector = account_settings[:connector]
|
26
32
|
@password = account_settings[:password]
|
27
33
|
@ssl = account_settings[:ssl]
|
28
34
|
@ssl_port = account_settings[:ssl_port]
|
29
35
|
@port = account_settings[:port]
|
30
36
|
@cert = account_settings[:cert]
|
31
37
|
@server = account_settings[:server]
|
32
|
-
@translit = translit
|
38
|
+
@translit = data.fetch(:translit, account_settings[:translit])
|
39
|
+
@priority = data.fetch(:priority, account_settings[:priority])
|
33
40
|
@errors = []
|
34
41
|
validate!
|
35
42
|
end
|
@@ -39,11 +46,25 @@ module Mfms
|
|
39
46
|
account = setting.keys.first
|
40
47
|
account_settings = setting[account]
|
41
48
|
account_settings[:cert] = init_cert_store(account_settings[:cert])
|
42
|
-
account_settings[:ssl] = account_settings
|
43
|
-
account_settings[:translit] = account_settings
|
44
|
-
|
45
|
-
|
49
|
+
account_settings[:ssl] = account_settings.fetch(:ssl, true)
|
50
|
+
account_settings[:translit] = account_settings.fetch(:translit, false)
|
51
|
+
account_settings[:additional_args] = account_settings.fetch(:additional_args, nil)
|
52
|
+
account_settings[:priority] = account_settings.fetch(:priority, nil)
|
53
|
+
if settings_valid?(account_settings)
|
54
|
+
self.class_variable_set("@@#{account}", account_settings)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.default_account
|
60
|
+
default_account = nil
|
61
|
+
Array.wrap(class_variables).each do |account|
|
62
|
+
if class_variable_get(account.to_s).has_key?(:default)
|
63
|
+
default_account = account
|
64
|
+
break
|
65
|
+
end
|
46
66
|
end
|
67
|
+
default_account || raise(ArgumentError, 'One of the accounts should be specified by default')
|
47
68
|
end
|
48
69
|
|
49
70
|
# => SMS send status codes:
|
@@ -103,9 +124,15 @@ module Mfms
|
|
103
124
|
|
104
125
|
def validate!
|
105
126
|
raise ArgumentError, "Phone should be assigned to #{self.class}." if @phone.nil?
|
106
|
-
|
127
|
+
unless @phone =~ /^[0-9]{10,}$/
|
128
|
+
raise ArgumentError, 'Phone number should contain only numbers. Minimum'+
|
129
|
+
"length is 10. #{@phone.inspect} is given."
|
130
|
+
end
|
107
131
|
raise ArgumentError, "Subject should be assigned to #{self.class}." if @subject.nil?
|
108
132
|
raise ArgumentError, "Message should be assigned to #{self.class}." if @message.nil?
|
133
|
+
if @priority && !%w(low normal high realtime).include?(@priority)
|
134
|
+
raise ArgumentError, 'Priority is not valid.'
|
135
|
+
end
|
109
136
|
end
|
110
137
|
|
111
138
|
private
|
@@ -126,25 +153,31 @@ module Mfms
|
|
126
153
|
cert_store
|
127
154
|
end
|
128
155
|
|
129
|
-
def self.
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
156
|
+
def self.settings_valid?(settings)
|
157
|
+
[:login, :password, :server, :port, :ssl_port].each do |attr|
|
158
|
+
if settings[attr].nil?
|
159
|
+
raise ArgumentError, "#{attr.to_s.gsub(/_/,' ').capitalize} should be defined for #{self}."
|
160
|
+
end
|
161
|
+
end
|
162
|
+
[:port, :ssl_port].each do |attr|
|
163
|
+
unless settings[attr].instance_of?(Fixnum)
|
164
|
+
raise ArgumentError,
|
165
|
+
"#{attr.to_s.gsub(/_/,' ').capitalize} should contain only numbers. #{settings[attr].inspect} is given."
|
166
|
+
end
|
167
|
+
end
|
168
|
+
true
|
137
169
|
end
|
138
170
|
|
139
171
|
def send_url
|
140
172
|
message = @translit ? Russian.translit(@message) : @message
|
141
|
-
"/revoup/
|
173
|
+
url = "/revoup/#{@connector}/send?login=#{@login}&password=#{@password}&" +
|
142
174
|
"subject[0]=#{@subject}&address[0]=#{@phone}&text[0]=#{URI.encode(message)}"
|
175
|
+
url += "&priority=#{@priority}" if @priority
|
176
|
+
url
|
143
177
|
end
|
144
178
|
|
145
|
-
def
|
146
|
-
"/revoup/
|
147
|
-
"providerId[0]=#{msg_id}"
|
179
|
+
def status_url(msg_id)
|
180
|
+
"/revoup/#{@connector}/status?login=#{@login}&password=#{@password}&providerId[0]=#{msg_id}"
|
148
181
|
end
|
149
182
|
|
150
183
|
end
|
data/lib/mfms/version.rb
CHANGED