sms77 0.0.2 → 0.1.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/README.md +2 -2
- data/lib/sms77/base.rb +75 -0
- data/lib/sms77/client.rb +14 -52
- data/lib/sms77/{contacts_action.rb → contacts.rb} +2 -2
- data/lib/sms77/endpoint.rb +11 -12
- data/lib/sms77/hooks.rb +58 -0
- data/lib/sms77/{lookup_type.rb → lookup.rb} +2 -2
- data/lib/sms77/util.rb +28 -0
- data/lib/sms77/version.rb +1 -1
- data/sms77.gemspec +12 -15
- data/spec/sms77/balance_spec.rb +1 -6
- data/spec/sms77/client_spec.rb +18 -0
- data/spec/sms77/contacts_spec.rb +21 -20
- data/spec/sms77/hooks_spec.rb +95 -0
- data/spec/sms77/lookup_spec.rb +68 -82
- data/spec/sms77/pricing_spec.rb +23 -27
- data/spec/sms77/sms_spec.rb +17 -17
- data/spec/sms77/validate_for_voice_spec.rb +3 -3
- data/spec/sms77/voice_spec.rb +8 -5
- data/spec/sms77_spec.rb +0 -8
- data/spec/spec_helper.rb +31 -23
- metadata +38 -25
- data/lib/sms77/header.rb +0 -7
- data/spec/sms77/http_spec.rb +0 -40
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
require 'sms77/hooks'
|
5
|
+
require 'sms77/util'
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
RSpec.describe Sms77, 'hooks' do
|
9
|
+
HOOK_ID = EnvKeyStore.new('HOOK_ID')
|
10
|
+
|
11
|
+
def alter_action_stub
|
12
|
+
{
|
13
|
+
:code => nil,
|
14
|
+
:success => true
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def request(action, stub, extra_params = {})
|
19
|
+
res = Helper.method(Sms77::Hooks::Action::READ == action ? :get : :post)
|
20
|
+
.call(Sms77::Endpoint::HOOKS, stub, { action: action }.merge(extra_params))
|
21
|
+
|
22
|
+
expect(res).to be_a(Hash)
|
23
|
+
|
24
|
+
stub_keys = stub.keys
|
25
|
+
res.each do |k, v|
|
26
|
+
expect(stub_keys).to include(k)
|
27
|
+
expect(v.class).to match(stub[:"#{k}"].class)
|
28
|
+
end
|
29
|
+
|
30
|
+
res
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns all hooks' do
|
34
|
+
res = request(Sms77::Hooks::Action::READ, {
|
35
|
+
:code => nil,
|
36
|
+
:hooks => [
|
37
|
+
{
|
38
|
+
:created => "2020-11-04 23:04:15",
|
39
|
+
:event_type => "sms_mo",
|
40
|
+
:id => "30",
|
41
|
+
:request_method => "GET",
|
42
|
+
:target_url => "http://my.tld/testHook"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
:success => true
|
46
|
+
})
|
47
|
+
|
48
|
+
res[:hooks].each do |hook|
|
49
|
+
expect(Sms77::Util::is_valid_datetime?(hook[:created])).to be
|
50
|
+
expect(hook[:created] =~ /^\d\d\d\d-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01]) (00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/).to be
|
51
|
+
expect(Sms77::Hooks::Validator::event_type?(hook[:event_type])).to be
|
52
|
+
expect(Sms77::Util::is_positive_integer?(hook[:id])).to be
|
53
|
+
expect(Sms77::Hooks::Validator::request_method?(hook[:request_method])).to be
|
54
|
+
expect(Sms77::Hooks::Validator::target_url?(hook[:target_url])).to be
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'subscribes' do
|
59
|
+
stub = alter_action_stub.merge({ :id => rand(1...1000000) })
|
60
|
+
|
61
|
+
res = request(Sms77::Hooks::Action::SUBSCRIBE, stub, {
|
62
|
+
:event_type => Sms77::Hooks::EventType::NEW_INBOUND_SMS,
|
63
|
+
:request_method => Sms77::Hooks::RequestMethod::GET,
|
64
|
+
:target_url => "http://ruby.tld/#{SecureRandom.uuid}"
|
65
|
+
})
|
66
|
+
|
67
|
+
expect(Sms77::Util::is_positive_integer?(res[:id])).to be
|
68
|
+
expect(res[:id]).to be_a(Integer)
|
69
|
+
expect(stub[:id]).to match(res[:id]) unless Helper.is_http
|
70
|
+
|
71
|
+
assert_alter_response(res)
|
72
|
+
|
73
|
+
puts "Subscribed ID: #{Helper.is_http ? res[:id] : stub[:id]}"
|
74
|
+
|
75
|
+
HOOK_ID.set(res[:id])
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'unsubscribes' do
|
79
|
+
id = HOOK_ID.get
|
80
|
+
res = request(Sms77::Hooks::Action::UNSUBSCRIBE, alter_action_stub, { :id => id })
|
81
|
+
|
82
|
+
assert_alter_response(res)
|
83
|
+
|
84
|
+
expect(res[:success]).to be_boolean
|
85
|
+
|
86
|
+
puts "Unsubscribed ID #{id}: #{res[:success]}"
|
87
|
+
|
88
|
+
res[:success]
|
89
|
+
end
|
90
|
+
|
91
|
+
def assert_alter_response(res)
|
92
|
+
expect(res[:code]).to match(nil)
|
93
|
+
expect(res[:success]).to be_boolean
|
94
|
+
end
|
95
|
+
end
|
data/spec/sms77/lookup_spec.rb
CHANGED
@@ -2,26 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'sms77/endpoint'
|
5
|
-
require 'sms77/
|
5
|
+
require 'sms77/lookup'
|
6
6
|
require 'json'
|
7
7
|
|
8
8
|
RSpec.describe Sms77, 'lookup' do
|
9
9
|
def request(type, stub, extra_args = {})
|
10
|
-
Helper.
|
11
|
-
|
12
|
-
response = Helper.client.lookup({ type: type, number: '+491771783130' }.merge(extra_args))
|
13
|
-
|
14
|
-
expect(response.class).to eq(Faraday::Response)
|
15
|
-
|
16
|
-
body = response.body
|
17
|
-
|
18
|
-
begin
|
19
|
-
body = JSON.parse(body)
|
20
|
-
rescue StandardError
|
21
|
-
# Ignored
|
22
|
-
end
|
23
|
-
|
24
|
-
body
|
10
|
+
Helper.post(Sms77::Endpoint::LOOKUP, stub, { type: type, number: '+491771783130' }.merge(extra_args))
|
25
11
|
end
|
26
12
|
|
27
13
|
it 'misses number to lookup' do
|
@@ -37,10 +23,10 @@ RSpec.describe Sms77, 'lookup' do
|
|
37
23
|
success: false
|
38
24
|
}
|
39
25
|
|
40
|
-
|
26
|
+
res = request(Sms77::Lookup::Type::FORMAT, stub, { number: '' })
|
41
27
|
|
42
|
-
expect(
|
43
|
-
expect(
|
28
|
+
expect(res).to be_a(Hash)
|
29
|
+
expect(res[:success]).to match(false)
|
44
30
|
end
|
45
31
|
|
46
32
|
it 'returns number formatting details as json' do
|
@@ -56,18 +42,18 @@ RSpec.describe Sms77, 'lookup' do
|
|
56
42
|
success: true
|
57
43
|
}
|
58
44
|
|
59
|
-
body = request(Sms77::
|
60
|
-
|
61
|
-
expect(body).to
|
62
|
-
expect(body[
|
63
|
-
expect(body[
|
64
|
-
expect(body[
|
65
|
-
expect(body[
|
66
|
-
expect(body[
|
67
|
-
expect(body[
|
68
|
-
expect(body[
|
69
|
-
expect(body[
|
70
|
-
expect(body[
|
45
|
+
body = request(Sms77::Lookup::Type::FORMAT, stub)
|
46
|
+
|
47
|
+
expect(body).to be_a(Hash)
|
48
|
+
expect(body[:carrier]).to be_a(String)
|
49
|
+
expect(body[:country_code]).to be_a(String)
|
50
|
+
expect(body[:country_iso]).to be_a(String)
|
51
|
+
expect(body[:country_name]).to be_a(String)
|
52
|
+
expect(body[:international]).to be_a(String)
|
53
|
+
expect(body[:international_formatted]).to be_a(String)
|
54
|
+
expect(body[:national]).to be_a(String)
|
55
|
+
expect(body[:network_type]).to be_a(String)
|
56
|
+
expect(body[:success]).to be_boolean
|
71
57
|
end
|
72
58
|
|
73
59
|
it 'returns CNAM details as json' do
|
@@ -77,19 +63,19 @@ RSpec.describe Sms77, 'lookup' do
|
|
77
63
|
number: '+491771783130',
|
78
64
|
success: 'true'
|
79
65
|
}
|
80
|
-
body = request(Sms77::
|
66
|
+
body = request(Sms77::Lookup::Type::CNAM, stub)
|
81
67
|
|
82
|
-
expect(body).to
|
83
|
-
expect(body[
|
84
|
-
expect(body[
|
85
|
-
expect(body[
|
86
|
-
expect(body[
|
68
|
+
expect(body).to be_a(Hash)
|
69
|
+
expect(body[:code]).to be_a(String)
|
70
|
+
expect(body[:name]).to be_a(String)
|
71
|
+
expect(body[:number]).to be_a(String)
|
72
|
+
expect(body[:success]).to be_a(String)
|
87
73
|
end
|
88
74
|
|
89
75
|
it 'returns MNP details as text' do
|
90
|
-
body = request(Sms77::
|
76
|
+
body = request(Sms77::Lookup::Type::MNP, 'eplus')
|
91
77
|
|
92
|
-
expect(body).to
|
78
|
+
expect(body).to be_a(String)
|
93
79
|
end
|
94
80
|
|
95
81
|
it 'returns MNP details as json' do
|
@@ -107,20 +93,20 @@ RSpec.describe Sms77, 'lookup' do
|
|
107
93
|
price: 0.005,
|
108
94
|
success: true
|
109
95
|
}
|
110
|
-
body = request(Sms77::
|
111
|
-
|
112
|
-
expect(body).to
|
113
|
-
expect(body[
|
114
|
-
expect(body[
|
115
|
-
expect(body[
|
116
|
-
expect(body[
|
117
|
-
expect(body[
|
118
|
-
expect(body[
|
119
|
-
expect(body[
|
120
|
-
expect(body[
|
121
|
-
expect(body[
|
122
|
-
expect(body[
|
123
|
-
expect(body[
|
96
|
+
body = request(Sms77::Lookup::Type::MNP, stub, { json: 1 })
|
97
|
+
|
98
|
+
expect(body).to be_a(Hash)
|
99
|
+
expect(body[:code]).to be_a(Integer)
|
100
|
+
expect(body[:price]).to be_a(Float)
|
101
|
+
expect(body[:mnp]).to be_a(Hash)
|
102
|
+
expect(body[:mnp][:country]).to be_a(String)
|
103
|
+
expect(body[:mnp][:international_formatted]).to be_a(String)
|
104
|
+
expect(body[:mnp][:isPorted]).to be_boolean
|
105
|
+
expect(body[:mnp][:mccmnc]).to be_a(String)
|
106
|
+
expect(body[:mnp][:national_format]).to be_a(String)
|
107
|
+
expect(body[:mnp][:network]).to be_a(String)
|
108
|
+
expect(body[:mnp][:number]).to be_a(String)
|
109
|
+
expect(body[:success]).to be_boolean
|
124
110
|
end
|
125
111
|
|
126
112
|
it 'returns HLR details as json' do
|
@@ -155,34 +141,34 @@ RSpec.describe Sms77, 'lookup' do
|
|
155
141
|
valid_number: 'valid'
|
156
142
|
}
|
157
143
|
|
158
|
-
body = request(Sms77::
|
159
|
-
|
160
|
-
expect(body).to
|
161
|
-
expect(body[
|
162
|
-
expect(body[
|
163
|
-
expect(body[
|
164
|
-
|
165
|
-
expect(body[
|
166
|
-
expect(body[
|
167
|
-
expect(body[
|
168
|
-
expect(body[
|
169
|
-
expect(body[
|
170
|
-
|
171
|
-
expect(body[
|
172
|
-
expect(body[
|
173
|
-
expect(body[
|
174
|
-
expect(body[
|
175
|
-
expect(body[
|
176
|
-
expect(body[
|
177
|
-
expect(body[
|
178
|
-
expect(body[
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
expect(
|
183
|
-
expect(
|
184
|
-
expect(
|
185
|
-
expect(
|
186
|
-
expect(
|
144
|
+
body = request(Sms77::Lookup::Type::HLR, stub)
|
145
|
+
|
146
|
+
expect(body).to be_a(Hash)
|
147
|
+
expect(body[:country_code]).to be_a(String)
|
148
|
+
expect(body[:country_name]).to be_a(String)
|
149
|
+
expect(body[:country_prefix]).to be_a(String)
|
150
|
+
assert_carrier(body[:current_carrier])
|
151
|
+
expect(body[:international_format_number]).to be_a(String)
|
152
|
+
expect(body[:international_formatted]).to be_a(String)
|
153
|
+
expect(body[:lookup_outcome]).to be_boolean
|
154
|
+
expect(body[:lookup_outcome_message]).to be_a(String)
|
155
|
+
expect(body[:national_format_number]).to be_a(String)
|
156
|
+
assert_carrier(body[:original_carrier])
|
157
|
+
expect(body[:status]).to be_boolean
|
158
|
+
expect(body[:status_message]).to be_a(String)
|
159
|
+
expect(body[:gsm_code]).to be_a(String)
|
160
|
+
expect(body[:gsm_message]).to be_a(String)
|
161
|
+
expect(body[:ported]).to be_a(String)
|
162
|
+
expect(body[:reachable]).to be_a(String)
|
163
|
+
expect(body[:roaming]).to be_a(String)
|
164
|
+
expect(body[:valid_number]).to be_a(String)
|
165
|
+
end
|
166
|
+
|
167
|
+
def assert_carrier(hash)
|
168
|
+
expect(hash).to be_a(Hash)
|
169
|
+
expect(hash[:country]).to be_a(String)
|
170
|
+
expect(hash[:name]).to be_a(String)
|
171
|
+
expect(hash[:network_code]).to be_a(String)
|
172
|
+
expect(hash[:network_type]).to be_a(String)
|
187
173
|
end
|
188
174
|
end
|
data/spec/sms77/pricing_spec.rb
CHANGED
@@ -36,44 +36,40 @@ RSpec.describe Sms77, 'pricing' do
|
|
36
36
|
]
|
37
37
|
}
|
38
38
|
|
39
|
-
Helper.
|
39
|
+
res = Helper.get(Sms77::Endpoint::PRICING, stub)
|
40
|
+
countries = res[:countries]
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
expect(response.class).to eq(Faraday::Response)
|
46
|
-
expect(body).to be_kind_of(Hash)
|
47
|
-
expect(body['countCountries']).to be_kind_of(Integer)
|
48
|
-
expect(body['countNetworks']).to be_kind_of(Integer)
|
49
|
-
expect(countries).to be_kind_of(Array)
|
42
|
+
expect(res).to be_a(Hash)
|
43
|
+
expect(res[:countCountries]).to be_a(Integer)
|
44
|
+
expect(res[:countNetworks]).to be_a(Integer)
|
45
|
+
expect(countries).to be_a(Array)
|
50
46
|
|
51
47
|
countries.each do |country|
|
52
|
-
networks = country[
|
48
|
+
networks = country[:networks]
|
53
49
|
|
54
|
-
expect(country).to
|
55
|
-
expect(country[
|
56
|
-
expect(country[
|
57
|
-
expect(country[
|
58
|
-
expect(networks).to
|
50
|
+
expect(country).to be_a(Hash)
|
51
|
+
expect(country[:countryCode]).to be_a(String)
|
52
|
+
expect(country[:countryName]).to be_a(String)
|
53
|
+
expect(country[:countryPrefix]).to be_a(String)
|
54
|
+
expect(networks).to be_a(Array)
|
59
55
|
|
60
56
|
networks.each do |network|
|
61
|
-
mncs = network[
|
62
|
-
features = network[
|
57
|
+
mncs = network[:mncs]
|
58
|
+
features = network[:features]
|
63
59
|
|
64
|
-
expect(network).to
|
65
|
-
expect(network[
|
66
|
-
expect(mncs).to
|
60
|
+
expect(network).to be_a(Hash)
|
61
|
+
expect(network[:mcc]).to be_a(String)
|
62
|
+
expect(mncs).to be_a(Array)
|
67
63
|
mncs.each do |mnc|
|
68
|
-
expect(mnc).to
|
64
|
+
expect(mnc).to be_a(String)
|
69
65
|
end
|
70
|
-
expect(network[
|
71
|
-
expect(network[
|
72
|
-
expect(features).to
|
66
|
+
expect(network[:networkName]).to be_a(String)
|
67
|
+
expect(network[:price]).to be_a(Float)
|
68
|
+
expect(features).to be_a(Array)
|
73
69
|
features.each do |feature|
|
74
|
-
expect(feature).to
|
70
|
+
expect(feature).to be_a(String)
|
75
71
|
end
|
76
|
-
expect(network[
|
72
|
+
expect(network[:comment]).to be_a(String)
|
77
73
|
end
|
78
74
|
end
|
79
75
|
end
|
data/spec/sms77/sms_spec.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'sms77/endpoint'
|
5
|
-
require 'sms77/
|
5
|
+
require 'sms77/contacts'
|
6
6
|
|
7
7
|
RSpec.describe Sms77, 'sms' do
|
8
8
|
$text = 'Your glasses are ready for pickup.'
|
@@ -28,11 +28,11 @@ RSpec.describe Sms77, 'sms' do
|
|
28
28
|
to: Helper.virtual_inbound_nr_eplus
|
29
29
|
}.merge(extra_params)
|
30
30
|
|
31
|
-
Helper.
|
31
|
+
Helper.post(Sms77::Endpoint::SMS, stub, params)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'sends a single sms and returns success code' do
|
35
|
-
expect(request(100)).to
|
35
|
+
expect(request(100)).to be_a(Integer)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'sends a single sms and returns detailed text response' do
|
@@ -51,14 +51,14 @@ RSpec.describe Sms77, 'sms' do
|
|
51
51
|
|
52
52
|
body = request(stub, { details: 1 })
|
53
53
|
|
54
|
-
expect(body).to
|
54
|
+
expect(body).to be_a(String)
|
55
55
|
|
56
56
|
code, booked, cost, balance, text, type, flash, encoding, gsm0338, debug = body.split("\n")
|
57
57
|
|
58
|
-
expect(code).to
|
59
|
-
expect(booked.split(':').last.to_f).to
|
60
|
-
expect(cost.split(':').last.to_f).to
|
61
|
-
expect(balance.split(':').last.to_f).to
|
58
|
+
expect(code).to be_a(String)
|
59
|
+
expect(booked.split(':').last.to_f).to be_a(Float)
|
60
|
+
expect(cost.split(':').last.to_f).to be_a(Float)
|
61
|
+
expect(balance.split(':').last.to_f).to be_a(Float)
|
62
62
|
expect(text.split(':').last.strip!).to eq($text)
|
63
63
|
expect(type.split(':').last.strip!).to eq('direct')
|
64
64
|
expect(flash.split(':').last.strip!).to eq('false')
|
@@ -88,16 +88,16 @@ RSpec.describe Sms77, 'sms' do
|
|
88
88
|
|
89
89
|
body = request(stub, { json: 1 })
|
90
90
|
|
91
|
-
expect(body).to
|
91
|
+
expect(body).to be_a(Hash)
|
92
92
|
|
93
|
-
expect(body[
|
94
|
-
expect(body[
|
95
|
-
expect(body[
|
96
|
-
expect(body[
|
97
|
-
expect(body[
|
98
|
-
expect(body[
|
99
|
-
body[
|
100
|
-
expect(message).to
|
93
|
+
expect(body[:success]).to be_a(String)
|
94
|
+
expect(body[:total_price]).to be_numeric
|
95
|
+
expect(body[:balance]).to be_a(Float)
|
96
|
+
expect(body[:debug]).to be_a(String)
|
97
|
+
expect(body[:sms_type]).to eq('direct')
|
98
|
+
expect(body[:messages]).to be_a(Array)
|
99
|
+
body[:messages].each do |message|
|
100
|
+
expect(message).to be_a(Hash)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -11,9 +11,9 @@ RSpec.describe Sms77, 'validate_for_voice' do
|
|
11
11
|
callback = "#{callback_host}/callback.php"
|
12
12
|
stub = { success: true }
|
13
13
|
|
14
|
-
body = Helper.
|
14
|
+
body = Helper.post(Sms77::Endpoint::VALIDATE_FOR_VOICE, stub, { number: number, callback: callback })
|
15
15
|
|
16
|
-
expect(body).to
|
17
|
-
expect(body[
|
16
|
+
expect(body).to be_a(Hash)
|
17
|
+
expect(body[:success]).to be_boolean
|
18
18
|
end
|
19
19
|
end
|
data/spec/sms77/voice_spec.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'sms77/endpoint'
|
5
|
-
require 'sms77/
|
5
|
+
require 'sms77/contacts'
|
6
6
|
|
7
7
|
RSpec.describe Sms77, 'voice' do
|
8
8
|
def assert_response(response)
|
9
|
-
expect(response).to
|
9
|
+
expect(response).to be_a(String)
|
10
10
|
|
11
11
|
code, id, cost = response.split("\n")
|
12
12
|
|
@@ -22,10 +22,13 @@ RSpec.describe Sms77, 'voice' do
|
|
22
22
|
0.1
|
23
23
|
TEXT
|
24
24
|
|
25
|
-
params = {
|
26
|
-
|
25
|
+
params = {
|
26
|
+
from: Helper.virtual_inbound_nr_eplus,
|
27
|
+
text: text,
|
28
|
+
to: Helper.virtual_inbound_nr_eplus
|
29
|
+
}.merge(extra_params)
|
27
30
|
|
28
|
-
Helper.
|
31
|
+
Helper.post(Sms77::Endpoint::VOICE, stub, params)
|
29
32
|
end
|
30
33
|
|
31
34
|
it 'calls a number with text input' do
|