sms_broker 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,6 @@
1
1
  require 'rack'
2
2
 
3
3
  module NexmoHelpers
4
-
5
- # NEXMO CREATE MESSAGE -------------------------------------------------------
6
-
7
4
  def stub_nexmo_create_message(request_body, response_body)
8
5
  stub_request(:post, 'https://rest.nexmo.com/sms/json')
9
6
  .with(body: request_body)
@@ -16,36 +13,18 @@ module NexmoHelpers
16
13
  )
17
14
  end
18
15
 
19
- def stub_nexmo_create_message_missing_params(to, message)
20
- request_body = {
16
+ def build_request_body(from, to, message)
17
+ {
21
18
  to: to,
22
- from: nil,
19
+ from: from,
23
20
  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
- ]
21
+ api_key: 'api_key',
22
+ api_secret: 'api_secret'
36
23
  }
37
-
38
- stub_nexmo_create_message(request_body, response_body)
39
24
  end
40
25
 
41
26
  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
- }
27
+ request_body = build_request_body(sender_id, to, message)
49
28
 
50
29
  response_body = {
51
30
  'message-count' => '1',
@@ -61,13 +40,10 @@ module NexmoHelpers
61
40
  end
62
41
 
63
42
  def stub_nexmo_create_message_invalid_credentials(from, to, message)
64
- request_body = {
65
- to: to,
66
- from: from,
67
- text: message,
43
+ request_body = build_request_body(from, to, message)
44
+ request_body.merge! \
68
45
  api_key: 'invalid',
69
46
  api_secret: 'invalid'
70
- }
71
47
 
72
48
  response_body = {
73
49
  'message-count' => '1',
@@ -83,13 +59,7 @@ module NexmoHelpers
83
59
  end
84
60
 
85
61
  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
- }
62
+ request_body = build_request_body(from, to, message)
93
63
 
94
64
  response_body = {
95
65
  'message-count': '1',
@@ -109,42 +79,19 @@ module NexmoHelpers
109
79
  stub_nexmo_create_message(request_body, response_body)
110
80
  end
111
81
 
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
82
+ def stub_nexmo_create_message_unknown_error(from, to, message)
83
+ request_body = build_request_body(from, to, message)
130
84
 
131
- def stub_nexmo_get_message_success(message_id)
132
85
  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"
86
+ 'message-count' => '1',
87
+ 'messages' => [
88
+ {
89
+ 'status' => '1',
90
+ 'error-text' => 'Unknown'
91
+ }
92
+ ]
145
93
  }
146
94
 
147
- stub_nexmo_get_message(message_id, response_body)
95
+ stub_nexmo_create_message(request_body, response_body)
148
96
  end
149
-
150
97
  end
@@ -0,0 +1,61 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.twilio.com/2010-04-01/Accounts/account_sid/Messages.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: Body=Hello+World&From=%2B15005550001&To=%2B15005550006
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Charset:
13
+ - utf-8
14
+ User-Agent:
15
+ - twilio-ruby/4.13.0 (ruby/x86_64-darwin14 2.2.1-p85)
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Authorization:
19
+ - Basic YWNjb3VudF9pZDphdXRoX3Rva2Vu
20
+ Content-Type:
21
+ - application/x-www-form-urlencoded
22
+ response:
23
+ status:
24
+ code: 400
25
+ message: BAD REQUEST
26
+ headers:
27
+ Access-Control-Allow-Credentials:
28
+ - 'true'
29
+ Access-Control-Allow-Headers:
30
+ - Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match,
31
+ If-Unmodified-Since
32
+ Access-Control-Allow-Methods:
33
+ - GET, POST, DELETE, OPTIONS
34
+ Access-Control-Allow-Origin:
35
+ - "*"
36
+ Access-Control-Expose-Headers:
37
+ - ETag
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ Date:
41
+ - Fri, 23 Sep 2016 12:53:22 GMT
42
+ Twilio-Request-Duration:
43
+ - '0.093'
44
+ Twilio-Request-Id:
45
+ - Twilio-Request-Id
46
+ X-Powered-By:
47
+ - AT-5000
48
+ X-Shenanigans:
49
+ - none
50
+ Content-Length:
51
+ - '199'
52
+ Connection:
53
+ - keep-alive
54
+ body:
55
+ encoding: UTF-8
56
+ string: '{"code": 21212, "message": "The ''From'' number +15005550001 is not
57
+ a valid phone number, shortcode, or alphanumeric sender ID.", "more_info":
58
+ "https://www.twilio.com/docs/errors/21212", "status": 400}'
59
+ http_version:
60
+ recorded_at: Fri, 23 Sep 2016 12:53:22 GMT
61
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,68 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.twilio.com/2010-04-01/Accounts/account_sid/Messages.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: Body=Hello+World&From=%2B15005550006&To=%2B15005550006
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Charset:
13
+ - utf-8
14
+ User-Agent:
15
+ - twilio-ruby/4.13.0 (ruby/x86_64-darwin14 2.2.1-p85)
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Authorization:
19
+ - Basic YWNjb3VudF9pZDphdXRoX3Rva2Vu
20
+ Content-Type:
21
+ - application/x-www-form-urlencoded
22
+ response:
23
+ status:
24
+ code: 201
25
+ message: CREATED
26
+ headers:
27
+ Access-Control-Allow-Credentials:
28
+ - 'true'
29
+ Access-Control-Allow-Headers:
30
+ - Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match,
31
+ If-Unmodified-Since
32
+ Access-Control-Allow-Methods:
33
+ - GET, POST, DELETE, OPTIONS
34
+ Access-Control-Allow-Origin:
35
+ - "*"
36
+ Access-Control-Expose-Headers:
37
+ - ETag
38
+ Content-Type:
39
+ - application/json; charset=utf-8
40
+ Date:
41
+ - Fri, 23 Sep 2016 12:53:22 GMT
42
+ Strict-Transport-Security:
43
+ - max-age=15768000
44
+ Twilio-Request-Duration:
45
+ - '0.034'
46
+ Twilio-Request-Id:
47
+ - Twilio-Request-Id
48
+ X-Powered-By:
49
+ - AT-5000
50
+ X-Shenanigans:
51
+ - none
52
+ Content-Length:
53
+ - '775'
54
+ Connection:
55
+ - keep-alive
56
+ body:
57
+ encoding: UTF-8
58
+ string: '{"sid": "message_sid", "date_created": "Fri,
59
+ 23 Sep 2016 12:53:22 +0000", "date_updated": "Fri, 23 Sep 2016 12:53:22 +0000",
60
+ "date_sent": null, "account_sid": "account_sid", "to":
61
+ "+15005550006", "from": "+15005550006", "messaging_service_sid": null, "body":
62
+ "Hello World", "status": "queued", "num_segments": "1", "num_media": "0",
63
+ "direction": "outbound-api", "api_version": "2010-04-01", "price": null, "price_unit":
64
+ "USD", "error_code": null, "error_message": null, "uri": "/2010-04-01/Accounts/account_sid/Messages/message_sid.json",
65
+ "subresource_uris": {"media": "/2010-04-01/Accounts/account_sid/Messages/message_sid/Media.json"}}'
66
+ http_version:
67
+ recorded_at: Fri, 23 Sep 2016 12:53:22 GMT
68
+ recorded_with: VCR 3.0.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_broker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Streetbees Dev Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-08 00:00:00.000000000 Z
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexmo
@@ -117,6 +117,8 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".travis.yml"
120
122
  - Gemfile
121
123
  - README.md
122
124
  - Rakefile
@@ -139,11 +141,14 @@ files:
139
141
  - lib/sms_broker/version.rb
140
142
  - sms_broker.gemspec
141
143
  - spec/sms_broker/nexmo_spec.rb
144
+ - spec/sms_broker/real_call_spec.rb
142
145
  - spec/sms_broker/setup_spec.rb
143
146
  - spec/sms_broker/sms_broker_spec.rb
144
147
  - spec/sms_broker/twilio_spec.rb
145
148
  - spec/spec_helper.rb
146
149
  - spec/support/nexmo_helpers.rb
150
+ - spec/support/vcr_cassettes/twilio/create_invalid_phone_error.yml
151
+ - spec/support/vcr_cassettes/twilio/create_success.yml
147
152
  homepage: https://github.com/streetbees/sms_broker
148
153
  licenses: []
149
154
  metadata: {}
@@ -169,8 +174,11 @@ specification_version: 4
169
174
  summary: Sms Broker
170
175
  test_files:
171
176
  - spec/sms_broker/nexmo_spec.rb
177
+ - spec/sms_broker/real_call_spec.rb
172
178
  - spec/sms_broker/setup_spec.rb
173
179
  - spec/sms_broker/sms_broker_spec.rb
174
180
  - spec/sms_broker/twilio_spec.rb
175
181
  - spec/spec_helper.rb
176
182
  - spec/support/nexmo_helpers.rb
183
+ - spec/support/vcr_cassettes/twilio/create_invalid_phone_error.yml
184
+ - spec/support/vcr_cassettes/twilio/create_success.yml