sms77 0.4.0 → 0.5.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/.gitignore +6 -4
- data/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/modules.xml +8 -0
- data/.idea/ruby-client.iml +18 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +2 -2
- data/LICENSE +20 -20
- data/README.md +41 -35
- data/Rakefile +5 -5
- data/doc/Sms77/Client.html +230 -0
- data/doc/Sms77/Contacts/Action.html +131 -0
- data/doc/Sms77/Contacts.html +126 -0
- data/doc/Sms77/Endpoint.html +187 -0
- data/doc/Sms77/Hooks/Action.html +131 -0
- data/doc/Sms77/Hooks/EventType.html +146 -0
- data/doc/Sms77/Hooks/RequestMethod.html +131 -0
- data/doc/Sms77/Hooks/Validator.html +598 -0
- data/doc/Sms77/Hooks.html +126 -0
- data/doc/Sms77/Journal/Type.html +136 -0
- data/doc/Sms77/Journal/Validator.html +394 -0
- data/doc/Sms77/Journal.html +126 -0
- data/doc/Sms77/Lookup/Type.html +136 -0
- data/doc/Sms77/Lookup.html +126 -0
- data/doc/Sms77/Resource.html +870 -0
- data/doc/Sms77/Resources/Analytics.html +263 -0
- data/doc/Sms77/Resources/Balance.html +246 -0
- data/doc/Sms77/Resources/Contacts.html +449 -0
- data/doc/Sms77/Resources/Hooks.html +457 -0
- data/doc/Sms77/Resources/Journal.html +261 -0
- data/doc/Sms77/Resources/Lookup.html +540 -0
- data/doc/Sms77/Resources/Pricing.html +263 -0
- data/doc/Sms77/Resources/Sms.html +261 -0
- data/doc/Sms77/Resources/Status.html +261 -0
- data/doc/Sms77/Resources/Subaccounts.html +651 -0
- data/doc/Sms77/Resources/ValidateForVoice.html +261 -0
- data/doc/Sms77/Resources/Voice.html +261 -0
- data/doc/Sms77/Resources.html +128 -0
- data/doc/Sms77/Sms/Type.html +126 -0
- data/doc/Sms77/Sms.html +126 -0
- data/doc/Sms77/Subaccounts/Action.html +141 -0
- data/doc/Sms77/Subaccounts/Validator.html +490 -0
- data/doc/Sms77/Subaccounts.html +126 -0
- data/doc/Sms77/Util.html +1033 -0
- data/doc/Sms77.html +146 -0
- data/doc/_index.html +444 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.html +112 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +112 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +563 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/sms77/client.rb +30 -29
- data/lib/sms77/contacts.rb +10 -9
- data/lib/sms77/endpoint.rb +17 -15
- data/lib/sms77/hooks.rb +67 -64
- data/lib/sms77/journal.rb +39 -38
- data/lib/sms77/lookup.rb +11 -10
- data/lib/sms77/resource.rb +94 -93
- data/lib/sms77/resources/analytics.rb +21 -16
- data/lib/sms77/resources/balance.rb +19 -15
- data/lib/sms77/resources/contacts.rb +38 -25
- data/lib/sms77/resources/hooks.rb +40 -29
- data/lib/sms77/resources/journal.rb +20 -15
- data/lib/sms77/resources/lookup.rb +47 -29
- data/lib/sms77/resources/pricing.rb +20 -15
- data/lib/sms77/resources/sms.rb +20 -15
- data/lib/sms77/resources/status.rb +20 -15
- data/lib/sms77/resources/subaccounts.rb +66 -0
- data/lib/sms77/resources/validate_for_voice.rb +20 -15
- data/lib/sms77/resources/voice.rb +20 -15
- data/lib/sms77/sms.rb +9 -8
- data/lib/sms77/subaccounts.rb +55 -0
- data/lib/sms77/util.rb +68 -67
- data/lib/sms77/version.rb +5 -5
- data/lib/sms77.rb +6 -6
- data/release.sh +4 -7
- data/sms77.gemspec +21 -21
- data/spec/EnvKeyStore.rb +14 -14
- data/spec/matchers.rb +22 -22
- data/spec/sms77/balance_spec.rb +12 -12
- data/spec/sms77/client_spec.rb +15 -15
- data/spec/sms77/contacts_spec.rb +129 -116
- data/spec/sms77/hooks_spec.rb +108 -105
- data/spec/sms77/instance_spec.rb +22 -20
- data/spec/sms77/journal_spec.rb +86 -86
- data/spec/sms77/lookup_spec.rb +179 -179
- data/spec/sms77/pricing_spec.rb +76 -76
- data/spec/sms77/sms_spec.rb +103 -103
- data/spec/sms77/subaccounts_spec.rb +121 -0
- data/spec/sms77/validate_for_voice_spec.rb +19 -19
- data/spec/sms77/voice_spec.rb +51 -51
- data/spec/sms77_spec.rb +9 -7
- data/spec/spec_helper.rb +53 -53
- metadata +75 -17
data/spec/sms77/hooks_spec.rb
CHANGED
@@ -1,106 +1,109 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require 'sms77/
|
6
|
-
require 'sms77/
|
7
|
-
require '
|
8
|
-
|
9
|
-
RSpec.describe Sms77, 'hooks' do
|
10
|
-
HOOK_ID = EnvKeyStore.new('HOOK_ID')
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
expect(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:
|
39
|
-
|
40
|
-
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
expect(res
|
52
|
-
expect(res[:
|
53
|
-
expect(res[:
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
expect(hook[:created]).to
|
60
|
-
expect(
|
61
|
-
expect(Sms77::
|
62
|
-
expect(Sms77::
|
63
|
-
expect(Sms77::Hooks::Validator::
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
:
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
expect(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'sms77/hooks'
|
6
|
+
require 'sms77/util'
|
7
|
+
require 'sms77/resources/hooks'
|
8
|
+
|
9
|
+
RSpec.describe Sms77, 'hooks' do
|
10
|
+
HOOK_ID = EnvKeyStore.new('HOOK_ID')
|
11
|
+
|
12
|
+
def alter_action_stub
|
13
|
+
{
|
14
|
+
:code => nil,
|
15
|
+
:success => true
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(fn, stub, extra_params = {})
|
20
|
+
helper = Helper.new(Sms77::Resources::Hooks)
|
21
|
+
|
22
|
+
res = helper.request(helper.resource.method(fn), stub, extra_params)
|
23
|
+
|
24
|
+
expect(res).to be_a(Hash)
|
25
|
+
|
26
|
+
stub_keys = stub.keys
|
27
|
+
|
28
|
+
res.each do |k, v|
|
29
|
+
expect(stub_keys).to include(k)
|
30
|
+
expect(v.class).to match(stub[:"#{k}"].class)
|
31
|
+
end
|
32
|
+
|
33
|
+
res
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'returns all hooks' do
|
37
|
+
res = request(:read, {
|
38
|
+
:code => nil,
|
39
|
+
:hooks => [
|
40
|
+
{
|
41
|
+
:created => "2020-11-04 23:04:15",
|
42
|
+
:event_type => "sms_mo",
|
43
|
+
:id => "30",
|
44
|
+
:request_method => "GET",
|
45
|
+
:target_url => "http://my.tld/testHook"
|
46
|
+
}
|
47
|
+
],
|
48
|
+
:success => true
|
49
|
+
})
|
50
|
+
|
51
|
+
expect(res).to include(:code, :hooks, :success)
|
52
|
+
expect(res[:code]).to eq(nil)
|
53
|
+
expect(res[:hooks]).to be_a(Array)
|
54
|
+
expect(res[:success]).to be_boolean
|
55
|
+
|
56
|
+
res[:hooks].each do |hook|
|
57
|
+
expect(hook).to include(:created, :event_type, :id, :request_method, :target_url)
|
58
|
+
|
59
|
+
expect(Sms77::Util::is_valid_datetime?(hook[:created])).to be
|
60
|
+
expect(hook[:created]).to match(/^\d\d\d\d-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01]) (1[0-9]|2[0-3]|0[0-9]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/)
|
61
|
+
expect(Sms77::Hooks::Validator::event_type?(hook[:event_type])).to be
|
62
|
+
expect(Sms77::Util::is_positive_integer?(hook[:id])).to be
|
63
|
+
expect(Sms77::Hooks::Validator::request_method?(hook[:request_method])).to be
|
64
|
+
expect(Sms77::Hooks::Validator::target_url?(hook[:target_url])).to be
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
=begin
|
69
|
+
it 'subscribes' do
|
70
|
+
helper = Helper.new(Sms77::Resources::Hooks)
|
71
|
+
stub = alter_action_stub.merge({ :id => rand(1...1000000) })
|
72
|
+
|
73
|
+
res = request(helper.resource.method(:subscribe), stub, {
|
74
|
+
:event_type => Sms77::Hooks::EventType::NEW_INBOUND_SMS,
|
75
|
+
:request_method => Sms77::Hooks::RequestMethod::GET,
|
76
|
+
:target_url => "http://ruby.tld/#{SecureRandom.uuid}"
|
77
|
+
})
|
78
|
+
|
79
|
+
expect(Sms77::Util::is_positive_integer?(res[:id])).to be
|
80
|
+
expect(res[:id]).to be_a(Integer)
|
81
|
+
expect(stub[:id]).to match(res[:id]) unless Helper::IS_HTTP
|
82
|
+
|
83
|
+
assert_alter_response(res)
|
84
|
+
|
85
|
+
puts "Subscribed ID: #{Helper::IS_HTTP ? res[:id] : stub[:id]}"
|
86
|
+
|
87
|
+
HOOK_ID.set(res[:id])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'unsubscribes' do
|
91
|
+
helper = Helper.new(Sms77::Resources::Hooks)
|
92
|
+
id = HOOK_ID.get
|
93
|
+
res = request(helper.resource.method(:unubscribe), alter_action_stub, { :id => id })
|
94
|
+
|
95
|
+
assert_alter_response(res)
|
96
|
+
|
97
|
+
expect(res[:success]).to be_boolean
|
98
|
+
|
99
|
+
puts "Unsubscribed ID #{id}: #{res[:success]}"
|
100
|
+
|
101
|
+
res[:success]
|
102
|
+
end
|
103
|
+
=end
|
104
|
+
|
105
|
+
def assert_alter_response(res)
|
106
|
+
expect(res[:code]).to match(nil)
|
107
|
+
expect(res[:success]).to be_boolean
|
108
|
+
end
|
106
109
|
end
|
data/spec/sms77/instance_spec.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#noinspection RubyResolve
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'sms77/resource'
|
6
|
+
|
7
|
+
#noinspection RubyResolve
|
8
|
+
RSpec.describe Sms77, 'instance' do
|
9
|
+
helper = Helper.new(Sms77::Resource)
|
10
|
+
|
11
|
+
it 'checks api key' do
|
12
|
+
expect(helper.resource.api_key).to be_lengthy_string
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'checks sentWith' do
|
16
|
+
expect(helper.resource.sent_with).to be_lengthy_string
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'fails authentication' do
|
20
|
+
expect { Sms77::Resource.new('') }.to raise_error(RuntimeError)
|
21
|
+
end
|
22
|
+
end
|
data/spec/sms77/journal_spec.rb
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'sms77/journal'
|
5
|
-
require 'sms77/resources/journal'
|
6
|
-
require 'sms77/sms'
|
7
|
-
|
8
|
-
RSpec.describe Sms77, 'journal' do
|
9
|
-
def valid_timestamp?(str)
|
10
|
-
str.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]) (2[0-3]|[01][\d]):[0-5][\d]/)
|
11
|
-
end
|
12
|
-
|
13
|
-
def request(type)
|
14
|
-
stub = [{
|
15
|
-
:from => "SMS",
|
16
|
-
:id => "123456789",
|
17
|
-
:price => "1.2",
|
18
|
-
:text => "Hey my friend!",
|
19
|
-
:timestamp => "2020-10-14 14:25:04",
|
20
|
-
:to => "49170123456789",
|
21
|
-
}]
|
22
|
-
|
23
|
-
helper = Helper.new(Sms77::Resources::Journal)
|
24
|
-
res = helper.request(helper.resource.method(:retrieve), stub, { type: type })
|
25
|
-
|
26
|
-
expect(res).to be_a(Array)
|
27
|
-
|
28
|
-
res.each do |journal|
|
29
|
-
expect(journal).to be_a(Hash)
|
30
|
-
expect(journal[:from]).to be_lengthy_string
|
31
|
-
expect(journal[:id]).to be_numeric
|
32
|
-
expect(Sms77::Util::valid_float?(journal[:price])).to be_truthy
|
33
|
-
expect(journal[:text]).to be_lengthy_string
|
34
|
-
expect(valid_timestamp?(journal[:timestamp])).to be_truthy
|
35
|
-
expect(journal[:to]).to be_lengthy_string
|
36
|
-
end
|
37
|
-
|
38
|
-
res
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns all inbound messages' do
|
42
|
-
request(Sms77::Journal::Type::INBOUND)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns all outbound messages' do
|
46
|
-
request(Sms77::Journal::Type::OUTBOUND).each do |journal|
|
47
|
-
journal.merge!({
|
48
|
-
:connection => "http",
|
49
|
-
:dlr => "DELIVERED",
|
50
|
-
:dlr_timestamp => "2020-10-04 09:26:10.000",
|
51
|
-
:foreign_id => "MyForeignId",
|
52
|
-
:label => "MyCustomLabel",
|
53
|
-
:latency => "5.1060",
|
54
|
-
:mccmnc => "26207",
|
55
|
-
:type => "direct",
|
56
|
-
})
|
57
|
-
expect(journal[:connection]).to be_lengthy_string
|
58
|
-
expect(journal[:dlr]).to be_nil_or_lengthy_string
|
59
|
-
expect(valid_timestamp?(journal[:dlr_timestamp])).to be_truthy
|
60
|
-
expect(journal[:foreign_id]).to be_nil_or_lengthy_string
|
61
|
-
expect(journal[:label]).to be_nil_or_lengthy_string
|
62
|
-
expect(journal[:latency]).to be_nil_or_lengthy_string
|
63
|
-
expect(journal[:mccmnc]).to be_nil_or_lengthy_string
|
64
|
-
expect(Sms77::Util::in_module_constants?(journal[:type], Sms77::Sms::Type)).to be_truthy
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'returns all voice messages' do
|
69
|
-
request(Sms77::Journal::Type::VOICE).each do |journal|
|
70
|
-
journal.merge!({
|
71
|
-
:duration => "2",
|
72
|
-
:error => "",
|
73
|
-
:status => "completed",
|
74
|
-
:xml => false,
|
75
|
-
})
|
76
|
-
expect(journal[:duration]).to be_numeric
|
77
|
-
expect(journal[:error]).to be_nil_or_lengthy_string
|
78
|
-
expect(journal[:status]).to be_lengthy_string
|
79
|
-
expect(journal[:xml]).to be_boolean
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'returns all reply messages' do
|
84
|
-
request(Sms77::Journal::Type::REPLIES)
|
85
|
-
end
|
86
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'sms77/journal'
|
5
|
+
require 'sms77/resources/journal'
|
6
|
+
require 'sms77/sms'
|
7
|
+
|
8
|
+
RSpec.describe Sms77, 'journal' do
|
9
|
+
def valid_timestamp?(str)
|
10
|
+
str.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]) (2[0-3]|[01][\d]):[0-5][\d]/)
|
11
|
+
end
|
12
|
+
|
13
|
+
def request(type)
|
14
|
+
stub = [{
|
15
|
+
:from => "SMS",
|
16
|
+
:id => "123456789",
|
17
|
+
:price => "1.2",
|
18
|
+
:text => "Hey my friend!",
|
19
|
+
:timestamp => "2020-10-14 14:25:04",
|
20
|
+
:to => "49170123456789",
|
21
|
+
}]
|
22
|
+
|
23
|
+
helper = Helper.new(Sms77::Resources::Journal)
|
24
|
+
res = helper.request(helper.resource.method(:retrieve), stub, { type: type })
|
25
|
+
|
26
|
+
expect(res).to be_a(Array)
|
27
|
+
|
28
|
+
res.each do |journal|
|
29
|
+
expect(journal).to be_a(Hash)
|
30
|
+
expect(journal[:from]).to be_lengthy_string
|
31
|
+
expect(journal[:id]).to be_numeric
|
32
|
+
expect(Sms77::Util::valid_float?(journal[:price])).to be_truthy
|
33
|
+
expect(journal[:text]).to be_lengthy_string
|
34
|
+
expect(valid_timestamp?(journal[:timestamp])).to be_truthy
|
35
|
+
expect(journal[:to]).to be_lengthy_string
|
36
|
+
end
|
37
|
+
|
38
|
+
res
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns all inbound messages' do
|
42
|
+
request(Sms77::Journal::Type::INBOUND)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns all outbound messages' do
|
46
|
+
request(Sms77::Journal::Type::OUTBOUND).each do |journal|
|
47
|
+
journal.merge!({
|
48
|
+
:connection => "http",
|
49
|
+
:dlr => "DELIVERED",
|
50
|
+
:dlr_timestamp => "2020-10-04 09:26:10.000",
|
51
|
+
:foreign_id => "MyForeignId",
|
52
|
+
:label => "MyCustomLabel",
|
53
|
+
:latency => "5.1060",
|
54
|
+
:mccmnc => "26207",
|
55
|
+
:type => "direct",
|
56
|
+
})
|
57
|
+
expect(journal[:connection]).to be_lengthy_string
|
58
|
+
expect(journal[:dlr]).to be_nil_or_lengthy_string
|
59
|
+
expect(valid_timestamp?(journal[:dlr_timestamp])).to be_truthy
|
60
|
+
expect(journal[:foreign_id]).to be_nil_or_lengthy_string
|
61
|
+
expect(journal[:label]).to be_nil_or_lengthy_string
|
62
|
+
expect(journal[:latency]).to be_nil_or_lengthy_string
|
63
|
+
expect(journal[:mccmnc]).to be_nil_or_lengthy_string
|
64
|
+
expect(Sms77::Util::in_module_constants?(journal[:type], Sms77::Sms::Type)).to be_truthy
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns all voice messages' do
|
69
|
+
request(Sms77::Journal::Type::VOICE).each do |journal|
|
70
|
+
journal.merge!({
|
71
|
+
:duration => "2",
|
72
|
+
:error => "",
|
73
|
+
:status => "completed",
|
74
|
+
:xml => false,
|
75
|
+
})
|
76
|
+
expect(journal[:duration]).to be_numeric
|
77
|
+
expect(journal[:error]).to be_nil_or_lengthy_string
|
78
|
+
expect(journal[:status]).to be_lengthy_string
|
79
|
+
expect(journal[:xml]).to be_boolean
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns all reply messages' do
|
84
|
+
request(Sms77::Journal::Type::REPLIES)
|
85
|
+
end
|
86
|
+
end
|