sms_safe 1.0.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.
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "action_texter", "0.2.0", :git => "git://github.com/mstycom/action_texter.git"
6
+ gem "mail", "2.5.4"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,106 @@
1
+ GIT
2
+ remote: git://github.com/mstycom/action_texter.git
3
+ revision: 75dea6a6dffe3e69082f1e2b50403f0e6c567119
4
+ specs:
5
+ action_texter (0.2.0)
6
+
7
+ PATH
8
+ remote: ../
9
+ specs:
10
+ sms_safe (0.1.0)
11
+ mail (>= 2.4)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (4.2.0)
17
+ i18n (~> 0.7)
18
+ json (~> 1.7, >= 1.7.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.3, >= 0.3.4)
21
+ tzinfo (~> 1.1)
22
+ ansi (1.4.3)
23
+ appraisal (1.0.2)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ builder (3.2.2)
28
+ codeclimate-test-reporter (0.4.3)
29
+ simplecov (>= 0.7.1, < 1.0.0)
30
+ coveralls (0.7.1)
31
+ multi_json (~> 1.3)
32
+ rest-client
33
+ simplecov (>= 0.7)
34
+ term-ansicolor
35
+ thor
36
+ docile (1.1.5)
37
+ i18n (0.7.0)
38
+ json (1.8.1)
39
+ jwt (1.0.0)
40
+ mail (2.5.4)
41
+ mime-types (~> 1.16)
42
+ treetop (~> 1.4.8)
43
+ metaclass (0.0.4)
44
+ mime-types (1.25.1)
45
+ minitest (5.5.0)
46
+ minitest-reporters (1.0.8)
47
+ ansi
48
+ builder
49
+ minitest (>= 5.0)
50
+ ruby-progressbar
51
+ mocha (1.1.0)
52
+ metaclass (~> 0.0.1)
53
+ multi_json (1.10.1)
54
+ netrc (0.10.2)
55
+ nexmo (2.0.0)
56
+ polyglot (0.3.5)
57
+ rake (10.4.2)
58
+ rest-client (1.7.2)
59
+ mime-types (>= 1.16, < 3.0)
60
+ netrc (~> 0.7)
61
+ ruby-progressbar (1.7.1)
62
+ shoulda (3.5.0)
63
+ shoulda-context (~> 1.0, >= 1.0.1)
64
+ shoulda-matchers (>= 1.4.1, < 3.0)
65
+ shoulda-context (1.2.1)
66
+ shoulda-matchers (2.7.0)
67
+ activesupport (>= 3.0.0)
68
+ simplecov (0.9.1)
69
+ docile (~> 1.1.0)
70
+ multi_json (~> 1.0)
71
+ simplecov-html (~> 0.8.0)
72
+ simplecov-html (0.8.0)
73
+ term-ansicolor (1.3.0)
74
+ tins (~> 1.0)
75
+ thor (0.19.1)
76
+ thread_safe (0.3.4)
77
+ tins (1.3.3)
78
+ treetop (1.4.15)
79
+ polyglot
80
+ polyglot (>= 0.3.1)
81
+ twilio-ruby (3.14.2)
82
+ builder (>= 2.1.2)
83
+ jwt (~> 1.0.0)
84
+ multi_json (>= 1.3.0)
85
+ tzinfo (1.2.2)
86
+ thread_safe (~> 0.1)
87
+
88
+ PLATFORMS
89
+ ruby
90
+
91
+ DEPENDENCIES
92
+ action_texter (= 0.2.0)!
93
+ appraisal
94
+ bundler
95
+ codeclimate-test-reporter
96
+ coveralls
97
+ mail (= 2.5.4)
98
+ minitest
99
+ minitest-reporters
100
+ mocha
101
+ nexmo
102
+ rake
103
+ shoulda
104
+ simplecov
105
+ sms_safe!
106
+ twilio-ruby
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "action_texter", "0.2.0", :git => "git://github.com/mstycom/action_texter.git"
6
+ gem "mail", "2.6.1"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,101 @@
1
+ GIT
2
+ remote: git://github.com/mstycom/action_texter.git
3
+ revision: 75dea6a6dffe3e69082f1e2b50403f0e6c567119
4
+ specs:
5
+ action_texter (0.2.0)
6
+
7
+ PATH
8
+ remote: ../
9
+ specs:
10
+ sms_safe (0.1.0)
11
+ mail (>= 2.4)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (4.2.0)
17
+ i18n (~> 0.7)
18
+ json (~> 1.7, >= 1.7.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.3, >= 0.3.4)
21
+ tzinfo (~> 1.1)
22
+ ansi (1.4.3)
23
+ appraisal (1.0.2)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ builder (3.2.2)
28
+ codeclimate-test-reporter (0.4.3)
29
+ simplecov (>= 0.7.1, < 1.0.0)
30
+ coveralls (0.7.1)
31
+ multi_json (~> 1.3)
32
+ rest-client
33
+ simplecov (>= 0.7)
34
+ term-ansicolor
35
+ thor
36
+ docile (1.1.5)
37
+ i18n (0.7.0)
38
+ json (1.8.1)
39
+ jwt (1.0.0)
40
+ mail (2.6.1)
41
+ mime-types (>= 1.16, < 3)
42
+ metaclass (0.0.4)
43
+ mime-types (2.4.3)
44
+ minitest (5.5.0)
45
+ minitest-reporters (1.0.8)
46
+ ansi
47
+ builder
48
+ minitest (>= 5.0)
49
+ ruby-progressbar
50
+ mocha (1.1.0)
51
+ metaclass (~> 0.0.1)
52
+ multi_json (1.10.1)
53
+ netrc (0.10.2)
54
+ nexmo (2.0.0)
55
+ rake (10.4.2)
56
+ rest-client (1.7.2)
57
+ mime-types (>= 1.16, < 3.0)
58
+ netrc (~> 0.7)
59
+ ruby-progressbar (1.7.1)
60
+ shoulda (3.5.0)
61
+ shoulda-context (~> 1.0, >= 1.0.1)
62
+ shoulda-matchers (>= 1.4.1, < 3.0)
63
+ shoulda-context (1.2.1)
64
+ shoulda-matchers (2.7.0)
65
+ activesupport (>= 3.0.0)
66
+ simplecov (0.9.1)
67
+ docile (~> 1.1.0)
68
+ multi_json (~> 1.0)
69
+ simplecov-html (~> 0.8.0)
70
+ simplecov-html (0.8.0)
71
+ term-ansicolor (1.3.0)
72
+ tins (~> 1.0)
73
+ thor (0.19.1)
74
+ thread_safe (0.3.4)
75
+ tins (1.3.3)
76
+ twilio-ruby (3.14.2)
77
+ builder (>= 2.1.2)
78
+ jwt (~> 1.0.0)
79
+ multi_json (>= 1.3.0)
80
+ tzinfo (1.2.2)
81
+ thread_safe (~> 0.1)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ action_texter (= 0.2.0)!
88
+ appraisal
89
+ bundler
90
+ codeclimate-test-reporter
91
+ coveralls
92
+ mail (= 2.6.1)
93
+ minitest
94
+ minitest-reporters
95
+ mocha
96
+ nexmo
97
+ rake
98
+ shoulda
99
+ simplecov
100
+ sms_safe!
101
+ twilio-ruby
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "action_texter", "0.2.0", :git => "git://github.com/mstycom/action_texter.git"
6
+ gem "mail", "2.6.3"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,101 @@
1
+ GIT
2
+ remote: git://github.com/mstycom/action_texter.git
3
+ revision: 75dea6a6dffe3e69082f1e2b50403f0e6c567119
4
+ specs:
5
+ action_texter (0.2.0)
6
+
7
+ PATH
8
+ remote: ../
9
+ specs:
10
+ sms_safe (0.1.0)
11
+ mail (>= 2.4)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (4.2.0)
17
+ i18n (~> 0.7)
18
+ json (~> 1.7, >= 1.7.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.3, >= 0.3.4)
21
+ tzinfo (~> 1.1)
22
+ ansi (1.4.3)
23
+ appraisal (1.0.2)
24
+ bundler
25
+ rake
26
+ thor (>= 0.14.0)
27
+ builder (3.2.2)
28
+ codeclimate-test-reporter (0.4.3)
29
+ simplecov (>= 0.7.1, < 1.0.0)
30
+ coveralls (0.7.1)
31
+ multi_json (~> 1.3)
32
+ rest-client
33
+ simplecov (>= 0.7)
34
+ term-ansicolor
35
+ thor
36
+ docile (1.1.5)
37
+ i18n (0.7.0)
38
+ json (1.8.1)
39
+ jwt (1.0.0)
40
+ mail (2.6.3)
41
+ mime-types (>= 1.16, < 3)
42
+ metaclass (0.0.4)
43
+ mime-types (2.4.3)
44
+ minitest (5.5.0)
45
+ minitest-reporters (1.0.8)
46
+ ansi
47
+ builder
48
+ minitest (>= 5.0)
49
+ ruby-progressbar
50
+ mocha (1.1.0)
51
+ metaclass (~> 0.0.1)
52
+ multi_json (1.10.1)
53
+ netrc (0.10.2)
54
+ nexmo (2.0.0)
55
+ rake (10.4.2)
56
+ rest-client (1.7.2)
57
+ mime-types (>= 1.16, < 3.0)
58
+ netrc (~> 0.7)
59
+ ruby-progressbar (1.7.1)
60
+ shoulda (3.5.0)
61
+ shoulda-context (~> 1.0, >= 1.0.1)
62
+ shoulda-matchers (>= 1.4.1, < 3.0)
63
+ shoulda-context (1.2.1)
64
+ shoulda-matchers (2.7.0)
65
+ activesupport (>= 3.0.0)
66
+ simplecov (0.9.1)
67
+ docile (~> 1.1.0)
68
+ multi_json (~> 1.0)
69
+ simplecov-html (~> 0.8.0)
70
+ simplecov-html (0.8.0)
71
+ term-ansicolor (1.3.0)
72
+ tins (~> 1.0)
73
+ thor (0.19.1)
74
+ thread_safe (0.3.4)
75
+ tins (1.3.3)
76
+ twilio-ruby (3.14.2)
77
+ builder (>= 2.1.2)
78
+ jwt (~> 1.0.0)
79
+ multi_json (>= 1.3.0)
80
+ tzinfo (1.2.2)
81
+ thread_safe (~> 0.1)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ action_texter (= 0.2.0)!
88
+ appraisal
89
+ bundler
90
+ codeclimate-test-reporter
91
+ coveralls
92
+ mail (= 2.6.3)
93
+ minitest
94
+ minitest-reporters
95
+ mocha
96
+ nexmo
97
+ rake
98
+ shoulda
99
+ simplecov
100
+ sms_safe!
101
+ twilio-ruby
@@ -0,0 +1,10 @@
1
+ require 'sms_safe/config'
2
+ require 'sms_safe/interceptor'
3
+ require 'sms_safe/message'
4
+ require 'sms_safe/version'
5
+
6
+ require 'sms_safe/interceptors/action_texter'
7
+ require 'sms_safe/interceptors/twilio'
8
+ require 'sms_safe/interceptors/nexmo'
9
+
10
+ require 'sms_safe/hooks' # Must be at the end, it needs access to all the other classes
@@ -0,0 +1,49 @@
1
+ module SmsSafe
2
+
3
+ class InvalidConfigSettingError < StandardError; end
4
+
5
+ def self.configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ def self.configure
10
+ yield(configuration) if block_given?
11
+ end
12
+
13
+ class Configuration
14
+
15
+ # List of phone numbers that can accept SMS. Any phone number not on this list will get the SMS intercepted
16
+ # Leaving this empty means *all* SMS are intercepted, which is a valid use case.
17
+ # Value can be a String, a Regex, or a Proc to determine whether the phone is internal or not.
18
+ # Value can also be an Array, in which case the SMS will be allowed to go through if *any* of the entries match.
19
+ attr_accessor :internal_phone_numbers
20
+
21
+ # What to do with intercepted messages.
22
+ # Options are:
23
+ # :redirect - send SMS to another number. Must set redirect_target option
24
+ # :email - send an Email instead. Must set email_target option.
25
+ # :discard - don't send anything. May want to set discard_delay if simulating load
26
+ attr_accessor :intercept_mechanism
27
+
28
+ # The target number where messages are redirected, if intercept mechanism is :redirect
29
+ # Value can be a string or a Proc that returns a string
30
+ attr_accessor :redirect_target
31
+
32
+ # The target email where messages are sent, instead of sending SMS, if intercept mechanism is :email
33
+ # Value can be a string or a Proc that returns a string
34
+ attr_accessor :email_target
35
+
36
+ # If you are doing stress testing, you don't want to send out millions of SMS or Emails, so discarding is the
37
+ # way to go. However, this may give you an unrealistic view of how many SMS you can send per minute, distorting
38
+ # the results of the stress test. Discard delay introduces a little `sleep` whilst discarding, to compensate for that.
39
+ # Defaults to 50ms
40
+ # Specify it in ms
41
+ attr_accessor :discard_delay
42
+
43
+ def initialize
44
+ @internal_phone_numbers = []
45
+ @intercept_mechanism = 'redirect'
46
+ @discard_delay = 50 # 50 milliseconds
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,60 @@
1
+
2
+ module SmsSafe
3
+
4
+ # Hooks into the specified texter gem to be able to analyze and modify / discard messages before they are sent.
5
+ # Uses a civilized method for :action_texter, and monkey_patching for the rest, unfortunately
6
+ # @param [Symbol] texter_gem the gem that is being used for sending messages.
7
+ # Can be :action_texter, :twilio, or :nexmo
8
+ # @return Nothing useful
9
+ def self.hook!(texter_gem)
10
+ case texter_gem
11
+ when :action_texter
12
+ ActionTexter.register_interceptor(SmsSafe::Interceptors::ActionTexter.new)
13
+ when :twilio
14
+ hook_twilio!
15
+ when :nexmo
16
+ hook_nexmo!
17
+ else
18
+ raise InvalidConfigSettingError.new("Ensure texter_gem is either :action_texter, :twilio or :nexmo")
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ # Hooks into Nexmo's message sending method to allows us to intercept.
25
+ # Uses monkeypatching, unfortunately.
26
+ def self.hook_nexmo!
27
+ Nexmo::Client.class_eval do
28
+ alias_method :sms_safe_original_send_message, :send_message
29
+
30
+ def send_message(params)
31
+ interceptor = SmsSafe::Interceptors::Nexmo.new
32
+ new_message = interceptor.process_message(params)
33
+ if new_message.nil?
34
+ return new_message
35
+ else
36
+ return sms_safe_original_send_message(new_message)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # Hooks into Twilio's message sending method to allows us to intercept.
43
+ # Uses monkeypatching, unfortunately.
44
+ def self.hook_twilio!
45
+ Twilio::REST::Messages.class_eval do
46
+ # There is no method to alias, the gem relies on method_missing on a base class...
47
+ #alias_method :sms_safe_original_send_message, :send_message
48
+
49
+ def create(params)
50
+ interceptor = SmsSafe::Interceptors::Twilio.new
51
+ new_message = interceptor.process_message(params)
52
+ if new_message.nil?
53
+ return new_message
54
+ else
55
+ return super(new_message)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end