sms_broker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
1
+ require 'rack'
2
+
3
+ module NexmoHelpers
4
+
5
+ # NEXMO CREATE MESSAGE -------------------------------------------------------
6
+
7
+ def stub_nexmo_create_message(request_body, response_body)
8
+ stub_request(:post, 'https://rest.nexmo.com/sms/json')
9
+ .with(body: request_body)
10
+ .to_return(
11
+ status: 200,
12
+ body: response_body.to_json,
13
+ headers: {
14
+ 'Content-Type' => 'application/json'
15
+ }
16
+ )
17
+ end
18
+
19
+ def stub_nexmo_create_message_missing_params(to, message)
20
+ request_body = {
21
+ to: to,
22
+ from: nil,
23
+ text: message,
24
+ api_key: ENV['NEXMO_API_KEY'],
25
+ api_secret: ENV['NEXMO_API_SECRET']
26
+ }
27
+
28
+ response_body = {
29
+ 'message-count' => '1',
30
+ 'messages' => [
31
+ {
32
+ 'status' => '2',
33
+ 'error-text' => 'Missing from param'
34
+ }
35
+ ]
36
+ }
37
+
38
+ stub_nexmo_create_message(request_body, response_body)
39
+ end
40
+
41
+ def stub_nexmo_create_message_invalid_sender_id_request(sender_id, to, message)
42
+ request_body = {
43
+ to: to,
44
+ from: sender_id,
45
+ text: message,
46
+ api_key: ENV['NEXMO_API_KEY'],
47
+ api_secret: ENV['NEXMO_API_SECRET']
48
+ }
49
+
50
+ response_body = {
51
+ 'message-count' => '1',
52
+ 'messages' => [
53
+ {
54
+ 'status' => '15',
55
+ 'error-text' => 'Invalid sender address'
56
+ }
57
+ ]
58
+ }
59
+
60
+ stub_nexmo_create_message(request_body, response_body)
61
+ end
62
+
63
+ def stub_nexmo_create_message_invalid_credentials(from, to, message)
64
+ request_body = {
65
+ to: to,
66
+ from: from,
67
+ text: message,
68
+ api_key: 'invalid',
69
+ api_secret: 'invalid'
70
+ }
71
+
72
+ response_body = {
73
+ 'message-count' => '1',
74
+ 'messages' => [
75
+ {
76
+ 'status' => '4',
77
+ 'error-text' => 'Bad Credentials'
78
+ }
79
+ ]
80
+ }
81
+
82
+ stub_nexmo_create_message(request_body, response_body)
83
+ end
84
+
85
+ def stub_nexmo_create_message_success(from, to, message)
86
+ request_body = {
87
+ to: to,
88
+ from: from,
89
+ text: message,
90
+ api_key: ENV['NEXMO_API_KEY'],
91
+ api_secret: ENV['NEXMO_API_SECRET']
92
+ }
93
+
94
+ response_body = {
95
+ 'message-count': '1',
96
+ 'messages': [
97
+ {
98
+ 'remaining-balance': '1.96670000',
99
+ 'message-price': '0.03330000',
100
+ 'message-id': '02000000D48B0A21',
101
+ 'network': '23420',
102
+ 'status': '0',
103
+ 'from': from,
104
+ 'to': to
105
+ }
106
+ ]
107
+ }
108
+
109
+ stub_nexmo_create_message(request_body, response_body)
110
+ end
111
+
112
+ # NEXMO GET MESSAGE ----------------------------------------------------------
113
+
114
+ def stub_nexmo_get_message(message_id, response_body)
115
+ query_string = \
116
+ Rack::Utils.build_query \
117
+ id: message_id,
118
+ api_key: ENV['NEXMO_API_KEY'],
119
+ api_secret: ENV['NEXMO_API_SECRET']
120
+
121
+ stub_request(:get, "https://rest.nexmo.com/search/message?#{query_string}")
122
+ .to_return(
123
+ status: 200,
124
+ body: response_body.to_json,
125
+ headers: {
126
+ 'Content-Type' => 'application/json'
127
+ }
128
+ )
129
+ end
130
+
131
+ def stub_nexmo_get_message_success(message_id)
132
+ response_body = {
133
+ "to" => "1234567890",
134
+ "from" => "1234567890",
135
+ "body" => "Hello[Nexmo DEMO]",
136
+ "type" => "MT",
137
+ "price" => "0.03330000",
138
+ "network" => "23420",
139
+ "latency" => 2234,
140
+ "message-id" => message_id,
141
+ "account-id" => "12345678",
142
+ "date-closed" => "2016-05-03 12:03:56",
143
+ "final-status" => "DELIVRD",
144
+ "date-received" => "2016-05-03 12:03:53"
145
+ }
146
+
147
+ stub_nexmo_get_message(message_id, response_body)
148
+ end
149
+
150
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_broker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Streetbees Dev Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nexmo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: compel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: twilio-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.11'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: sms_broker
112
+ email:
113
+ - dev@streetbees.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - lib/sms_broker.rb
124
+ - lib/sms_broker/client/base.rb
125
+ - lib/sms_broker/client/nexmo.rb
126
+ - lib/sms_broker/client/response/error.rb
127
+ - lib/sms_broker/client/response/nexmo_error.rb
128
+ - lib/sms_broker/client/response/nexmo_success.rb
129
+ - lib/sms_broker/client/response/success.rb
130
+ - lib/sms_broker/client/response/twilio_error.rb
131
+ - lib/sms_broker/client/response/twilio_success.rb
132
+ - lib/sms_broker/client/twilio.rb
133
+ - lib/sms_broker/configuration.rb
134
+ - lib/sms_broker/exceptions/invalid_service.rb
135
+ - lib/sms_broker/exceptions/invalid_setup.rb
136
+ - lib/sms_broker/message_sender.rb
137
+ - lib/sms_broker/service.rb
138
+ - lib/sms_broker/setup.rb
139
+ - lib/sms_broker/version.rb
140
+ - sms_broker.gemspec
141
+ - spec/sms_broker/nexmo_spec.rb
142
+ - spec/sms_broker/setup_spec.rb
143
+ - spec/sms_broker/sms_broker_spec.rb
144
+ - spec/sms_broker/twilio_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/support/nexmo_helpers.rb
147
+ homepage: https://github.com/streetbees/sms_broker
148
+ licenses: []
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.4.6
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: Sms Broker
170
+ test_files:
171
+ - spec/sms_broker/nexmo_spec.rb
172
+ - spec/sms_broker/setup_spec.rb
173
+ - spec/sms_broker/sms_broker_spec.rb
174
+ - spec/sms_broker/twilio_spec.rb
175
+ - spec/spec_helper.rb
176
+ - spec/support/nexmo_helpers.rb