sms_broker 1.0.7 → 1.0.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0acc9a14c5a0467200ba73c2c3e1cd0f89fec0b4
4
- data.tar.gz: 10f556f81b8e7cb032f572fc25457f17ac08268d
3
+ metadata.gz: ef32eafa4d95269c26382e2b43058a9253862ff6
4
+ data.tar.gz: a9f299fe0efbc007aa7718a641580d2bc074202a
5
5
  SHA512:
6
- metadata.gz: '0915db6c9fd498ad8af471050428e9191bd317b642cb6586a23e8014000cc0e809f2db141af8f955ef7f79c264255e6a8708397935bfea47d1fe95b1e1bdb011'
7
- data.tar.gz: b4a85f44034db87b1b6c685ee5f4221c1a8ac6ccf433c0c773d3a41ad8bc32c860275cb41854270dcdbe19375d3648cdf9a6fefe1dba77c00e0ff4b8c51caf94
6
+ metadata.gz: 62f1bd9c8240c787d0e0bb29011e3c3031c2c35a2d53f7b213e62c5e7794f5f6f71bbc198f6a2c29aa56e4e3561aef8e1af854ca44f3f29831ac9e165f2cb60f
7
+ data.tar.gz: ffc1b5f61a7a187b0df2096bb1aa67e90c444feea4ea87faeb709e43fbe9286d240a849263eaf3394ff9f108c8b2faa88c695ab90561ea91391acde0801d966d
@@ -8,7 +8,7 @@ module OpenMarket
8
8
  class Client < OpenMarket::Client
9
9
  BASE_URL ='sms/v4'.freeze
10
10
 
11
- def send_message(from:, to:, text:)
11
+ def send_message(from:nil, to:, text:)
12
12
  request = Requests::SendMessage.new(from, to, text)
13
13
 
14
14
  SMS::Responses::SendMessage.new(request, send_request(request))
@@ -46,6 +46,8 @@ module OpenMarket
46
46
  end
47
47
 
48
48
  def source
49
+ return {} unless @from && !@from.empty?
50
+
49
51
  { source: { ton: ALPHANUMERIC_TYPE_OF_NUMBER, address: @from } }
50
52
  end
51
53
 
@@ -64,7 +64,7 @@ module SmsBroker
64
64
  def get_sender(from)
65
65
  if client.sender_id && from == :sender_id
66
66
  client.sender_id
67
- else
67
+ elsif client.phone_number
68
68
  return client.phone_number if client.phone_number.start_with?('+')
69
69
 
70
70
  "+#{client.phone_number}"
@@ -1,3 +1,3 @@
1
1
  module SmsBroker
2
- VERSION = '1.0.7'.freeze
2
+ VERSION = '1.0.8'.freeze
3
3
  end
@@ -13,17 +13,48 @@ describe OpenMarket do
13
13
  )
14
14
  }
15
15
 
16
- context 'sending a text message' do
16
+ context 'sending a text message without originator' do
17
17
  let(:response) {
18
18
  client.send_message(
19
- from: from,
20
19
  to: to,
21
20
  text: text
22
21
  )
23
22
  }
24
23
 
25
24
  context 'with success' do
25
+ it 'should return success == true' do
26
+ VCR.use_cassette('open_market/no_sender_message_success') do
27
+ expect(response.success?).to eq(true)
28
+ expect(response.status).to eq(202)
29
+ expect(response.message_id).to eq('2018Z-0329K-14090-31ISC')
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'invalid auth' do
35
+ it 'should return success == false' do
36
+ VCR.use_cassette('open_market/no_sender_message_unauthorized') do
37
+ expect(response.success?).to eq(false)
38
+ expect(response.status).to eq(401)
39
+
40
+ expect(response.error_code).to eq(420)
41
+ expect(response.error_message).not_to be(nil)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
26
47
 
48
+ context 'sending a text message with originator' do
49
+ let(:response) {
50
+ client.send_message(
51
+ from: from,
52
+ to: to,
53
+ text: text
54
+ )
55
+ }
56
+
57
+ context 'with success' do
27
58
  it 'should return success == true' do
28
59
  VCR.use_cassette('open_market/message_success') do
29
60
  expect(response.success?).to eq(true)
@@ -31,7 +62,6 @@ describe OpenMarket do
31
62
  expect(response.message_id).to eq('2618Z-03021-1603K-03FDL')
32
63
  end
33
64
  end
34
-
35
65
  end
36
66
 
37
67
  context 'invalid auth' do
@@ -1,54 +1,76 @@
1
1
  describe SmsBroker do
2
2
  context 'OpenMarket' do
3
- context '#send_message' do
4
- let(:provider) { 'open_market' }
3
+ let(:provider) { 'open_market' }
4
+ let(:account_id) { '132'}
5
+ let(:account_password) { '456' }
5
6
 
6
- let(:account_id) { '132'}
7
- let(:account_password) { '456' }
8
- let(:text_message) { 'Hello World' }
9
- let(:sender_id) { 'SenderID' }
10
- let(:to_phone) { '44000000000' }
7
+ let(:service) do
8
+ SmsBroker.service(provider)
9
+ end
11
10
 
12
- before(:each) do
13
- SmsBroker.clear_setup
11
+ let(:sender_id) {}
14
12
 
15
- setup
13
+ let(:setup) {
14
+ SmsBroker.setup do |config|
15
+ config.services [provider]
16
+ config.default_service provider
17
+ config.open_market_setup \
18
+ account_id: account_id,
19
+ account_password: account_password,
20
+ sender_id: sender_id
16
21
  end
22
+ }
17
23
 
18
- let(:service) do
19
- SmsBroker.service(provider)
20
- end
24
+ before(:each) do
25
+ SmsBroker.clear_setup
21
26
 
22
- let(:setup) {
23
- SmsBroker.setup do |config|
24
- config.services [provider]
25
- config.default_service provider
26
- config.open_market_setup \
27
- account_id: account_id,
28
- account_password: account_password,
29
- sender_id: sender_id
30
- end
31
- }
27
+ setup
28
+ end
29
+
30
+ context '#send_message' do
31
+ let(:text_message) { 'Hello World' }
32
+ let(:to_phone) { '44000000000' }
32
33
 
33
34
  context 'valid' do
34
- it 'should send message with success' do
35
- setup
36
35
 
37
- VCR.use_cassette('open_market/message_success') do
38
- response = service.message(text_message).to(to_phone).deliver
36
+ context 'without sender_id' do
37
+ it 'should send message with success' do
38
+ setup
39
39
 
40
- expect(response.service).to eq(:open_market)
41
- expect(response.success?).to eq(true)
42
- expect(response.message_id).not_to eq(nil)
43
- expect(response.location).not_to eq(nil)
44
- expect(response.request_id).not_to eq(nil)
40
+ VCR.use_cassette('open_market/no_sender_message_success') do
41
+ response = service.message(text_message).to(to_phone).deliver
45
42
 
43
+ expect(response.service).to eq(:open_market)
44
+ expect(response.success?).to eq(true)
45
+ expect(response.message_id).not_to eq(nil)
46
+ expect(response.location).not_to eq(nil)
47
+ expect(response.request_id).not_to eq(nil)
48
+ end
46
49
  end
50
+ end
51
+
52
+ context 'with sender_id' do
53
+ let(:sender_id) { 'SenderID' }
54
+
55
+ it 'should send message with success' do
56
+ setup
57
+
58
+ VCR.use_cassette('open_market/message_success') do
59
+ response = service.message(text_message).to(to_phone).deliver
47
60
 
61
+ expect(response.service).to eq(:open_market)
62
+ expect(response.success?).to eq(true)
63
+ expect(response.message_id).not_to eq(nil)
64
+ expect(response.location).not_to eq(nil)
65
+ expect(response.request_id).not_to eq(nil)
66
+ end
67
+ end
48
68
  end
49
69
  end
50
70
 
51
71
  context 'invalid' do
72
+ let(:sender_id) { 'SenderID' }
73
+
52
74
  it 'should return the error' do
53
75
  setup
54
76
 
@@ -65,36 +87,10 @@ describe SmsBroker do
65
87
  end
66
88
 
67
89
  context '#delivery_status' do
68
- let(:provider) { 'open_market' }
69
-
70
- let(:account_id) { '132'}
71
- let(:account_password) { '456' }
72
- let(:sender_id) { 'SenderID' }
73
-
74
- let(:message_id) { '2218Z-0318E-2225A-4999C' }
75
-
76
- before(:each) do
77
- SmsBroker.clear_setup
78
-
79
- setup
80
- end
81
-
82
- let(:service) do
83
- SmsBroker.service(provider)
84
- end
85
-
86
- let(:setup) {
87
- SmsBroker.setup do |config|
88
- config.services [provider]
89
- config.default_service provider
90
- config.open_market_setup \
91
- account_id: account_id,
92
- account_password: account_password,
93
- sender_id: sender_id
94
- end
95
- }
96
90
 
97
91
  context 'valid message id' do
92
+ let(:message_id) { '2218Z-0318E-2225A-4999C' }
93
+
98
94
  it 'should return the status of the message with success' do
99
95
  setup
100
96
 
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://smsc.openmarket.com/sms/v4/mt
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"mobileTerminate":{"message":{"content":"Hello OpenMarket World!","type":"text"},"destination":{"address":"447736067864"}}}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.14.0
12
+ Authorization:
13
+ - Basic BOGUS
14
+ Content-Type:
15
+ - application/json
16
+ Accept:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 202
23
+ message: Accepted
24
+ headers:
25
+ X-Request-Id:
26
+ - 001-20-CE9E4F4D-E86B-4F37-AAD2-004094B26590
27
+ Location:
28
+ - http://smsc.openmarket.com/sms/v4/mt/2018Z-0329K-14090-31ISC
29
+ Content-Type:
30
+ - application/json;charset=UTF-8
31
+ Content-Length:
32
+ - '0'
33
+ Date:
34
+ - Thu, 29 Mar 2018 14:09:31 GMT
35
+ Server:
36
+ - OpenMarket Server
37
+ body:
38
+ encoding: UTF-8
39
+ string: ''
40
+ http_version:
41
+ recorded_at: Thu, 29 Mar 2018 14:09:32 GMT
42
+ recorded_with: VCR 4.0.0
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://smsc.openmarket.com/sms/v4/mt
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"mobileTerminate":{"message":{"content":"Hello OpenMarket World!","type":"text"},"destination":{"address":"918000001"}}}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.14.0
12
+ Authorization:
13
+ - Basic BOGUS
14
+ Content-Type:
15
+ - application/json
16
+ Accept:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 401
23
+ message: Unauthorized
24
+ headers:
25
+ X-Request-Id:
26
+ - 001-23-5659D2F0-44DA-4270-B662-9F276DAF6F81
27
+ Content-Type:
28
+ - application/json;charset=ISO-8859-1
29
+ Content-Length:
30
+ - '80'
31
+ Date:
32
+ - Thu, 29 Mar 2018 14:11:16 GMT
33
+ Server:
34
+ - OpenMarket Server
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"error":{"code":"420","description":"Invalid account ID or account
38
+ password"}}
39
+
40
+ '
41
+ http_version:
42
+ recorded_at: Thu, 29 Mar 2018 14:11:16 GMT
43
+ recorded_with: VCR 4.0.0
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.7
4
+ version: 1.0.8
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: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexmo
@@ -187,6 +187,8 @@ files:
187
187
  - spec/support/vcr_cassettes/open_market/message_status_unauthorized.yml
188
188
  - spec/support/vcr_cassettes/open_market/message_success.yml
189
189
  - spec/support/vcr_cassettes/open_market/message_unauthorized.yml
190
+ - spec/support/vcr_cassettes/open_market/no_sender_message_success.yml
191
+ - spec/support/vcr_cassettes/open_market/no_sender_message_unauthorized.yml
190
192
  - spec/support/vcr_cassettes/twilio/create_invalid_phone_error.yml
191
193
  - spec/support/vcr_cassettes/twilio/create_invalid_phone_error_21612.yml
192
194
  - spec/support/vcr_cassettes/twilio/create_success.yml
@@ -229,6 +231,8 @@ test_files:
229
231
  - spec/support/vcr_cassettes/open_market/message_status_unauthorized.yml
230
232
  - spec/support/vcr_cassettes/open_market/message_success.yml
231
233
  - spec/support/vcr_cassettes/open_market/message_unauthorized.yml
234
+ - spec/support/vcr_cassettes/open_market/no_sender_message_success.yml
235
+ - spec/support/vcr_cassettes/open_market/no_sender_message_unauthorized.yml
232
236
  - spec/support/vcr_cassettes/twilio/create_invalid_phone_error.yml
233
237
  - spec/support/vcr_cassettes/twilio/create_invalid_phone_error_21612.yml
234
238
  - spec/support/vcr_cassettes/twilio/create_success.yml