smess 1.0.10 → 2.0
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 +1 -1
- data/Gemfile.lock +15 -12
- data/README.md +24 -5
- data/lib/smess.rb +61 -20
- data/lib/smess/output.rb +23 -0
- data/lib/smess/outputs/auto.rb +15 -16
- data/lib/smess/outputs/card_board_fish.rb +5 -11
- data/lib/smess/outputs/clickatell.rb +14 -9
- data/lib/smess/outputs/global_mouth.rb +8 -9
- data/lib/smess/outputs/http_base.rb +8 -7
- data/lib/smess/outputs/iconectiv.rb +0 -4
- data/lib/smess/outputs/ipx.rb +12 -43
- data/lib/smess/outputs/mblox.rb +18 -8
- data/lib/smess/outputs/smsglobal.rb +7 -10
- data/lib/smess/outputs/test.rb +6 -4
- data/lib/smess/outputs/twilio.rb +23 -19
- data/lib/smess/sms.rb +4 -4
- data/lib/smess/version.rb +1 -1
- data/lib/{string.rb → string_ext.rb} +0 -0
- metadata +28 -29
- data/lib/smess/country_code_registry.rb +0 -36
- data/lib/smess/outputs/etisalatdemo.rb +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1da1bd648e95236f325b5c70c5bc274ab92944b
|
4
|
+
data.tar.gz: 16069db6c4ce54709459b595cda9dee7d0e49341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce971172a2b5b55238d41ea7c2be8281b1e9b5e247caf30b8257f275e769724042627339b5eb5fa269598f9033af5f39bd9cfd17aca4617c96ab12431c8686f1
|
7
|
+
data.tar.gz: 8a5a83d00200e89236edbba2d62475f2d43049d96749adc3beda74d17864bccfd6b2d2d7bdd3d0d302bd6a8149b05a65a5276ddfb4d508065ebcb9c0e4c20778
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smess (
|
4
|
+
smess (2.0)
|
5
5
|
activesupport (>= 3.0)
|
6
6
|
clickatell
|
7
7
|
httpi
|
@@ -10,9 +10,9 @@ PATH
|
|
10
10
|
twilio-ruby
|
11
11
|
|
12
12
|
GEM
|
13
|
-
remote:
|
13
|
+
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (4.2.
|
15
|
+
activesupport (4.2.5)
|
16
16
|
i18n (~> 0.7)
|
17
17
|
json (~> 1.7, >= 1.7.7)
|
18
18
|
minitest (~> 5.1)
|
@@ -30,18 +30,18 @@ GEM
|
|
30
30
|
httpi (1.1.1)
|
31
31
|
rack
|
32
32
|
i18n (0.7.0)
|
33
|
-
json (1.8.
|
34
|
-
jwt (1.5.
|
33
|
+
json (1.8.3)
|
34
|
+
jwt (1.5.2)
|
35
35
|
mail (2.6.3)
|
36
36
|
mime-types (>= 1.16, < 3)
|
37
|
-
mime-types (2.
|
38
|
-
|
39
|
-
minitest (5.
|
37
|
+
mime-types (2.99)
|
38
|
+
mini_portile2 (2.0.0)
|
39
|
+
minitest (5.8.3)
|
40
40
|
multi_json (1.8.2)
|
41
|
-
nokogiri (1.6.
|
42
|
-
|
41
|
+
nokogiri (1.6.7.1)
|
42
|
+
mini_portile2 (~> 2.0.0.rc2)
|
43
43
|
nori (1.1.5)
|
44
|
-
rack (1.6.
|
44
|
+
rack (1.6.4)
|
45
45
|
rspec (2.14.1)
|
46
46
|
rspec-core (~> 2.14.0)
|
47
47
|
rspec-expectations (~> 2.14.0)
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
simplecov-html (~> 0.7.1)
|
64
64
|
simplecov-html (0.7.1)
|
65
65
|
thread_safe (0.3.5)
|
66
|
-
twilio-ruby (4.
|
66
|
+
twilio-ruby (4.9.0)
|
67
67
|
builder (>= 2.1.2)
|
68
68
|
jwt (~> 1.0)
|
69
69
|
multi_json (>= 1.3.0)
|
@@ -81,3 +81,6 @@ DEPENDENCIES
|
|
81
81
|
rspec (>= 2.4.0)
|
82
82
|
simplecov
|
83
83
|
smess!
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.10.3
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ module Smess
|
|
48
48
|
def deliver
|
49
49
|
# Do work and return a hash like this one
|
50
50
|
{
|
51
|
-
|
51
|
+
:response_code => '-1',
|
52
52
|
:response => {
|
53
53
|
:temporaryError =>'true',
|
54
54
|
:responseCode => '-1',
|
@@ -75,10 +75,29 @@ or
|
|
75
75
|
gem install smess
|
76
76
|
```
|
77
77
|
|
78
|
-
###
|
79
|
-
|
78
|
+
### Configure the SMS providers you use
|
79
|
+
Smess is very configurable and there is a fair amout of things to setup. Smess chooses SMS provider based on the recipient phone number and is meant to abstract away the differences betweenn providers. You have to provide the account information and "configure" each provider you actually use. THe repository contains an example_config.rb file which should be a fairly up-to date config of how I personally have providers mapped to different countries based on delivery success rates.
|
80
|
+
|
81
|
+
A pretty minimal setup would look something like this:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
Smess.configure do |config|
|
85
|
+
|
86
|
+
config.default_sender_id = ENV["SMESS_SENDER_ID"]
|
87
|
+
config.default_output = :my_default
|
88
|
+
config.register_output({
|
89
|
+
name: :my_default,
|
90
|
+
country_codes: ["1", "46"],
|
91
|
+
type: :global_mouth,
|
92
|
+
config: {
|
93
|
+
username: ENV["SMESS_GLOBAL_MOUTH_USER"],
|
94
|
+
password: ENV["SMESS_GLOBAL_MOUTH_PASS"],
|
95
|
+
sender_id: ENV["SMESS_GLOBAL_MOUTH_SENDER_ID"]
|
96
|
+
}
|
97
|
+
})
|
98
|
+
end
|
99
|
+
```
|
80
100
|
|
81
|
-
All ENV variables used by Smess are listed in the file .env. You only need to define the aggregator credentials you actually use though.
|
82
101
|
|
83
102
|
## Usage
|
84
103
|
|
@@ -87,7 +106,7 @@ sms = Smess.new(
|
|
87
106
|
to: '46701234567', # phone number in normalized msisdn format
|
88
107
|
message: 'Test SMS', # Message text
|
89
108
|
originator: 'TestSuite', # originator, sender id. This has many names. Outside the US this can usually be set to whatever you like.
|
90
|
-
output: "test" #
|
109
|
+
output: "test" # Optional name of the output plugin to use. Defaults to auto select.
|
91
110
|
)
|
92
111
|
results = sms.deliver
|
93
112
|
puts result
|
data/lib/smess.rb
CHANGED
@@ -9,7 +9,7 @@ require 'active_support/core_ext'
|
|
9
9
|
|
10
10
|
require "smess/version"
|
11
11
|
require 'smess/logging'
|
12
|
-
require 'smess/
|
12
|
+
require 'smess/output'
|
13
13
|
require 'smess/utils'
|
14
14
|
require 'smess/sms'
|
15
15
|
require 'smess/outputs/http_base'
|
@@ -18,7 +18,6 @@ require 'smess/outputs/ipx'
|
|
18
18
|
require 'smess/outputs/ipxus'
|
19
19
|
require 'smess/outputs/card_board_fish'
|
20
20
|
require 'smess/outputs/clickatell'
|
21
|
-
require 'smess/outputs/etisalatdemo'
|
22
21
|
require 'smess/outputs/smsglobal'
|
23
22
|
require 'smess/outputs/global_mouth'
|
24
23
|
require 'smess/outputs/mblox'
|
@@ -26,41 +25,83 @@ require 'smess/outputs/twilio'
|
|
26
25
|
require 'smess/outputs/iconectiv'
|
27
26
|
require 'smess/outputs/test'
|
28
27
|
|
29
|
-
require '
|
28
|
+
require 'string_ext'
|
30
29
|
|
31
30
|
module Smess
|
32
31
|
|
33
|
-
# Move to config?
|
34
|
-
OUTPUTS = %w{auto card_board_fish clickatell etisalatdemo global_mouth iconectiv mblox ipxus smsglobal twilio}
|
35
|
-
COUNTRY_CODES = [1, 20, 212, 33, 34, 44, 46, 49, 966, 971]
|
36
|
-
|
37
32
|
def self.new(*args)
|
38
33
|
Sms.new(*args)
|
39
34
|
end
|
40
35
|
|
36
|
+
def self.named_output_instance(name)
|
37
|
+
output_class_name = config.configured_outputs.fetch(name)[:type].to_s.camelize
|
38
|
+
conf = config.configured_outputs[name][:config]
|
39
|
+
"Smess::#{output_class_name}".constantize.new(conf)
|
40
|
+
end
|
41
|
+
|
41
42
|
def self.config
|
42
|
-
@config ||=Config.new
|
43
|
+
@config ||= Config.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.reset_config
|
47
|
+
@config = Config.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.configure
|
51
|
+
yield(config)
|
43
52
|
end
|
44
53
|
|
45
54
|
class Config
|
55
|
+
attr_accessor :nothing, :default_output, :default_sender_id, :default_sender_id, :output_types, :configured_outputs, :output_by_country_code
|
56
|
+
|
46
57
|
def initialize
|
47
|
-
@
|
58
|
+
@nothing = false
|
59
|
+
@default_output = nil
|
60
|
+
@default_sender_id = "Smess"
|
61
|
+
@output_types = %i{auto card_board_fish clickatell global_mouth iconectiv mblox smsglobal twilio}
|
62
|
+
@configured_outputs = {test: {type: :test, config: nil}}
|
63
|
+
@output_by_country_code = {}
|
64
|
+
|
65
|
+
register_output({
|
66
|
+
name: :auto,
|
67
|
+
country_codes: [],
|
68
|
+
type: :auto,
|
69
|
+
config: {}
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
def add_country_code(cc, output=default_output)
|
74
|
+
raise ArgumentError.new("Invalid country code") unless cc.to_i.to_s == cc.to_s
|
75
|
+
raise ArgumentError.new("Unknown output specified") unless outputs.include? output.to_sym
|
76
|
+
output_by_country_code[cc.to_s] = output.to_sym
|
77
|
+
true
|
48
78
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
79
|
+
|
80
|
+
def register_output(options)
|
81
|
+
name = options.fetch(:name).to_sym
|
82
|
+
type = options.fetch(:type).to_sym
|
83
|
+
countries = options.fetch(:country_codes)
|
84
|
+
config = options.fetch(:config)
|
85
|
+
|
86
|
+
raise ArgumentError.new("Duplicate output name") if outputs.include? name
|
87
|
+
raise ArgumentError.new("Unknown output type specified") unless output_types.include? type
|
88
|
+
|
89
|
+
configured_outputs[name] = {type: type, config: config}
|
90
|
+
countries.each do |cc|
|
91
|
+
add_country_code(cc, name)
|
53
92
|
end
|
54
|
-
@config[method]
|
55
93
|
end
|
56
|
-
end
|
57
94
|
|
95
|
+
def outputs
|
96
|
+
configured_outputs.keys
|
97
|
+
end
|
98
|
+
|
99
|
+
def country_codes
|
100
|
+
output_by_country_code.keys
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
58
104
|
end
|
59
105
|
|
60
106
|
# httpclient does not send basic auth correctly, or at all.
|
61
107
|
HTTPI.adapter = :net_http
|
62
|
-
|
63
|
-
# Setting config defaults
|
64
|
-
# there is probably a better way and better place
|
65
|
-
# Unused and deprecated
|
66
|
-
Smess.config.debug = Smess.booleanize(ENV["SMESS_DEBUG"])
|
data/lib/smess/output.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Smess
|
2
|
+
class Output
|
3
|
+
|
4
|
+
attr_accessor :sms
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
validate_config
|
10
|
+
end
|
11
|
+
|
12
|
+
# should be used to make a reasonable validation that the configuration provided is good.
|
13
|
+
def validate_config
|
14
|
+
raise NotImplementedError.new("You must define validate_config in your Smess output class")
|
15
|
+
end
|
16
|
+
|
17
|
+
# entry point to the sms delivery process.
|
18
|
+
def deliver
|
19
|
+
raise NotImplementedError.new("You must define deliver in your Smess output class")
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/smess/outputs/auto.rb
CHANGED
@@ -1,30 +1,29 @@
|
|
1
1
|
module Smess
|
2
|
-
class Auto
|
2
|
+
class Auto < Output
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
attr_accessor :output_name
|
5
|
+
|
6
|
+
def validate_config
|
7
|
+
end
|
8
|
+
|
9
|
+
def deliver
|
10
|
+
out = output_for sms.to
|
11
|
+
out.deliver.merge({sent_with: output_name})
|
6
12
|
end
|
7
13
|
|
8
14
|
def get_output_name_for_msisdn(msisdn)
|
9
15
|
3.downto(0).each do |index|
|
10
|
-
return
|
16
|
+
return Smess.config.output_by_country_code[msisdn[0..index]] if Smess.config.output_by_country_code.key? msisdn[0..index]
|
11
17
|
end
|
12
|
-
|
18
|
+
Smess.config.default_output
|
13
19
|
end
|
14
20
|
|
15
21
|
def output_for(msisdn)
|
16
|
-
|
17
|
-
|
22
|
+
output_name = get_output_name_for_msisdn(msisdn)
|
23
|
+
output = Smess.named_output_instance( output_name )
|
24
|
+
output.sms = sms
|
25
|
+
output
|
18
26
|
end
|
19
27
|
|
20
|
-
def deliver
|
21
|
-
out = output_for sms.to
|
22
|
-
out.deliver
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
attr_reader :sms
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
@@ -6,19 +6,13 @@ module Smess
|
|
6
6
|
http_get request
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def password
|
16
|
-
ENV["SMESS_CARD_BOARD_FISH_PASS"]
|
9
|
+
attr_accessor :username, :password
|
10
|
+
def validate_config
|
11
|
+
@username = config.fetch(:username)
|
12
|
+
@password = config.fetch(:password)
|
17
13
|
end
|
18
14
|
|
19
|
-
|
20
|
-
ENV["SMESS_SENDER_ID"]
|
21
|
-
end
|
15
|
+
private
|
22
16
|
|
23
17
|
def url
|
24
18
|
"https://sms2.cardboardfish.com:9444/HTTPSMS"
|
@@ -23,11 +23,11 @@ end
|
|
23
23
|
|
24
24
|
|
25
25
|
module Smess
|
26
|
-
class Clickatell
|
26
|
+
class Clickatell < Output
|
27
27
|
include Smess::Logging
|
28
28
|
|
29
|
-
def initialize(
|
30
|
-
|
29
|
+
def initialize(config)
|
30
|
+
super
|
31
31
|
::Clickatell::API.debug_mode = true
|
32
32
|
::Clickatell::API.secure_mode = true
|
33
33
|
end
|
@@ -47,13 +47,22 @@ module Smess
|
|
47
47
|
result
|
48
48
|
end
|
49
49
|
|
50
|
+
attr_accessor :api_id, :user, :pass, :sender_id, :sender_ids
|
51
|
+
def validate_config
|
52
|
+
@api_id = config.fetch(:api_id)
|
53
|
+
@user = config.fetch(:user)
|
54
|
+
@pass = config.fetch(:pass)
|
55
|
+
@sender_id = config.fetch(:sender_id)
|
56
|
+
@sender_ids = config.fetch(:sender_ids)
|
57
|
+
end
|
58
|
+
|
50
59
|
private
|
51
60
|
|
52
61
|
attr_reader :sms
|
53
62
|
|
54
63
|
def from
|
55
64
|
return nil if sender_not_supported
|
56
|
-
|
65
|
+
sender_ids.split(",").include?(sms.originator) ? sms.originator : sender_id
|
57
66
|
end
|
58
67
|
|
59
68
|
def messages
|
@@ -74,11 +83,7 @@ module Smess
|
|
74
83
|
end
|
75
84
|
|
76
85
|
def api
|
77
|
-
@api ||= ::Clickatell::API.authenticate(
|
78
|
-
ENV["SMESS_CLICKATELL_API_ID"],
|
79
|
-
ENV["SMESS_CLICKATELL_USER"],
|
80
|
-
ENV["SMESS_CLICKATELL_PASS"]
|
81
|
-
)
|
86
|
+
@api ||= ::Clickatell::API.authenticate(api_id, user, pass)
|
82
87
|
end
|
83
88
|
|
84
89
|
def normal_result(response)
|
@@ -10,18 +10,17 @@ module Smess
|
|
10
10
|
http_get request
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
attr_accessor :username, :password, :sender_id
|
14
|
+
def validate_config
|
15
|
+
@username = config.fetch(:username)
|
16
|
+
@password = config.fetch(:password)
|
17
|
+
@sender_id = config.fetch(:sender_id)
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
ENV["SMESS_GLOBAL_MOUTH_PASS"]
|
21
|
-
end
|
20
|
+
private
|
22
21
|
|
23
|
-
def
|
24
|
-
|
22
|
+
def username
|
23
|
+
@username.dup # paranoid safeguard
|
25
24
|
end
|
26
25
|
|
27
26
|
def url
|
@@ -2,22 +2,23 @@ require 'uri'
|
|
2
2
|
require 'httpi'
|
3
3
|
|
4
4
|
module Smess
|
5
|
-
class HttpBase
|
5
|
+
class HttpBase < Output
|
6
6
|
include Smess::Logging
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(config)
|
9
|
+
super
|
10
10
|
HTTPI.log_level = :debug
|
11
11
|
end
|
12
12
|
|
13
|
-
private
|
14
|
-
|
15
|
-
attr_reader :sms
|
16
13
|
|
17
14
|
def sender_id
|
18
|
-
|
15
|
+
@sender_id || Smess.config.default_sender_id
|
19
16
|
end
|
20
17
|
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :sms
|
21
|
+
|
21
22
|
def from
|
22
23
|
sms.originator || sender_id
|
23
24
|
end
|
@@ -3,10 +3,6 @@ module Smess
|
|
3
3
|
|
4
4
|
private
|
5
5
|
|
6
|
-
def account_key_prefix
|
7
|
-
"ICONECTIV"
|
8
|
-
end
|
9
|
-
|
10
6
|
# iConectiv asserts that this is all that is still reqquired and that it wont break other carriers.
|
11
7
|
# test of major carriers confirm this too... let's see how the small ones do.
|
12
8
|
def perform_operator_adaptation(msisdn)
|
data/lib/smess/outputs/ipx.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
module Smess
|
2
|
-
class Ipx
|
2
|
+
class Ipx < Output
|
3
3
|
include Smess::Logging
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
attr_accessor :sms_url, :username, :password, :shortcode, :account_name, :service_name, :service_meta_data_verizon, :service_meta_data_t_mobile_us
|
6
|
+
def validate_config
|
7
|
+
@sms_url = config.fetch(:sms_url)
|
8
|
+
@username = config.fetch(:username)
|
9
|
+
@password = config.fetch(:password)
|
10
|
+
@shortcode = config.fetch(:shortcode)
|
11
|
+
@account_name = config.fetch(:account_name)
|
12
|
+
@service_name = config.fetch(:service_name)
|
13
|
+
@service_meta_data_verizon = config.fetch(:service_meta_data_verizon, "")
|
14
|
+
@service_meta_data_t_mobile_us = config.fetch(:service_meta_data_t_mobile_us, "")
|
15
|
+
|
7
16
|
@results = []
|
8
17
|
@endpoint = sms_url
|
9
18
|
@credentials = {
|
@@ -36,46 +45,6 @@ module Smess
|
|
36
45
|
attr_reader :sms
|
37
46
|
attr_accessor :results
|
38
47
|
|
39
|
-
def account_key_prefix
|
40
|
-
"IPX"
|
41
|
-
end
|
42
|
-
|
43
|
-
def account_key_for(key_part)
|
44
|
-
"SMESS_#{account_key_prefix}_#{key_part}"
|
45
|
-
end
|
46
|
-
|
47
|
-
def sms_url
|
48
|
-
ENV[ account_key_for("URL") ]
|
49
|
-
end
|
50
|
-
|
51
|
-
def shortcode
|
52
|
-
ENV[ account_key_for("SHORTCODE") ]
|
53
|
-
end
|
54
|
-
|
55
|
-
def username
|
56
|
-
ENV[ account_key_for("USER") ]
|
57
|
-
end
|
58
|
-
|
59
|
-
def password
|
60
|
-
ENV[ account_key_for("PASS") ]
|
61
|
-
end
|
62
|
-
|
63
|
-
def account_name
|
64
|
-
ENV[ account_key_for("ACCOUNT_NAME") ]
|
65
|
-
end
|
66
|
-
|
67
|
-
def service_name
|
68
|
-
ENV["SMESS_SERVICE_NAME"]
|
69
|
-
end
|
70
|
-
|
71
|
-
def service_meta_data_t_mobile_us
|
72
|
-
ENV[ account_key_for("SERVICE_META_DATA_T_MOBILE_US") ]
|
73
|
-
end
|
74
|
-
|
75
|
-
def service_meta_data_verizon
|
76
|
-
ENV[ account_key_for("SERVICE_META_DATA_VERIZON") ]
|
77
|
-
end
|
78
|
-
|
79
48
|
def soap_body
|
80
49
|
@soap_body ||= {
|
81
50
|
"correlationId" => Time.now.strftime('%Y%m%d%H%M%S') + sms.to,
|
data/lib/smess/outputs/mblox.rb
CHANGED
@@ -2,11 +2,11 @@ require 'uri'
|
|
2
2
|
require 'httpi'
|
3
3
|
|
4
4
|
module Smess
|
5
|
-
class Mblox
|
5
|
+
class Mblox < Output
|
6
6
|
include Smess::Logging
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
|
8
|
+
def initialize(config)
|
9
|
+
super
|
10
10
|
@results = []
|
11
11
|
end
|
12
12
|
|
@@ -25,6 +25,16 @@ module Smess
|
|
25
25
|
results.first
|
26
26
|
end
|
27
27
|
|
28
|
+
attr_accessor :username, :password, :shortcode, :profile_id, :sid
|
29
|
+
def validate_config
|
30
|
+
@username = config.fetch(:username)
|
31
|
+
@password = config.fetch(:password)
|
32
|
+
@shortcode = config.fetch(:shortcode)
|
33
|
+
@profile_id = config.fetch(:profile_id)
|
34
|
+
@sid = config.fetch(:sid)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
28
38
|
def hash_data_for(xml_params)
|
29
39
|
rand = (SecureRandom.random_number*100000000).to_i
|
30
40
|
@message_id = rand
|
@@ -32,13 +42,13 @@ module Smess
|
|
32
42
|
xml_hash = {
|
33
43
|
notification_request: {
|
34
44
|
notification_header: {
|
35
|
-
partner_name:
|
36
|
-
partner_password:
|
45
|
+
partner_name: username,
|
46
|
+
partner_password: password
|
37
47
|
},
|
38
48
|
notification_list: {
|
39
49
|
notification: {
|
40
50
|
message: xml_params[:message],
|
41
|
-
profile:
|
51
|
+
profile: profile_id,
|
42
52
|
udh: xml_params.fetch(:udh,""),
|
43
53
|
sender_i_d: from,
|
44
54
|
# expire_date: "",
|
@@ -51,7 +61,7 @@ module Smess
|
|
51
61
|
# tags: '<Tag Name=”Number”>56</Tag><Tag Name=”City”>Paris</Tag>',
|
52
62
|
# service_desc: "",
|
53
63
|
# content_type: "",
|
54
|
-
service_id:
|
64
|
+
service_id: sid,
|
55
65
|
attributes!: { sender_i_d: { "Type" => "Shortcode" } }
|
56
66
|
},
|
57
67
|
attributes!: { notification: { "SequenceNumber" => "1", "MessageType" => "SMS" } } # FlashSMS
|
@@ -70,7 +80,7 @@ module Smess
|
|
70
80
|
attr_accessor :results
|
71
81
|
|
72
82
|
def from
|
73
|
-
|
83
|
+
shortcode
|
74
84
|
end
|
75
85
|
|
76
86
|
def parts
|
@@ -11,18 +11,15 @@ module Smess
|
|
11
11
|
http_post request
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def password
|
20
|
-
ENV["SMESS_SMSGLOBAL_PASS"]
|
21
|
-
end
|
22
|
-
def sender_id
|
23
|
-
ENV["SMESS_SMSGLOBAL_SENDER_ID"]
|
14
|
+
attr_accessor :username, :password, :sender_id
|
15
|
+
def validate_config
|
16
|
+
@username = config.fetch(:username)
|
17
|
+
@password = config.fetch(:password)
|
18
|
+
@sender_id = config.fetch(:sender_id, Smess.config.default_sender_id)
|
24
19
|
end
|
25
20
|
|
21
|
+
private
|
22
|
+
|
26
23
|
def url
|
27
24
|
"https://www.smsglobal.com/http-api.php"
|
28
25
|
end
|
data/lib/smess/outputs/test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Smess
|
2
|
-
class Test
|
2
|
+
class Test < Output
|
3
3
|
|
4
4
|
@@instance = nil
|
5
5
|
@delivery_result = {
|
@@ -11,10 +11,9 @@ module Smess
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
class << self; attr_accessor :delivery_result end
|
14
|
-
attr_reader :sms
|
15
14
|
|
16
|
-
def initialize(
|
17
|
-
|
15
|
+
def initialize(config)
|
16
|
+
super
|
18
17
|
@@instance = self
|
19
18
|
end
|
20
19
|
|
@@ -22,6 +21,9 @@ module Smess
|
|
22
21
|
@@instance
|
23
22
|
end
|
24
23
|
|
24
|
+
def validate_config
|
25
|
+
end
|
26
|
+
|
25
27
|
def deliver
|
26
28
|
self.class.delivery_result
|
27
29
|
end
|
data/lib/smess/outputs/twilio.rb
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
require 'twilio-ruby'
|
2
2
|
|
3
3
|
module Smess
|
4
|
-
class Twilio
|
4
|
+
class Twilio < Output
|
5
5
|
include Smess::Logging
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
|
7
|
+
def initialize(config)
|
8
|
+
super
|
9
9
|
@results = []
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
attr_accessor :sid, :auth_token, :from, :messaging_service_sid, :callback_url
|
13
|
+
def validate_config
|
14
|
+
@sid = config.fetch(:sid)
|
15
|
+
@auth_token = config.fetch(:auth_token)
|
16
|
+
@from = config.fetch(:from, nil)
|
17
|
+
@messaging_service_sid = config.fetch(:messaging_service_sid, nil)
|
18
|
+
@callback_url = config.fetch(:callback_url)
|
19
|
+
end
|
16
20
|
|
17
|
-
|
18
|
-
|
21
|
+
def deliver
|
22
|
+
send_one_sms sms.message.strip_nongsm_chars
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
22
26
|
|
23
|
-
attr_reader :sms
|
24
27
|
attr_accessor :results
|
25
28
|
|
26
|
-
def from
|
27
|
-
ENV["SMESS_TWILIO_FROM"]
|
28
|
-
end
|
29
|
-
|
30
29
|
def parts
|
31
30
|
@parts ||= split_parts
|
32
31
|
end
|
@@ -37,12 +36,17 @@ module Smess
|
|
37
36
|
|
38
37
|
def send_one_sms(message)
|
39
38
|
begin
|
40
|
-
|
41
|
-
from: from,
|
39
|
+
opts = {
|
42
40
|
to: "+#{sms.to}",
|
43
41
|
body: message,
|
44
|
-
status_callback:
|
45
|
-
}
|
42
|
+
status_callback: callback_url
|
43
|
+
}
|
44
|
+
if messaging_service_sid.present?
|
45
|
+
opts[:messaging_service_sid] = messaging_service_sid
|
46
|
+
else
|
47
|
+
opts[:from] = from
|
48
|
+
end
|
49
|
+
response = create_client_message(opts)
|
46
50
|
result = normal_result(response)
|
47
51
|
rescue => e
|
48
52
|
result = result_for_error(e)
|
@@ -55,7 +59,7 @@ module Smess
|
|
55
59
|
end
|
56
60
|
|
57
61
|
def client
|
58
|
-
@client ||= ::Twilio::REST::Client.new(
|
62
|
+
@client ||= ::Twilio::REST::Client.new(sid, auth_token)
|
59
63
|
end
|
60
64
|
|
61
65
|
def normal_result(response)
|
data/lib/smess/sms.rb
CHANGED
@@ -8,13 +8,13 @@ module Smess
|
|
8
8
|
@to = opts.fetch(:to, nil)
|
9
9
|
@message = opts.fetch(:message, "")
|
10
10
|
@originator = opts.fetch(:originator, nil)
|
11
|
-
@output = opts.fetch(:output,
|
11
|
+
@output = opts.fetch(:output, :auto).to_sym
|
12
12
|
end
|
13
13
|
|
14
14
|
def deliver
|
15
|
-
|
16
|
-
out =
|
17
|
-
results = out.deliver
|
15
|
+
out = Smess.named_output_instance(output)
|
16
|
+
out.sms = self
|
17
|
+
self.results = {sent_with: output}.merge(out.deliver)
|
18
18
|
end
|
19
19
|
|
20
20
|
def delivered?
|
data/lib/smess/version.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Westin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 2.4.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dotenv
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: mail
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -84,56 +84,56 @@ dependencies:
|
|
84
84
|
name: httpi
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: clickatell
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: twilio-ruby
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: activesupport
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '3.0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.0'
|
139
139
|
description: A mess of SMS messaging
|
@@ -142,12 +142,16 @@ executables: []
|
|
142
142
|
extensions: []
|
143
143
|
extra_rdoc_files: []
|
144
144
|
files:
|
145
|
-
-
|
145
|
+
- Gemfile
|
146
|
+
- Gemfile.lock
|
147
|
+
- LICENSE
|
148
|
+
- README.md
|
149
|
+
- lib/smess.rb
|
146
150
|
- lib/smess/logging.rb
|
151
|
+
- lib/smess/output.rb
|
147
152
|
- lib/smess/outputs/auto.rb
|
148
153
|
- lib/smess/outputs/card_board_fish.rb
|
149
154
|
- lib/smess/outputs/clickatell.rb
|
150
|
-
- lib/smess/outputs/etisalatdemo.rb
|
151
155
|
- lib/smess/outputs/global_mouth.rb
|
152
156
|
- lib/smess/outputs/http_base.rb
|
153
157
|
- lib/smess/outputs/iconectiv.rb
|
@@ -160,12 +164,7 @@ files:
|
|
160
164
|
- lib/smess/sms.rb
|
161
165
|
- lib/smess/utils.rb
|
162
166
|
- lib/smess/version.rb
|
163
|
-
- lib/
|
164
|
-
- lib/string.rb
|
165
|
-
- Gemfile
|
166
|
-
- Gemfile.lock
|
167
|
-
- LICENSE
|
168
|
-
- README.md
|
167
|
+
- lib/string_ext.rb
|
169
168
|
homepage: https://github.com/eimermusic/smess
|
170
169
|
licenses:
|
171
170
|
- MIT
|
@@ -176,17 +175,17 @@ require_paths:
|
|
176
175
|
- lib
|
177
176
|
required_ruby_version: !ruby/object:Gem::Requirement
|
178
177
|
requirements:
|
179
|
-
- -
|
178
|
+
- - ">="
|
180
179
|
- !ruby/object:Gem::Version
|
181
180
|
version: 1.9.2
|
182
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
182
|
requirements:
|
184
|
-
- -
|
183
|
+
- - ">="
|
185
184
|
- !ruby/object:Gem::Version
|
186
185
|
version: 1.3.7
|
187
186
|
requirements: []
|
188
187
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
188
|
+
rubygems_version: 2.2.2
|
190
189
|
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: A messy SMS messenger supporting every aggregator I have gotten my hands
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Smess
|
2
|
-
OUTPUT_BY_COUNTRY_CODE = {
|
3
|
-
"0" => :global_mouth, # default for any undefined code
|
4
|
-
"1" => :iconectiv, # USA
|
5
|
-
"1242"=> :global_mouth, # Bahamas
|
6
|
-
"1246"=> :global_mouth, # Barbados
|
7
|
-
"1264"=> :global_mouth, # Anguilla
|
8
|
-
"1268"=> :global_mouth, # Antigua and Barbuda
|
9
|
-
"1284"=> :global_mouth, # British Virgin Islands
|
10
|
-
"1345"=> :global_mouth, # Cayman Islands
|
11
|
-
"1441"=> :clickatell, # Bermuda
|
12
|
-
"1473"=> :global_mouth, # Grenada
|
13
|
-
"1649"=> :global_mouth, # Turks and Caicos Islands
|
14
|
-
"1664"=> :global_mouth, # Montserrat
|
15
|
-
"1670"=> :global_mouth, # Northern Mariana Islands
|
16
|
-
"1671"=> :global_mouth, # Guam
|
17
|
-
"1684"=> :global_mouth, # American Samoa
|
18
|
-
"1758"=> :global_mouth, # Saint Lucia
|
19
|
-
"1767"=> :global_mouth, # Dominica
|
20
|
-
"1784"=> :global_mouth, # Saint Vincent and the Grenadines
|
21
|
-
"1787"=> :global_mouth, # Puerto Rico
|
22
|
-
"1809"=> :global_mouth, # Dominican Republic
|
23
|
-
"1868"=> :global_mouth, # Trinidad and Tobago
|
24
|
-
"1869"=> :global_mouth, # Saint Kitts and Nevis
|
25
|
-
"1876"=> :global_mouth, # Jamaica
|
26
|
-
"20" => :global_mouth, # Egypt
|
27
|
-
"212" => :card_board_fish, # Morocco
|
28
|
-
"33" => :global_mouth, # France
|
29
|
-
"34" => :global_mouth, # Spain
|
30
|
-
"44" => :global_mouth, # Great Britain
|
31
|
-
"46" => :global_mouth, # Sweden
|
32
|
-
"49" => :global_mouth, # Germany
|
33
|
-
"966" => :global_mouth, # Saudi Arabia
|
34
|
-
"971" => :etisalatdemo # United Arab Emirates
|
35
|
-
}
|
36
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
module Smess
|
2
|
-
class Etisalatdemo
|
3
|
-
include Smess::Logging
|
4
|
-
|
5
|
-
attr_reader :sms
|
6
|
-
|
7
|
-
def initialize(sms)
|
8
|
-
@sms = sms
|
9
|
-
@smtp_settings = {
|
10
|
-
address: "exmail.emirates.net.ae",
|
11
|
-
port: 25,
|
12
|
-
domain: 'eim.ae',
|
13
|
-
user_name: ENV["SMESS_ETISALATDEMO_USER"],
|
14
|
-
password: ENV["SMESS_ETISALATDEMO_PASS"],
|
15
|
-
authentication: 'plain',
|
16
|
-
enable_starttls_auto: false
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
def deliver
|
21
|
-
local_from_var = from_address
|
22
|
-
local_sms = sms
|
23
|
-
mail = Mail.new do
|
24
|
-
from local_from_var
|
25
|
-
to "+#{local_sms.to}@email2sms.ae"
|
26
|
-
subject "Smess Message"
|
27
|
-
body local_sms.message.strip_nongsm_chars
|
28
|
-
end
|
29
|
-
|
30
|
-
mail.delivery_method :smtp, @smtp_settings
|
31
|
-
|
32
|
-
begin
|
33
|
-
mail.deliver
|
34
|
-
rescue => e
|
35
|
-
result = {
|
36
|
-
response_code: "-1",
|
37
|
-
response: {text: "Email2sms: Delivery Error: #{e.inspect}"},
|
38
|
-
data: {
|
39
|
-
to: sms.to,
|
40
|
-
text: sms.message.strip_nongsm_chars,
|
41
|
-
from: from_address
|
42
|
-
}
|
43
|
-
}
|
44
|
-
else
|
45
|
-
result = {
|
46
|
-
response_code: "0",
|
47
|
-
response: {text: "Email2sms: Delivery Successful"},
|
48
|
-
data: {
|
49
|
-
to: sms.to,
|
50
|
-
text: sms.message.strip_nongsm_chars,
|
51
|
-
from: from_address
|
52
|
-
}
|
53
|
-
}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def from_address
|
58
|
-
"#{@smtp_settings[:user_name]}@#{@smtp_settings[:domain]}"
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|