seven_api 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 +7 -0
- data/.gitignore +6 -0
- 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 +3 -0
- data/LICENSE +22 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- 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/seven_api/client.rb +30 -0
- data/lib/seven_api/contacts.rb +10 -0
- data/lib/seven_api/endpoint.rb +17 -0
- data/lib/seven_api/hooks.rb +67 -0
- data/lib/seven_api/journal.rb +39 -0
- data/lib/seven_api/lookup.rb +11 -0
- data/lib/seven_api/resource.rb +94 -0
- data/lib/seven_api/resources/analytics.rb +21 -0
- data/lib/seven_api/resources/balance.rb +20 -0
- data/lib/seven_api/resources/contacts.rb +39 -0
- data/lib/seven_api/resources/hooks.rb +41 -0
- data/lib/seven_api/resources/journal.rb +21 -0
- data/lib/seven_api/resources/lookup.rb +48 -0
- data/lib/seven_api/resources/pricing.rb +21 -0
- data/lib/seven_api/resources/sms.rb +21 -0
- data/lib/seven_api/resources/status.rb +21 -0
- data/lib/seven_api/resources/subaccounts.rb +66 -0
- data/lib/seven_api/resources/validate_for_voice.rb +21 -0
- data/lib/seven_api/resources/voice.rb +21 -0
- data/lib/seven_api/sms.rb +9 -0
- data/lib/seven_api/subaccounts.rb +55 -0
- data/lib/seven_api/util.rb +69 -0
- data/lib/seven_api/version.rb +5 -0
- data/lib/seven_api.rb +6 -0
- data/release.sh +5 -0
- data/seven_api.gemspec +22 -0
- data/spec/EnvKeyStore.rb +15 -0
- data/spec/matchers.rb +23 -0
- data/spec/seven_api/balance_spec.rb +12 -0
- data/spec/seven_api/client_spec.rb +15 -0
- data/spec/seven_api/contacts_spec.rb +129 -0
- data/spec/seven_api/hooks_spec.rb +109 -0
- data/spec/seven_api/instance_spec.rb +22 -0
- data/spec/seven_api/journal_spec.rb +86 -0
- data/spec/seven_api/lookup_spec.rb +179 -0
- data/spec/seven_api/pricing_spec.rb +76 -0
- data/spec/seven_api/sms_spec.rb +103 -0
- data/spec/seven_api/subaccounts_spec.rb +121 -0
- data/spec/seven_api/validate_for_voice_spec.rb +19 -0
- data/spec/seven_api/voice_spec.rb +51 -0
- data/spec/seven_api_spec.rb +9 -0
- data/spec/spec_helper.rb +53 -0
- metadata +215 -0
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module holds all utilities related to the /subaccounts endpoint.
|
4
|
+
module SevenApi::Subaccounts
|
5
|
+
module Action
|
6
|
+
CREATE = 'create'
|
7
|
+
DELETE = 'delete'
|
8
|
+
READ = 'read'
|
9
|
+
TRANSFER_CREDITS = 'transfer_credits'
|
10
|
+
UPDATE = 'update'
|
11
|
+
end
|
12
|
+
|
13
|
+
module Validator
|
14
|
+
def self.is_action?(str)
|
15
|
+
SevenApi::Util::in_module_constants?(str, SevenApi::Subaccounts::Action)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.validate(params)
|
19
|
+
action = params[:action]
|
20
|
+
|
21
|
+
case action
|
22
|
+
when SevenApi::Subaccounts::Action::CREATE
|
23
|
+
raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::create(params)
|
24
|
+
when SevenApi::Subaccounts::Action::DELETE
|
25
|
+
raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::delete(params)
|
26
|
+
when SevenApi::Subaccounts::Action::TRANSFER_CREDITS
|
27
|
+
raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::transfer_credits(params)
|
28
|
+
when SevenApi::Subaccounts::Action::UPDATE
|
29
|
+
raise 'Parameter validation failed' unless SevenApi::Subaccounts::Validator::update(params)
|
30
|
+
else
|
31
|
+
raise "Unknown action #{action}" unless SevenApi::Subaccounts::Validator::is_action?(action)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.create(params)
|
36
|
+
SevenApi::Util::lengthy_string?(params[:email]) &&
|
37
|
+
SevenApi::Util::lengthy_string?(params[:name])
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.delete(params)
|
41
|
+
SevenApi::Util::is_positive_integer?(params[:id])
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.transfer_credits(params)
|
45
|
+
SevenApi::Util::is_positive_integer?(params[:amount]) &&
|
46
|
+
SevenApi::Util::is_positive_integer?(params[:id])
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.update(params)
|
50
|
+
SevenApi::Util::is_positive_integer?(params[:amount]) &&
|
51
|
+
SevenApi::Util::is_positive_integer?(params[:id]) &&
|
52
|
+
SevenApi::Util::is_positive_integer?(params[:threshold])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
# This module exposes general utilities used throughout the library.
|
4
|
+
module SevenApi::Util
|
5
|
+
def self.to_numbered_bool(val)
|
6
|
+
if true == val
|
7
|
+
return 1
|
8
|
+
elsif false == val
|
9
|
+
return 0
|
10
|
+
end
|
11
|
+
|
12
|
+
return val
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_namespace_members_by_type(ns, type)
|
16
|
+
ns.constants.map(&ns.method(:const_get)).grep(type)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_namespace_classes(ns)
|
20
|
+
return self.get_namespace_members_by_type(ns, Class)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.get_module_constant_values(mod)
|
24
|
+
mod.constants(false).map &mod.method(:const_get)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.is_valid_url?(str)
|
28
|
+
str =~ URI::regexp
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.is_valid_datetime?(str)
|
32
|
+
begin
|
33
|
+
DateTime.parse(str)
|
34
|
+
true
|
35
|
+
rescue ArgumentError
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.is_positive_integer?(val)
|
41
|
+
/\A\d+\z/.match?(val.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.in_module_constants?(needle, mod)
|
45
|
+
get_module_constant_values(mod).include?(needle)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.valid_float?(str)
|
49
|
+
!!Float(str) rescue false
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.numeric?(val)
|
53
|
+
return true if val.is_a?(Integer)
|
54
|
+
|
55
|
+
val.scan(/\D/).empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.boolean?(val)
|
59
|
+
[true, false].include? val
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.nil_or_lengthy_string?(val)
|
63
|
+
val.nil? || (val.is_a?(String) && val.length)
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.lengthy_string?(val)
|
67
|
+
return val.is_a?(String) && !val.empty?
|
68
|
+
end
|
69
|
+
end
|
data/lib/seven_api.rb
ADDED
data/release.sh
ADDED
data/seven_api.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'seven_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
8
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
9
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
10
|
+
spec.add_runtime_dependency 'faraday', '~> 1.1'
|
11
|
+
spec.author = 'seven communications GmbH & Co. KG'
|
12
|
+
spec.description = 'Send SMS & text-to-speech messages via the seven SMS Gateway.'
|
13
|
+
spec.email = 'support@seven.io'
|
14
|
+
spec.files = `git ls-files`.split("\n")
|
15
|
+
spec.homepage = 'https://github.com/seven-io/ruby-client'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.name = 'seven_api'
|
18
|
+
spec.required_ruby_version = '>= 2.6.0'
|
19
|
+
spec.summary = 'Official API Client for the seven SMS Gateway'
|
20
|
+
spec.test_files = Dir['spec/**/*']
|
21
|
+
spec.version = SevenApi::VERSION
|
22
|
+
end
|
data/spec/EnvKeyStore.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class EnvKeyStore
|
2
|
+
def initialize(key)
|
3
|
+
@key = "SEVEN_TEST_#{key}"
|
4
|
+
|
5
|
+
@store = ENV[@key]
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(fallback = nil)
|
9
|
+
@store.nil? ? fallback : @store
|
10
|
+
end
|
11
|
+
|
12
|
+
def set(val, only_on_nil = false)
|
13
|
+
@store = val unless only_on_nil
|
14
|
+
end
|
15
|
+
end
|
data/spec/matchers.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
RSpec::Matchers.define :be_nil_or_lengthy_string do
|
2
|
+
match do |val|
|
3
|
+
SevenApi::Util::nil_or_lengthy_string?(val)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
RSpec::Matchers.define :be_boolean do
|
8
|
+
match do |val|
|
9
|
+
SevenApi::Util::boolean?(val)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec::Matchers.define :be_numeric do
|
14
|
+
match do |val|
|
15
|
+
SevenApi::Util::numeric?(val)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec::Matchers.define :be_lengthy_string do
|
20
|
+
match do |val|
|
21
|
+
SevenApi::Util::lengthy_string?(val)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/resources/balance'
|
5
|
+
|
6
|
+
RSpec.describe SevenApi, 'balance' do
|
7
|
+
it 'returns the account balance' do
|
8
|
+
helper = Helper.new(SevenApi::Resources::Balance)
|
9
|
+
balance = helper.request(helper.resource.method(:retrieve), 155.55)
|
10
|
+
expect(balance).to be_a(Float)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/client'
|
5
|
+
require 'seven_api/resource'
|
6
|
+
|
7
|
+
RSpec.describe SevenApi, 'client' do
|
8
|
+
it 'should contain all resource modules' do
|
9
|
+
client = SevenApi::Client.new(SevenApi::Resource.new('x'))
|
10
|
+
|
11
|
+
client.instance_variables.each do |var|
|
12
|
+
expect(SevenApi::Resources.const_get(client.instance_variable_get(var).class.name)).to be_truthy
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/contacts'
|
5
|
+
require 'seven_api/resources/contacts'
|
6
|
+
|
7
|
+
RSpec.describe SevenApi, 'contacts' do
|
8
|
+
$new_contact_id = nil
|
9
|
+
|
10
|
+
def assert_new(response_body)
|
11
|
+
if response_body.is_a?(String)
|
12
|
+
code, $new_contact_id = response_body.split("\n")
|
13
|
+
$new_contact_id = $new_contact_id.to_i
|
14
|
+
else
|
15
|
+
code = response_body[:return]
|
16
|
+
$new_contact_id = response_body[:id]
|
17
|
+
end
|
18
|
+
|
19
|
+
expect(code).to be_numeric
|
20
|
+
expect($new_contact_id).to be_an_instance_of(Integer)
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_contact(contact)
|
24
|
+
if contact.is_a?(String)
|
25
|
+
id, name, number = contact.split(';')
|
26
|
+
|
27
|
+
id = id.gsub('"', '')
|
28
|
+
name = name.gsub('"', '')
|
29
|
+
number = number.gsub('"', '')
|
30
|
+
else
|
31
|
+
id = contact[:ID]
|
32
|
+
name = contact[:Name]
|
33
|
+
number = contact[:Number]
|
34
|
+
end
|
35
|
+
|
36
|
+
expect(id).to be_numeric
|
37
|
+
expect(name).to be_an_instance_of(String)
|
38
|
+
expect(number.sub('+', '')).to be_numeric
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns all contacts as CSV' do
|
42
|
+
stub = <<~CSV
|
43
|
+
"4848436";"";""
|
44
|
+
"4848437";"";""
|
45
|
+
"4848433";"Alf Albert";"007"
|
46
|
+
"3172517";"BNN Nolte";"004911112"
|
47
|
+
"4848434";"Harry Harald";"0049123456"
|
48
|
+
"4848431";"Karl Konrad";"00123456"
|
49
|
+
"4848432";"Petra Pan";"00513414"
|
50
|
+
"2925186";"Tom Tester";"004901234567890"
|
51
|
+
CSV
|
52
|
+
|
53
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
54
|
+
body = helper.request(helper.resource.method(:read), stub)
|
55
|
+
|
56
|
+
expect(body).to be_a(String)
|
57
|
+
|
58
|
+
body.split("\n").each do |contact|
|
59
|
+
assert_contact(contact)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns all contacts as JSON' do
|
64
|
+
stub = [
|
65
|
+
{ ID: '4848436', Name: '', Number: '' },
|
66
|
+
{ ID: '4848437', Name: '', Number: '' },
|
67
|
+
{ ID: '4848433', Name: 'Alf Albert', Number: '007' },
|
68
|
+
{ ID: '3172517', Name: 'BNN Nolte', Number: '004911112' },
|
69
|
+
{ ID: '4848434', Name: 'Harry Harald', Number: '0049123456' },
|
70
|
+
{ ID: '4848431', Name: 'Karl Konrad', Number: '00123456' },
|
71
|
+
{ ID: '4848432', Name: 'Petra Pan', Number: '00513414' },
|
72
|
+
{ ID: '2925186', Name: 'Tom Tester', Number: '004901234567890' }
|
73
|
+
]
|
74
|
+
|
75
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
76
|
+
body = helper.request(helper.resource.method(:read), stub, { json: true })
|
77
|
+
|
78
|
+
expect(body).to be_a(Array)
|
79
|
+
|
80
|
+
body.each do |contact|
|
81
|
+
assert_contact(contact)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'creates a contact and returns its ID as TEXT' do
|
86
|
+
stub = <<~TEXT
|
87
|
+
152
|
88
|
+
4868400
|
89
|
+
TEXT
|
90
|
+
|
91
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
92
|
+
body = helper.request(helper.resource.method(:write), stub, {})
|
93
|
+
|
94
|
+
expect(body).to be_a(String)
|
95
|
+
|
96
|
+
assert_new(body)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'deletes a contact with given ID and return code' do
|
100
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
101
|
+
expect(helper.request(helper.resource.method(:delete), 152, { id: $new_contact_id })).to be_a(Integer)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'creates a contact and returns its ID as JSON' do
|
105
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
106
|
+
body = helper.request(helper.resource.method(:write), { id: 4868401, return: '152' }, { json: true })
|
107
|
+
|
108
|
+
expect(body).to be_a(Hash)
|
109
|
+
|
110
|
+
assert_new(body)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'deletes a contact with given ID and return code as JSON' do
|
114
|
+
helper = Helper.new(SevenApi::Resources::Contacts)
|
115
|
+
body = helper.request(
|
116
|
+
helper.resource.method(:delete),
|
117
|
+
{
|
118
|
+
return: '152'
|
119
|
+
},
|
120
|
+
{
|
121
|
+
id: $new_contact_id,
|
122
|
+
json: true,
|
123
|
+
}
|
124
|
+
)
|
125
|
+
|
126
|
+
expect(body).to be_a(Hash)
|
127
|
+
expect(body[:return]).to be_a(String)
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'seven_api/hooks'
|
6
|
+
require 'seven_api/util'
|
7
|
+
require 'seven_api/resources/hooks'
|
8
|
+
|
9
|
+
RSpec.describe SevenApi, '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(SevenApi::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(SevenApi::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(SevenApi::Hooks::Validator::event_type?(hook[:event_type])).to be
|
62
|
+
expect(SevenApi::Util::is_positive_integer?(hook[:id])).to be
|
63
|
+
expect(SevenApi::Hooks::Validator::request_method?(hook[:request_method])).to be
|
64
|
+
expect(SevenApi::Hooks::Validator::target_url?(hook[:target_url])).to be
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
=begin
|
69
|
+
it 'subscribes' do
|
70
|
+
helper = Helper.new(Seven::Resources::Hooks)
|
71
|
+
stub = alter_action_stub.merge({ :id => rand(1...1000000) })
|
72
|
+
|
73
|
+
res = request(helper.resource.method(:subscribe), stub, {
|
74
|
+
:event_type => Seven::Hooks::EventType::NEW_INBOUND_SMS,
|
75
|
+
:request_method => Seven::Hooks::RequestMethod::GET,
|
76
|
+
:target_url => "http://ruby.tld/#{SecureRandom.uuid}"
|
77
|
+
})
|
78
|
+
|
79
|
+
expect(Seven::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(Seven::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
|
109
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#noinspection RubyResolve
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'seven_api/resource'
|
6
|
+
|
7
|
+
#noinspection RubyResolve
|
8
|
+
RSpec.describe SevenApi, 'instance' do
|
9
|
+
helper = Helper.new(SevenApi::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 { SevenApi::Resource.new('') }.to raise_error(RuntimeError)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'seven_api/journal'
|
5
|
+
require 'seven_api/resources/journal'
|
6
|
+
require 'seven_api/sms'
|
7
|
+
|
8
|
+
RSpec.describe SevenApi, '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(SevenApi::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(SevenApi::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(SevenApi::Journal::Type::INBOUND)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns all outbound messages' do
|
46
|
+
request(SevenApi::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(SevenApi::Util::in_module_constants?(journal[:type], SevenApi::Sms::Type)).to be_truthy
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns all voice messages' do
|
69
|
+
request(SevenApi::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(SevenApi::Journal::Type::REPLIES)
|
85
|
+
end
|
86
|
+
end
|