smess 1.0.2 → 1.0.3
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/Gemfile.lock +1 -1
- data/README.md +7 -1
- data/lib/smess.rb +2 -1
- data/lib/smess/outputs/auto.rb +11 -7
- data/lib/smess/outputs/clickatell.rb +62 -61
- data/lib/smess/outputs/etisalatdemo.rb +8 -7
- data/lib/smess/outputs/global_mouth.rb +4 -42
- data/lib/smess/outputs/http_base.rb +54 -0
- data/lib/smess/outputs/ipx.rb +20 -16
- data/lib/smess/outputs/mblox.rb +101 -87
- data/lib/smess/outputs/smsglobal.rb +14 -40
- data/lib/smess/outputs/test.rb +4 -5
- data/lib/smess/outputs/twilio.rb +6 -2
- data/lib/smess/sms.rb +2 -2
- data/lib/smess/utils.rb +1 -1
- data/lib/smess/version.rb +1 -1
- data/lib/string.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c74dd29d5a45e1ac70089ea67c1f29148706bb4
|
4
|
+
data.tar.gz: fd3a185d53f641db6226a9a4a80dd2de5e8f57c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 818eee9d6e7328c6fee1bf647bbf30342dddf9d83dbdd97a6292e0cc70dabad8bef04b94105bd3042aaf0fe0f1076709db516ab2bfb0af8644ca71fe7386c59a
|
7
|
+
data.tar.gz: 5bd2f48c54d878ccdb589be344d756ea49024d296eca34bd3da11d90e22e46648b3470ebf41b2845615295257a2ebf161e208dd978d4cde8407d4892e8a9f843
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,13 @@ The aggregator outputs are a very simple plugin system so you can subclass, modi
|
|
39
39
|
module Smess
|
40
40
|
class Example
|
41
41
|
|
42
|
-
|
42
|
+
attr_reader :sms
|
43
|
+
|
44
|
+
def initialize(sms)
|
45
|
+
@sms = sms
|
46
|
+
end
|
47
|
+
|
48
|
+
def deliver
|
43
49
|
# Do work and return a hash like this one
|
44
50
|
{
|
45
51
|
:response_code => '-1',
|
data/lib/smess.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# coding: UTF-8
|
2
2
|
smess_path = File.expand_path('.', File.dirname(__FILE__))
|
3
3
|
$:.unshift(smess_path) if File.directory?(smess_path) && !$:.include?(smess_path)
|
4
4
|
|
@@ -11,6 +11,7 @@ require 'smess/logging'
|
|
11
11
|
require 'smess/country_code_registry'
|
12
12
|
require 'smess/utils'
|
13
13
|
require 'smess/sms'
|
14
|
+
require 'smess/outputs/http_base'
|
14
15
|
require 'smess/outputs/auto'
|
15
16
|
require 'smess/outputs/ipx'
|
16
17
|
require 'smess/outputs/ipxus'
|
data/lib/smess/outputs/auto.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Smess
|
2
2
|
class Auto
|
3
3
|
|
4
|
+
def initialize(sms)
|
5
|
+
@sms = sms
|
6
|
+
end
|
7
|
+
|
4
8
|
def get_output_name_for_msisdn(msisdn)
|
5
9
|
3.downto(0).each do |index|
|
6
10
|
return OUTPUT_BY_COUNTRY_CODE[msisdn[0..index]] if OUTPUT_BY_COUNTRY_CODE.key? msisdn[0..index]
|
@@ -10,17 +14,17 @@ module Smess
|
|
10
14
|
|
11
15
|
def output_for(msisdn)
|
12
16
|
out_class = get_output_name_for_msisdn msisdn
|
13
|
-
("Smess::#{out_class.to_s.camelize}").constantize.new
|
17
|
+
("Smess::#{out_class.to_s.camelize}").constantize.new(sms)
|
14
18
|
end
|
15
19
|
|
16
|
-
def
|
20
|
+
def deliver
|
17
21
|
out = output_for sms.to
|
18
|
-
|
19
|
-
out.deliver_sms sms
|
20
|
-
else
|
21
|
-
nil
|
22
|
-
end
|
22
|
+
out.deliver
|
23
23
|
end
|
24
24
|
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :sms
|
28
|
+
|
25
29
|
end
|
26
30
|
end
|
@@ -26,88 +26,89 @@ module Smess
|
|
26
26
|
class Clickatell
|
27
27
|
include Smess::Logging
|
28
28
|
|
29
|
-
def initialize
|
29
|
+
def initialize(sms)
|
30
|
+
@sms = sms
|
30
31
|
::Clickatell::API.debug_mode = true
|
31
32
|
::Clickatell::API.secure_mode = true
|
32
33
|
end
|
33
34
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
def deliver
|
36
|
+
begin
|
37
|
+
responses = []
|
38
|
+
messages.each do |msg|
|
39
|
+
rsp = api.send_message(sms.to, msg.encode('ISO-8859-1'), {from: from, concat: 3, callback: 7})
|
40
|
+
responses << rsp
|
41
|
+
end
|
42
|
+
result = normal_result(responses.first)
|
43
|
+
rescue Exception => e
|
44
|
+
# connection problem or some error
|
45
|
+
result = result_for_error(e)
|
44
46
|
end
|
45
|
-
result << text
|
46
47
|
result
|
47
48
|
end
|
48
49
|
|
49
|
-
|
50
|
+
private
|
51
|
+
|
52
|
+
attr_reader :sms
|
53
|
+
|
54
|
+
def from
|
55
|
+
return nil if sender_not_supported
|
56
|
+
ENV["SMESS_CLICKATELL_SENDER_IDS"].split(",").include?(sms.originator) ? sms.originator : ENV["SMESS_CLICKATELL_SENDER_ID"]
|
57
|
+
end
|
58
|
+
|
59
|
+
def messages
|
60
|
+
msg = sms.message.strip_nongsm_chars
|
61
|
+
concat_not_supported ? Smess.separate_sms(msg) : [msg]
|
62
|
+
end
|
63
|
+
|
64
|
+
# "feature detection"
|
65
|
+
# Clickatell's API requires knowledge of country-specific quirks and feature support.
|
66
|
+
# Supported features can and does change without notice, breaking some countries.
|
67
|
+
def sender_not_supported
|
50
68
|
sms.to[0] == "1" || # USA
|
51
69
|
sms.to[0..2] == "962" || # Jordan
|
52
70
|
sms.to[0..2] == "971" # UAE
|
53
71
|
end
|
54
|
-
def concat_not_supported
|
72
|
+
def concat_not_supported
|
55
73
|
sms.to[0] == "1" # USA
|
56
74
|
end
|
57
75
|
|
58
|
-
|
59
|
-
|
60
|
-
def deliver_sms(sms)
|
61
|
-
return false unless sms.kind_of? Sms
|
62
|
-
@sms = sms
|
63
|
-
|
64
|
-
api = ::Clickatell::API.authenticate(
|
76
|
+
def api
|
77
|
+
@api ||= ::Clickatell::API.authenticate(
|
65
78
|
ENV["SMESS_CLICKATELL_API_ID"],
|
66
79
|
ENV["SMESS_CLICKATELL_USER"],
|
67
80
|
ENV["SMESS_CLICKATELL_PASS"]
|
68
81
|
)
|
69
|
-
|
70
|
-
from = ENV["SMESS_CLICKATELL_SENDER_IDS"].split(",").include?(sms.originator) ? sms.originator : ENV["SMESS_CLICKATELL_SENDER_ID"]
|
71
|
-
|
72
|
-
# Pretty pretty "feature detection"
|
73
|
-
if sender_not_supported sms
|
74
|
-
from = nil
|
75
|
-
end
|
76
|
-
if concat_not_supported sms
|
77
|
-
message_array = split_sms(message)
|
78
|
-
end
|
82
|
+
end
|
79
83
|
|
80
|
-
|
81
|
-
if concat_not_supported sms
|
82
|
-
response = nil
|
83
|
-
message_array.each do |msg|
|
84
|
-
rsp = api.send_message(sms.to, msg, {:from => from, :concat => 3, :callback => 7})
|
85
|
-
response = rsp if response.nil?
|
86
|
-
end
|
87
|
-
else
|
88
|
-
response = api.send_message(sms.to, message, {:from => from, :concat => 3, :callback => 7})
|
89
|
-
end
|
90
|
-
rescue Exception => e
|
91
|
-
logger.warn response
|
92
|
-
# connection problem or some error
|
93
|
-
result = {
|
94
|
-
:response_code => '-1',
|
95
|
-
:response => {
|
96
|
-
:temporaryError =>'true',
|
97
|
-
:responseCode => e.code,
|
98
|
-
:responseText => e.message
|
99
|
-
},
|
100
|
-
:data => {:to => sms.to, :text => sms.message.strip_nongsm_chars, :from => from}
|
101
|
-
}
|
102
|
-
return result
|
103
|
-
end
|
84
|
+
def normal_result(response)
|
104
85
|
# Successful response
|
105
|
-
|
106
|
-
:
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
|
86
|
+
{
|
87
|
+
message_id: response['ID'],
|
88
|
+
response_code: '0',
|
89
|
+
response: response,
|
90
|
+
destination_address: sms.to,
|
91
|
+
data: result_data
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def result_for_error(e)
|
96
|
+
{
|
97
|
+
response_code: '-1',
|
98
|
+
response: {
|
99
|
+
temporaryError: 'true',
|
100
|
+
responseCode: '-1',
|
101
|
+
responseText: e.message
|
102
|
+
},
|
103
|
+
data: result_data
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
def result_data
|
108
|
+
{
|
109
|
+
to: sms.to,
|
110
|
+
text: sms.message.strip_nongsm_chars,
|
111
|
+
from: from
|
111
112
|
}
|
112
113
|
end
|
113
114
|
|
@@ -2,7 +2,10 @@ module Smess
|
|
2
2
|
class Etisalatdemo
|
3
3
|
include Smess::Logging
|
4
4
|
|
5
|
-
|
5
|
+
attr_reader :sms
|
6
|
+
|
7
|
+
def initialize(sms)
|
8
|
+
@sms = sms
|
6
9
|
@smtp_settings = {
|
7
10
|
address: "exmail.emirates.net.ae",
|
8
11
|
port: 25,
|
@@ -14,16 +17,14 @@ module Smess
|
|
14
17
|
}
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
18
|
-
return false unless sms.kind_of? Sms
|
19
|
-
@sms = sms
|
20
|
-
|
20
|
+
def deliver
|
21
21
|
local_from_var = from_address
|
22
|
+
local_sms = sms
|
22
23
|
mail = Mail.new do
|
23
24
|
from local_from_var
|
24
|
-
to "+#{
|
25
|
+
to "+#{local_sms.to}@email2sms.ae"
|
25
26
|
subject "Smess Message"
|
26
|
-
body
|
27
|
+
body local_sms.message.strip_nongsm_chars
|
27
28
|
end
|
28
29
|
|
29
30
|
mail.delivery_method :smtp, @smtp_settings
|
@@ -2,18 +2,13 @@ require 'uri'
|
|
2
2
|
require 'httpi'
|
3
3
|
|
4
4
|
module Smess
|
5
|
-
class GlobalMouth
|
6
|
-
include Smess::Logging
|
7
|
-
|
8
|
-
def deliver_sms(sms_arg)
|
9
|
-
return false unless sms_arg.kind_of? Sms
|
10
|
-
@sms = sms_arg
|
5
|
+
class GlobalMouth < HttpBase
|
11
6
|
|
7
|
+
def deliver
|
12
8
|
generate_mac_hash
|
13
9
|
request.url = "#{url}?#{params.to_query}"
|
14
10
|
|
15
11
|
begin
|
16
|
-
HTTPI.log_level = :debug
|
17
12
|
response = HTTPI.get request
|
18
13
|
result = normal_result(response)
|
19
14
|
rescue Exception => e
|
@@ -26,14 +21,14 @@ module Smess
|
|
26
21
|
|
27
22
|
private
|
28
23
|
|
29
|
-
attr_reader :sms
|
30
|
-
|
31
24
|
def username
|
32
25
|
ENV["SMESS_GLOBAL_MOUTH_USER"].dup # paranoid safeguard
|
33
26
|
end
|
27
|
+
|
34
28
|
def password
|
35
29
|
ENV["SMESS_GLOBAL_MOUTH_PASS"]
|
36
30
|
end
|
31
|
+
|
37
32
|
def sender_id
|
38
33
|
ENV["SMESS_GLOBAL_MOUTH_SENDER_ID"]
|
39
34
|
end
|
@@ -42,14 +37,6 @@ module Smess
|
|
42
37
|
"https://mcm.globalmouth.com:8443/api/mcm"
|
43
38
|
end
|
44
39
|
|
45
|
-
def from
|
46
|
-
sms.originator || sender_id
|
47
|
-
end
|
48
|
-
|
49
|
-
def message_id
|
50
|
-
@message_id ||= Digest::MD5.hexdigest "#{Time.now.strftime('%Y%m%d%H%M%S')}#{sms.to}-#{SecureRandom.hex(6)}"
|
51
|
-
end
|
52
|
-
|
53
40
|
def params
|
54
41
|
@params ||= {
|
55
42
|
username: username,
|
@@ -73,23 +60,6 @@ module Smess
|
|
73
60
|
)
|
74
61
|
end
|
75
62
|
|
76
|
-
def request
|
77
|
-
@request ||= HTTPI::Request.new
|
78
|
-
end
|
79
|
-
|
80
|
-
def result_for_error(e)
|
81
|
-
code = e.code rescue "-1"
|
82
|
-
{
|
83
|
-
response_code: '-1',
|
84
|
-
response: {
|
85
|
-
temporaryError: 'true',
|
86
|
-
responseCode: e.code,
|
87
|
-
responseText: e.message
|
88
|
-
},
|
89
|
-
data: result_data
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
63
|
def normal_result(response)
|
94
64
|
response_code = response.body.split(/\n/).first
|
95
65
|
response_code = "0" if response_code == "200"
|
@@ -103,13 +73,5 @@ module Smess
|
|
103
73
|
}
|
104
74
|
end
|
105
75
|
|
106
|
-
def result_data
|
107
|
-
{
|
108
|
-
to: sms.to,
|
109
|
-
text: sms.message.strip_nongsm_chars,
|
110
|
-
from: from
|
111
|
-
}
|
112
|
-
end
|
113
|
-
|
114
76
|
end
|
115
77
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'httpi'
|
3
|
+
|
4
|
+
module Smess
|
5
|
+
class HttpBase
|
6
|
+
include Smess::Logging
|
7
|
+
|
8
|
+
def initialize(sms)
|
9
|
+
@sms = sms
|
10
|
+
HTTPI.log_level = :debug
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :sms
|
16
|
+
|
17
|
+
def sender_id
|
18
|
+
ENV["SMESS_SENDER_ID"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def from
|
22
|
+
sms.originator || sender_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def message_id
|
26
|
+
@message_id ||= Digest::MD5.hexdigest "#{Time.now.strftime('%Y%m%d%H%M%S')}#{sms.to}-#{SecureRandom.hex(6)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def request
|
30
|
+
@request ||= HTTPI::Request.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def result_for_error(e)
|
34
|
+
{
|
35
|
+
response_code: '-1',
|
36
|
+
response: {
|
37
|
+
temporaryError: 'true',
|
38
|
+
responseCode: '-1',
|
39
|
+
responseText: e.message
|
40
|
+
},
|
41
|
+
data: result_data
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def result_data
|
46
|
+
{
|
47
|
+
to: sms.to,
|
48
|
+
text: sms.message.strip_nongsm_chars,
|
49
|
+
from: from
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/smess/outputs/ipx.rb
CHANGED
@@ -2,7 +2,9 @@ module Smess
|
|
2
2
|
class Ipx
|
3
3
|
include Smess::Logging
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize(sms)
|
6
|
+
@sms = sms
|
7
|
+
@results = []
|
6
8
|
@endpoint = account[:sms_url]
|
7
9
|
@credentials = {
|
8
10
|
name: account[:username],
|
@@ -21,25 +23,16 @@ module Smess
|
|
21
23
|
}
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
return false unless sms_arg.kind_of? Sms
|
26
|
-
@sms = sms_arg
|
27
|
-
|
26
|
+
def deliver
|
28
27
|
set_originator(sms.originator)
|
28
|
+
perform_operator_adaptation(sms.to)
|
29
29
|
|
30
|
-
perform_operator_adaptation sms.to
|
31
|
-
|
32
|
-
results = []
|
33
30
|
parts.each_with_index do |part, i|
|
34
|
-
|
35
|
-
# if we have several parts, send them as concatenated sms using UDH codes
|
36
|
-
soap_body["userDataHeader"] = concatenation_udh(i+1, parts.length) if parts.length > 1
|
37
|
-
soap_body["userData"] = part
|
38
|
-
soap_body["correlationId"] = Time.now.strftime('%Y%m%d%H%M%S') + sms.to + (i+1).to_s
|
31
|
+
populate_soap_body(part, i)
|
39
32
|
results << send_one_sms
|
40
33
|
|
41
34
|
# halt and use fallback on error...
|
42
|
-
|
35
|
+
if last_result_was_error
|
43
36
|
logger.info "IPX_ERROR: #{results.last}"
|
44
37
|
return fallback_to_twilio || results.first
|
45
38
|
end
|
@@ -52,6 +45,7 @@ module Smess
|
|
52
45
|
private
|
53
46
|
|
54
47
|
attr_reader :sms
|
48
|
+
attr_accessor :results
|
55
49
|
|
56
50
|
def soap_body
|
57
51
|
@soap_body ||= {
|
@@ -147,6 +141,13 @@ module Smess
|
|
147
141
|
@ref_id ||= Random.new.rand(255).to_s(16).rjust(2,"0")
|
148
142
|
end
|
149
143
|
|
144
|
+
def populate_soap_body(part, i)
|
145
|
+
# if we have several parts, send them as concatenated sms using UDH codes
|
146
|
+
soap_body["userDataHeader"] = concatenation_udh(i+1, parts.length) if parts.length > 1
|
147
|
+
soap_body["userData"] = part
|
148
|
+
soap_body["correlationId"] = Time.now.strftime('%Y%m%d%H%M%S') + sms.to + (i+1).to_s
|
149
|
+
end
|
150
|
+
|
150
151
|
def send_one_sms
|
151
152
|
client = soap_client
|
152
153
|
soap_body_var = soap_body
|
@@ -162,6 +163,10 @@ module Smess
|
|
162
163
|
result
|
163
164
|
end
|
164
165
|
|
166
|
+
def last_result_was_error
|
167
|
+
results.last.fetch(:response_code, '').to_s != "0"
|
168
|
+
end
|
169
|
+
|
165
170
|
def parse_sms_response(response)
|
166
171
|
if response.http_error? || response.soap_fault?
|
167
172
|
e = Struct.new(:code, :message).new("-1", response.http_error || response.soap_fault.to_hash)
|
@@ -173,12 +178,11 @@ module Smess
|
|
173
178
|
end
|
174
179
|
|
175
180
|
def result_for_error(e)
|
176
|
-
code = e.code rescue "-1"
|
177
181
|
{
|
178
182
|
response_code: '-1',
|
179
183
|
response: {
|
180
184
|
temporaryError: 'true',
|
181
|
-
responseCode:
|
185
|
+
responseCode: '-1',
|
182
186
|
responseText: e.message
|
183
187
|
},
|
184
188
|
data: result_data
|
data/lib/smess/outputs/mblox.rb
CHANGED
@@ -5,100 +5,24 @@ module Smess
|
|
5
5
|
class Mblox
|
6
6
|
include Smess::Logging
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return false if parts[0].empty?
|
8
|
+
def initialize(sms)
|
9
|
+
@sms = sms
|
10
|
+
@results = []
|
11
|
+
end
|
13
12
|
|
13
|
+
def deliver
|
14
14
|
xml_params = {
|
15
15
|
subscriber_number: sms.to,
|
16
16
|
message: ""
|
17
17
|
}
|
18
|
-
# if we have several parts, send them as concatenated sms
|
19
|
-
if parts.length > 1
|
20
|
-
logger.info "Num Parts: #{parts.length.to_s}"
|
21
|
-
# create concat-sms UDH
|
22
|
-
ref_id = Random.new.rand(255).to_s(16).rjust(2,"0")
|
23
|
-
num_parts = parts.length
|
24
|
-
xml_params[:udh] = ":05:00:03:#{ref_id}:#{num_parts.to_s(16).rjust(2,'0')}:01" # {050003}{ff}{02}{01} {concat-command}{id to link all parts}{total num parts}{num of current part}
|
25
|
-
end
|
26
18
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# send additional parts if we have them
|
34
|
-
if parts.length > 0 && result[:response_code] != "-1"
|
35
|
-
more_results = []
|
36
|
-
parts.each_with_index do |part, i|
|
37
|
-
xml_params[:message] = part
|
38
|
-
xml_params[:udh] = ":05:00:03:#{ref_id}:#{num_parts.to_s(16).rjust(2,'0')}:#{(i+2).to_s(16).rjust(2,'0')}"
|
39
|
-
more_results << send_one_sms( xml_params )
|
40
|
-
end
|
41
|
-
# we don't actually return the status for any of these which is cheating
|
42
|
-
logger.info more_results
|
19
|
+
parts.each_with_index do |part, i|
|
20
|
+
xml_params[:message] = part
|
21
|
+
xml_params[:udh] = concatenation_udh(i+1, parts.length) if parts.length > 1
|
22
|
+
results << send_one_sms(xml_params)
|
43
23
|
end
|
44
24
|
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def send_one_sms(xml_params)
|
50
|
-
xml = xml_data_for(xml_params)
|
51
|
-
body = "XMLDATA="+URI::encode( xml.encode("ISO-8859-1") ) # escape
|
52
|
-
|
53
|
-
request = HTTPI::Request.new
|
54
|
-
request.url = 'https://xml4.us.mblox.com:443/send'
|
55
|
-
request.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
56
|
-
request.body = body
|
57
|
-
|
58
|
-
begin
|
59
|
-
HTTPI.log_level = :debug
|
60
|
-
response = HTTPI.post request
|
61
|
-
|
62
|
-
rescue Exception => e
|
63
|
-
logger.warn response
|
64
|
-
# connection problem or some error
|
65
|
-
result = {
|
66
|
-
response_code: '-1',
|
67
|
-
response: {
|
68
|
-
temporaryError: 'true',
|
69
|
-
responseCode: e.code,
|
70
|
-
responseText: e.message
|
71
|
-
},
|
72
|
-
data: {
|
73
|
-
to: xml_params[:subscriber_number],
|
74
|
-
text: xml_params[:message],
|
75
|
-
from: ENV["SMESS_MBLOX_SURE_ROUTE_SHORTCODE"]
|
76
|
-
}
|
77
|
-
}
|
78
|
-
else
|
79
|
-
response_data = Nori.parse(response.body)
|
80
|
-
response_code = response_code_for response_data
|
81
|
-
# Successful response
|
82
|
-
result = {
|
83
|
-
message_id: @message_id,
|
84
|
-
response_code: response_code,
|
85
|
-
response: response_data,
|
86
|
-
destination_address: xml_params[:subscriber_number],
|
87
|
-
data: {
|
88
|
-
to: xml_params[:subscriber_number],
|
89
|
-
text: xml_params[:message],
|
90
|
-
from: ENV["SMESS_MBLOX_SURE_ROUTE_SHORTCODE"]
|
91
|
-
}
|
92
|
-
}
|
93
|
-
end
|
94
|
-
result
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def xml_data_for(xml_params)
|
99
|
-
Gyoku.convert_symbols_to :camelcase
|
100
|
-
'<?xml version="1.0"?>'+
|
101
|
-
Gyoku.xml( hash_data_for(xml_params) )
|
25
|
+
results.first
|
102
26
|
end
|
103
27
|
|
104
28
|
def hash_data_for(xml_params)
|
@@ -116,7 +40,7 @@ module Smess
|
|
116
40
|
message: xml_params[:message],
|
117
41
|
profile: ENV["SMESS_MBLOX_SURE_ROUTE_PROFILE_ID"],
|
118
42
|
udh: xml_params.fetch(:udh,""),
|
119
|
-
sender_i_d:
|
43
|
+
sender_i_d: from,
|
120
44
|
# expire_date: "",
|
121
45
|
# operator: "",
|
122
46
|
# tariff: "",
|
@@ -140,6 +64,72 @@ module Smess
|
|
140
64
|
xml_hash
|
141
65
|
end
|
142
66
|
|
67
|
+
private
|
68
|
+
|
69
|
+
attr_reader :sms
|
70
|
+
attr_accessor :results
|
71
|
+
|
72
|
+
def from
|
73
|
+
ENV["SMESS_MBLOX_SURE_ROUTE_SHORTCODE"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def parts
|
77
|
+
@parts ||= split_parts
|
78
|
+
end
|
79
|
+
|
80
|
+
def split_parts
|
81
|
+
Smess.split_sms(sms.message.strip_nongsm_chars).reject {|s| s.empty? }
|
82
|
+
end
|
83
|
+
|
84
|
+
def send_one_sms(xml_params)
|
85
|
+
request.url = 'https://xml4.us.mblox.com:443/send'
|
86
|
+
request.headers["Content-Type"] = "application/x-www-form-urlencoded"
|
87
|
+
request.body = http_body(xml_params)
|
88
|
+
|
89
|
+
begin
|
90
|
+
HTTPI.log_level = :debug
|
91
|
+
response = HTTPI.post request
|
92
|
+
result = normal_result(response)
|
93
|
+
rescue Exception => e
|
94
|
+
logger.warn response
|
95
|
+
# connection problem or some error
|
96
|
+
result = result_for_error(e)
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
def http_body(xml_params)
|
102
|
+
xml = xml_data_for(xml_params)
|
103
|
+
"XMLDATA="+URI::encode( xml.encode("ISO-8859-1") )
|
104
|
+
end
|
105
|
+
|
106
|
+
def xml_data_for(xml_params)
|
107
|
+
Gyoku.convert_symbols_to :camelcase
|
108
|
+
'<?xml version="1.0"?>'+
|
109
|
+
Gyoku.xml( hash_data_for(xml_params) )
|
110
|
+
end
|
111
|
+
|
112
|
+
def concatenation_udh(num, total)
|
113
|
+
"050003#{ref_id}#{total.to_s(16).rjust(2,'0')}#{(num).to_s(16).rjust(2,'0')}".scan(/../).join(':').prepend(':')
|
114
|
+
end
|
115
|
+
|
116
|
+
def ref_id
|
117
|
+
@ref_id ||= Random.new.rand(255).to_s(16).rjust(2,"0")
|
118
|
+
end
|
119
|
+
|
120
|
+
def normal_result(response)
|
121
|
+
response_data = Nori.parse(response.body)
|
122
|
+
response_code = response_code_for response_data
|
123
|
+
# Successful response
|
124
|
+
result = {
|
125
|
+
message_id: @message_id,
|
126
|
+
response_code: response_code,
|
127
|
+
response: response_data,
|
128
|
+
destination_address: sms.to,
|
129
|
+
data: result_data
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
143
133
|
def response_code_for(response_data)
|
144
134
|
request_result_code = response_data[:notification_request_result][:notification_result_header][:request_result_code] rescue "-1"
|
145
135
|
return "request:#{request_result_code}" unless request_result_code == "0"
|
@@ -151,5 +141,29 @@ module Smess
|
|
151
141
|
(subscriber_result_code == "0") ? subscriber_result_code : "subscriber:#{subscriber_result_code}"
|
152
142
|
end
|
153
143
|
|
144
|
+
def request
|
145
|
+
@request ||= HTTPI::Request.new
|
146
|
+
end
|
147
|
+
|
148
|
+
def result_for_error(e)
|
149
|
+
{
|
150
|
+
response_code: '-1',
|
151
|
+
response: {
|
152
|
+
temporaryError: 'true',
|
153
|
+
responseCode: '-1',
|
154
|
+
responseText: e.message
|
155
|
+
},
|
156
|
+
data: result_data
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
def result_data
|
161
|
+
{
|
162
|
+
to: sms.to,
|
163
|
+
text: sms.message.strip_nongsm_chars,
|
164
|
+
from: from
|
165
|
+
}
|
166
|
+
end
|
167
|
+
|
154
168
|
end
|
155
169
|
end
|
@@ -2,22 +2,17 @@ require 'uri'
|
|
2
2
|
require 'httpi'
|
3
3
|
|
4
4
|
module Smess
|
5
|
-
class Smsglobal
|
6
|
-
include Smess::Logging
|
7
|
-
|
8
|
-
def deliver_sms(sms_arg)
|
9
|
-
return false unless sms_arg.kind_of? Sms
|
10
|
-
@sms = sms_arg
|
5
|
+
class Smsglobal < HttpBase
|
11
6
|
|
7
|
+
def deliver
|
12
8
|
request.url = url
|
13
9
|
request.body = params
|
14
10
|
|
15
11
|
begin
|
16
|
-
HTTPI.log_level = :debug
|
17
12
|
response = HTTPI.post request
|
18
13
|
result = normal_result(response)
|
19
14
|
rescue Exception => e
|
20
|
-
|
15
|
+
logger.warn response
|
21
16
|
# connection problem or some error
|
22
17
|
result = result_for_error(e)
|
23
18
|
end
|
@@ -26,21 +21,25 @@ module Smess
|
|
26
21
|
|
27
22
|
private
|
28
23
|
|
29
|
-
|
24
|
+
def username
|
25
|
+
ENV["SMESS_SMSGLOBAL_USER"]
|
26
|
+
end
|
27
|
+
def password
|
28
|
+
ENV["SMESS_SMSGLOBAL_PASS"]
|
29
|
+
end
|
30
|
+
def sender_id
|
31
|
+
ENV["SMESS_SMSGLOBAL_SENDER_ID"]
|
32
|
+
end
|
30
33
|
|
31
34
|
def url
|
32
35
|
"https://www.smsglobal.com/http-api.php"
|
33
36
|
end
|
34
37
|
|
35
|
-
def from
|
36
|
-
sms.originator || ENV["SMESS_SMSGLOBAL_SENDER_ID"]
|
37
|
-
end
|
38
|
-
|
39
38
|
def params
|
40
39
|
@params ||= {
|
41
40
|
action: "sendsms",
|
42
|
-
user:
|
43
|
-
password:
|
41
|
+
user: username,
|
42
|
+
password: password,
|
44
43
|
from: from,
|
45
44
|
to: sms.to,
|
46
45
|
text: sms.message.strip_nongsm_chars,
|
@@ -48,23 +47,6 @@ module Smess
|
|
48
47
|
}
|
49
48
|
end
|
50
49
|
|
51
|
-
def request
|
52
|
-
@request ||= HTTPI::Request.new
|
53
|
-
end
|
54
|
-
|
55
|
-
def result_for_error(e)
|
56
|
-
code = e.code rescue "-1"
|
57
|
-
{
|
58
|
-
response_code: '-1',
|
59
|
-
response: {
|
60
|
-
temporaryError: 'true',
|
61
|
-
responseCode: e.code,
|
62
|
-
responseText: e.message
|
63
|
-
},
|
64
|
-
data: result_data
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
50
|
def normal_result(response)
|
69
51
|
first_response = response.body.split(/\r\n/).first.split(";")
|
70
52
|
response_code = first_response.first.split(':').last.to_i
|
@@ -79,13 +61,5 @@ module Smess
|
|
79
61
|
}
|
80
62
|
end
|
81
63
|
|
82
|
-
def result_data
|
83
|
-
{
|
84
|
-
to: sms.to,
|
85
|
-
text: sms.message.strip_nongsm_chars,
|
86
|
-
from: from
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
64
|
end
|
91
65
|
end
|
data/lib/smess/outputs/test.rb
CHANGED
@@ -11,9 +11,10 @@ module Smess
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
class << self; attr_accessor :delivery_result end
|
14
|
-
attr_reader :sms
|
14
|
+
attr_reader :sms
|
15
15
|
|
16
|
-
def initialize
|
16
|
+
def initialize(sms)
|
17
|
+
@sms = sms
|
17
18
|
@@instance = self
|
18
19
|
end
|
19
20
|
|
@@ -21,9 +22,7 @@ module Smess
|
|
21
22
|
@@instance
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
return false unless sms.kind_of? Sms
|
26
|
-
@sms = sms
|
25
|
+
def deliver
|
27
26
|
self.class.delivery_result
|
28
27
|
end
|
29
28
|
|
data/lib/smess/outputs/twilio.rb
CHANGED
@@ -4,9 +4,13 @@ module Smess
|
|
4
4
|
class Twilio
|
5
5
|
include Smess::Logging
|
6
6
|
|
7
|
-
|
8
|
-
return false unless sms.kind_of? Sms
|
7
|
+
attr_reader :sms
|
9
8
|
|
9
|
+
def initialize(sms)
|
10
|
+
@sms = sms
|
11
|
+
end
|
12
|
+
|
13
|
+
def deliver
|
10
14
|
parts = Smess.separate_sms sms.message.strip_nongsm_chars
|
11
15
|
return false if parts[0].empty?
|
12
16
|
|
data/lib/smess/sms.rb
CHANGED
@@ -13,8 +13,8 @@ module Smess
|
|
13
13
|
|
14
14
|
def deliver
|
15
15
|
out_class = output
|
16
|
-
out = ("Smess::#{out_class.to_s.camelize}").constantize.new
|
17
|
-
results = out.
|
16
|
+
out = ("Smess::#{out_class.to_s.camelize}").constantize.new(self)
|
17
|
+
results = out.deliver
|
18
18
|
end
|
19
19
|
|
20
20
|
def delivered?
|
data/lib/smess/utils.rb
CHANGED
data/lib/smess/version.rb
CHANGED
data/lib/string.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Westin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- lib/smess/outputs/clickatell.rb
|
149
149
|
- lib/smess/outputs/etisalatdemo.rb
|
150
150
|
- lib/smess/outputs/global_mouth.rb
|
151
|
+
- lib/smess/outputs/http_base.rb
|
151
152
|
- lib/smess/outputs/iconectiv.rb
|
152
153
|
- lib/smess/outputs/ipx.rb
|
153
154
|
- lib/smess/outputs/ipxus.rb
|