seven_api 0.5.0 → 0.6.1
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 +7 -6
- data/.idea/inspectionProfiles/Project_Default.xml +5 -5
- data/.idea/ruby-client.iml +51 -4
- data/Gemfile +2 -2
- data/LICENSE +21 -21
- data/README.md +3 -3
- data/Rakefile +5 -5
- data/doc/{Sms77 → SevenApi}/Client.html +229 -229
- data/doc/{Sms77 → SevenApi}/Contacts/Action.html +130 -130
- data/doc/{Sms77 → SevenApi}/Contacts.html +125 -125
- data/doc/{Sms77 → SevenApi}/Endpoint.html +186 -186
- data/doc/{Sms77 → SevenApi}/Hooks/Action.html +130 -130
- data/doc/{Sms77 → SevenApi}/Hooks/EventType.html +145 -145
- data/doc/{Sms77 → SevenApi}/Hooks/RequestMethod.html +130 -130
- data/doc/{Sms77 → SevenApi}/Hooks/Validator.html +597 -597
- data/doc/{Sms77 → SevenApi}/Hooks.html +125 -125
- data/doc/{Sms77 → SevenApi}/Journal/Type.html +135 -135
- data/doc/{Sms77 → SevenApi}/Journal/Validator.html +393 -393
- data/doc/{Sms77 → SevenApi}/Journal.html +125 -125
- data/doc/{Sms77 → SevenApi}/Lookup/Type.html +135 -135
- data/doc/{Sms77 → SevenApi}/Lookup.html +125 -125
- data/doc/{Sms77 → SevenApi}/Resource.html +869 -869
- data/doc/{Sms77 → SevenApi}/Resources/Analytics.html +262 -262
- data/doc/{Sms77 → SevenApi}/Resources/Balance.html +245 -245
- data/doc/{Sms77 → SevenApi}/Resources/Contacts.html +448 -448
- data/doc/{Sms77 → SevenApi}/Resources/Hooks.html +456 -456
- data/doc/{Sms77 → SevenApi}/Resources/Journal.html +260 -260
- data/doc/{Sms77 → SevenApi}/Resources/Lookup.html +539 -539
- data/doc/{Sms77 → SevenApi}/Resources/Pricing.html +262 -262
- data/doc/{Sms77 → SevenApi}/Resources/Sms.html +260 -260
- data/doc/{Sms77 → SevenApi}/Resources/Status.html +260 -260
- data/doc/{Sms77 → SevenApi}/Resources/Subaccounts.html +650 -650
- data/doc/{Sms77 → SevenApi}/Resources/ValidateForVoice.html +260 -260
- data/doc/{Sms77 → SevenApi}/Resources/Voice.html +260 -260
- data/doc/SevenApi/Resources.html +128 -0
- data/doc/{Sms77 → SevenApi}/Sms/Type.html +125 -125
- data/doc/{Sms77 → SevenApi}/Sms.html +125 -125
- data/doc/{Sms77 → SevenApi}/Subaccounts/Action.html +140 -140
- data/doc/SevenApi/Subaccounts/Validator.html +490 -0
- data/doc/{Sms77 → SevenApi}/Subaccounts.html +125 -125
- data/doc/{Sms77 → SevenApi}/Util.html +1032 -1032
- data/doc/{Sms77.html → SevenApi.html} +145 -145
- data/doc/_index.html +443 -443
- data/doc/class_list.html +51 -51
- data/doc/css/full_list.css +58 -58
- data/doc/css/style.css +497 -497
- data/doc/file.README.html +110 -111
- data/doc/file_list.html +56 -56
- data/doc/frames.html +17 -17
- data/doc/index.html +110 -111
- data/doc/js/app.js +314 -314
- data/doc/js/full_list.js +216 -216
- data/doc/js/jquery.js +3 -3
- data/doc/method_list.html +563 -563
- data/doc/top-level-namespace.html +109 -109
- data/document.sh +3 -0
- data/lib/seven_api/client.rb +32 -30
- data/lib/seven_api/contacts.rb +5 -10
- data/lib/seven_api/endpoint.rb +5 -0
- data/lib/seven_api/hooks.rb +69 -67
- data/lib/seven_api/journal.rb +39 -39
- data/lib/seven_api/lookup.rb +12 -11
- data/lib/seven_api/numbers.rb +9 -0
- data/lib/seven_api/paginated.rb +10 -0
- data/lib/seven_api/rcs.rb +9 -0
- data/lib/seven_api/resource.rb +8 -4
- data/lib/seven_api/resources/analytics.rb +54 -21
- data/lib/seven_api/resources/balance.rb +19 -19
- data/lib/seven_api/resources/contacts.rb +56 -38
- data/lib/seven_api/resources/groups.rb +57 -0
- data/lib/seven_api/resources/hooks.rb +40 -40
- data/lib/seven_api/resources/journal.rb +20 -20
- data/lib/seven_api/resources/lookup.rb +63 -47
- data/lib/seven_api/resources/numbers.rb +71 -0
- data/lib/seven_api/resources/pricing.rb +20 -20
- data/lib/seven_api/resources/rcs.rb +39 -0
- data/lib/seven_api/resources/sms.rb +29 -20
- data/lib/seven_api/resources/status.rb +20 -20
- data/lib/seven_api/resources/subaccounts.rb +65 -65
- data/lib/seven_api/resources/validate_for_voice.rb +20 -20
- data/lib/seven_api/resources/voice.rb +29 -20
- data/lib/seven_api/sms.rb +9 -9
- data/lib/seven_api/subaccounts.rb +55 -55
- data/lib/seven_api/util.rb +68 -68
- data/lib/seven_api/version.rb +5 -5
- data/lib/seven_api.rb +6 -6
- data/release.sh +4 -4
- data/seven_api.gemspec +5 -5
- data/spec/EnvKeyStore.rb +14 -14
- data/spec/matchers.rb +22 -22
- data/spec/seven_api/analytics_spec.rb +49 -0
- data/spec/seven_api/balance_spec.rb +18 -12
- data/spec/seven_api/client_spec.rb +15 -15
- data/spec/seven_api/contacts_spec.rb +100 -129
- data/spec/seven_api/groups_spec.rb +74 -0
- data/spec/seven_api/hooks_spec.rb +108 -108
- data/spec/seven_api/instance_spec.rb +22 -22
- data/spec/seven_api/journal_spec.rb +86 -86
- data/spec/seven_api/lookup_spec.rb +197 -179
- data/spec/seven_api/numbers_spec.rb +135 -0
- data/spec/seven_api/pricing_spec.rb +76 -76
- data/spec/seven_api/rcs_spec.rb +99 -0
- data/spec/seven_api/sms_spec.rb +103 -103
- data/spec/seven_api/subaccounts_spec.rb +121 -121
- data/spec/seven_api/validate_for_voice_spec.rb +19 -19
- data/spec/seven_api/voice_spec.rb +51 -51
- data/spec/seven_api_spec.rb +9 -9
- data/spec/spec_helper.rb +8 -17
- metadata +62 -50
- data/doc/Sms77/Resources.html +0 -128
- data/doc/Sms77/Subaccounts/Validator.html +0 -490
@@ -1,21 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/resource'
|
4
|
-
|
5
|
-
# This module exposes the methods for communicating with the API endpoint /sms.
|
6
|
-
module SevenApi::Resources
|
7
|
-
class Sms < SevenApi::Resource
|
8
|
-
@endpoint = SevenApi::Endpoint::SMS
|
9
|
-
@http_methods = {
|
10
|
-
:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/resource'
|
4
|
+
|
5
|
+
# This module exposes the methods for communicating with the API endpoint /sms.
|
6
|
+
module SevenApi::Resources
|
7
|
+
class Sms < SevenApi::Resource
|
8
|
+
@endpoint = SevenApi::Endpoint::SMS
|
9
|
+
@http_methods = {
|
10
|
+
:delete => :delete,
|
11
|
+
:retrieve => :post,
|
12
|
+
}
|
13
|
+
|
14
|
+
# Delete SMS
|
15
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/sms#delete-sms
|
16
|
+
# @param ids [Array]
|
17
|
+
# @return [Hash]
|
18
|
+
def delete(ids)
|
19
|
+
request(:delete, ids)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Send SMS
|
23
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/sms#send-sms
|
24
|
+
# @param params [Hash]
|
25
|
+
# @return [Integer,String,Hash]
|
26
|
+
def retrieve(params)
|
27
|
+
request(:post, params)
|
28
|
+
end
|
29
|
+
end
|
21
30
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/resource'
|
4
|
-
|
5
|
-
# This module exposes the methods for communicating with the API endpoint /status.
|
6
|
-
module SevenApi::Resources
|
7
|
-
class Status < SevenApi::Resource
|
8
|
-
@endpoint = SevenApi::Endpoint::STATUS
|
9
|
-
@http_methods = {
|
10
|
-
:retrieve => :get,
|
11
|
-
}
|
12
|
-
|
13
|
-
# Retrieve delivery report for a SMS
|
14
|
-
# read more: https://
|
15
|
-
# @param params [Hash]
|
16
|
-
# @return [String]
|
17
|
-
def retrieve(params)
|
18
|
-
request(params)
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/resource'
|
4
|
+
|
5
|
+
# This module exposes the methods for communicating with the API endpoint /status.
|
6
|
+
module SevenApi::Resources
|
7
|
+
class Status < SevenApi::Resource
|
8
|
+
@endpoint = SevenApi::Endpoint::STATUS
|
9
|
+
@http_methods = {
|
10
|
+
:retrieve => :get,
|
11
|
+
}
|
12
|
+
|
13
|
+
# Retrieve delivery report for a SMS
|
14
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/status-reports#query-status-reports
|
15
|
+
# @param params [Hash]
|
16
|
+
# @return [String]
|
17
|
+
def retrieve(params)
|
18
|
+
request(:get, params)
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/resource'
|
4
|
-
require 'seven_api/subaccounts'
|
5
|
-
|
6
|
-
# This module exposes the methods for communicating with the API endpoint /subaccounts.
|
7
|
-
module SevenApi::Resources
|
8
|
-
class Subaccounts < SevenApi::Resource
|
9
|
-
@endpoint = SevenApi::Endpoint::SUBACCOUNTS
|
10
|
-
@http_methods = {
|
11
|
-
:create => :post,
|
12
|
-
:delete => :post,
|
13
|
-
:read => :get,
|
14
|
-
:transfer_credits => :post,
|
15
|
-
:update => :post,
|
16
|
-
}
|
17
|
-
|
18
|
-
# Create a subaccount
|
19
|
-
# read more: https://
|
20
|
-
# @param params [Hash]
|
21
|
-
# @return [Hash]
|
22
|
-
def create(params)
|
23
|
-
SevenApi::Subaccounts::Validator::create(params)
|
24
|
-
|
25
|
-
request(params.merge({ :action => SevenApi::Subaccounts::Action::CREATE }))
|
26
|
-
end
|
27
|
-
|
28
|
-
# Delete a subaccount
|
29
|
-
# read more: https://
|
30
|
-
# @param params [Hash]
|
31
|
-
# @return [Hash]
|
32
|
-
def delete(params)
|
33
|
-
SevenApi::Subaccounts::Validator::delete(params)
|
34
|
-
|
35
|
-
request(params.merge({ :action => SevenApi::Subaccounts::Action::DELETE }))
|
36
|
-
end
|
37
|
-
|
38
|
-
# Retrieve all subaccounts
|
39
|
-
# read more: https://
|
40
|
-
# @param params [Hash]
|
41
|
-
# @return [Hash]
|
42
|
-
def read(params = {})
|
43
|
-
request({}, params.merge({ :action => SevenApi::Subaccounts::Action::READ }))
|
44
|
-
end
|
45
|
-
|
46
|
-
# Transfer credits to a subaccount
|
47
|
-
# read more: https://
|
48
|
-
# @param params [Hash]
|
49
|
-
# @return [Hash]
|
50
|
-
def transfer_credits(params)
|
51
|
-
SevenApi::Subaccounts::Validator::transfer_credits(params)
|
52
|
-
|
53
|
-
request(params.merge({ :action => SevenApi::Subaccounts::Action::TRANSFER_CREDITS }))
|
54
|
-
end
|
55
|
-
|
56
|
-
# Update automatic charging of a subaccount
|
57
|
-
# read more: https://
|
58
|
-
# @param params [Hash]
|
59
|
-
# @return [Hash]
|
60
|
-
def update(params)
|
61
|
-
SevenApi::Subaccounts::Validator::update(params)
|
62
|
-
|
63
|
-
request(params.merge({ :action => SevenApi::Subaccounts::Action::UPDATE }))
|
64
|
-
end
|
65
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/resource'
|
4
|
+
require 'seven_api/subaccounts'
|
5
|
+
|
6
|
+
# This module exposes the methods for communicating with the API endpoint /subaccounts.
|
7
|
+
module SevenApi::Resources
|
8
|
+
class Subaccounts < SevenApi::Resource
|
9
|
+
@endpoint = SevenApi::Endpoint::SUBACCOUNTS
|
10
|
+
@http_methods = {
|
11
|
+
:create => :post,
|
12
|
+
:delete => :post,
|
13
|
+
:read => :get,
|
14
|
+
:transfer_credits => :post,
|
15
|
+
:update => :post,
|
16
|
+
}
|
17
|
+
|
18
|
+
# Create a subaccount
|
19
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#create-subaccount
|
20
|
+
# @param params [Hash]
|
21
|
+
# @return [Hash]
|
22
|
+
def create(params)
|
23
|
+
SevenApi::Subaccounts::Validator::create(params)
|
24
|
+
|
25
|
+
request(:post, params.merge({ :action => SevenApi::Subaccounts::Action::CREATE }))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Delete a subaccount
|
29
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#delete-a-subaccount
|
30
|
+
# @param params [Hash]
|
31
|
+
# @return [Hash]
|
32
|
+
def delete(params)
|
33
|
+
SevenApi::Subaccounts::Validator::delete(params)
|
34
|
+
|
35
|
+
request(:post, params.merge({ :action => SevenApi::Subaccounts::Action::DELETE }))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieve all subaccounts
|
39
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#list-subaccounts
|
40
|
+
# @param params [Hash]
|
41
|
+
# @return [Hash]
|
42
|
+
def read(params = {})
|
43
|
+
request(:get, {}, params.merge({ :action => SevenApi::Subaccounts::Action::READ }))
|
44
|
+
end
|
45
|
+
|
46
|
+
# Transfer credits to a subaccount
|
47
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#manual-credit-transfer
|
48
|
+
# @param params [Hash]
|
49
|
+
# @return [Hash]
|
50
|
+
def transfer_credits(params)
|
51
|
+
SevenApi::Subaccounts::Validator::transfer_credits(params)
|
52
|
+
|
53
|
+
request(:post, params.merge({ :action => SevenApi::Subaccounts::Action::TRANSFER_CREDITS }))
|
54
|
+
end
|
55
|
+
|
56
|
+
# Update automatic charging of a subaccount
|
57
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/subaccounts#automatic-credit-transfer
|
58
|
+
# @param params [Hash]
|
59
|
+
# @return [Hash]
|
60
|
+
def update(params)
|
61
|
+
SevenApi::Subaccounts::Validator::update(params)
|
62
|
+
|
63
|
+
request(:post, params.merge({ :action => SevenApi::Subaccounts::Action::UPDATE }))
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/resource'
|
4
|
-
|
5
|
-
# This module exposes the methods for communicating with the API endpoint /validate_for_voice.
|
6
|
-
module SevenApi::Resources
|
7
|
-
class ValidateForVoice < SevenApi::Resource
|
8
|
-
@endpoint = SevenApi::Endpoint::VALIDATE_FOR_VOICE
|
9
|
-
@http_methods = {
|
10
|
-
:retrieve => :post,
|
11
|
-
}
|
12
|
-
|
13
|
-
# Validate a phone number for using it as caller ID via our voice API
|
14
|
-
# read more: https://
|
15
|
-
# @param params [Hash]
|
16
|
-
# @return [Hash]
|
17
|
-
def retrieve(params)
|
18
|
-
request(params)
|
19
|
-
end
|
20
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/resource'
|
4
|
+
|
5
|
+
# This module exposes the methods for communicating with the API endpoint /validate_for_voice.
|
6
|
+
module SevenApi::Resources
|
7
|
+
class ValidateForVoice < SevenApi::Resource
|
8
|
+
@endpoint = SevenApi::Endpoint::VALIDATE_FOR_VOICE
|
9
|
+
@http_methods = {
|
10
|
+
:retrieve => :post,
|
11
|
+
}
|
12
|
+
|
13
|
+
# Validate a phone number for using it as caller ID via our voice API
|
14
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/sender-identifiers#validate-sender-for-voice
|
15
|
+
# @param params [Hash]
|
16
|
+
# @return [Hash]
|
17
|
+
def retrieve(params)
|
18
|
+
request(:post, params)
|
19
|
+
end
|
20
|
+
end
|
21
21
|
end
|
@@ -1,21 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/resource'
|
4
|
-
|
5
|
-
# This module exposes the methods for communicating with the API endpoint /voice.
|
6
|
-
module SevenApi::Resources
|
7
|
-
class Voice < SevenApi::Resource
|
8
|
-
@endpoint = SevenApi::Endpoint::VOICE
|
9
|
-
@http_methods = {
|
10
|
-
:
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/resource'
|
4
|
+
|
5
|
+
# This module exposes the methods for communicating with the API endpoint /voice.
|
6
|
+
module SevenApi::Resources
|
7
|
+
class Voice < SevenApi::Resource
|
8
|
+
@endpoint = SevenApi::Endpoint::VOICE
|
9
|
+
@http_methods = {
|
10
|
+
:hangup => :post,
|
11
|
+
:send => :post,
|
12
|
+
}
|
13
|
+
|
14
|
+
# This endpoint ends an active call. Only calls with the status in-progress can be ended.
|
15
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/voice#hangup-a-call
|
16
|
+
# @param call_id [String]
|
17
|
+
# @return Hash
|
18
|
+
def hangup(call_id)
|
19
|
+
request(:post, {}, {}, "/#{call_id}/hangup")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Convert text to speech, call number and read voice message out loud.
|
23
|
+
# read more: https://docs.seven.io/en/rest-api/endpoints/voice#send-voice-call
|
24
|
+
# @param params [Hash]
|
25
|
+
# @return [String,Hash]
|
26
|
+
def send(params)
|
27
|
+
request(:post, params)
|
28
|
+
end
|
29
|
+
end
|
21
30
|
end
|
data/lib/seven_api/sms.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# This module holds all utilities related to the /sms endpoint.
|
4
|
-
module SevenApi::Sms
|
5
|
-
module Type
|
6
|
-
DIRECT = 'direct'
|
7
|
-
ECONOMY = 'economy'
|
8
|
-
end
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module holds all utilities related to the /sms endpoint.
|
4
|
+
module SevenApi::Sms
|
5
|
+
module Type
|
6
|
+
DIRECT = 'direct'
|
7
|
+
ECONOMY = 'economy'
|
8
|
+
end
|
9
|
+
end
|
@@ -1,55 +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
|
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
|
data/lib/seven_api/util.rb
CHANGED
@@ -1,69 +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
|
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
69
|
end
|
data/lib/seven_api/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SevenApi
|
4
|
-
VERSION = '0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SevenApi
|
4
|
+
VERSION = '0.6.1'
|
5
|
+
end
|
data/lib/seven_api.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'seven_api/version'
|
4
|
-
|
5
|
-
module SevenApi
|
6
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'seven_api/version'
|
4
|
+
|
5
|
+
module SevenApi
|
6
|
+
end
|
data/release.sh
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
gem build --strict
|
4
|
-
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
gem build --strict
|
4
|
+
|
5
5
|
gem push "$(find . -name "*.gem" -print0 | xargs -r -0 ls -1 -t | head -1)"
|
data/seven_api.gemspec
CHANGED
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'seven_api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
8
|
-
spec.add_development_dependency 'rake', '~> 13.
|
9
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
10
|
-
spec.add_runtime_dependency 'faraday', '~>
|
7
|
+
spec.add_development_dependency 'bundler', '~> 2.4'
|
8
|
+
spec.add_development_dependency 'rake', '~> 13.1'
|
9
|
+
spec.add_development_dependency 'rspec', '~> 3.13'
|
10
|
+
spec.add_runtime_dependency 'faraday', '~> 2.9'
|
11
11
|
spec.author = 'seven communications GmbH & Co. KG'
|
12
12
|
spec.description = 'Send SMS & text-to-speech messages via the seven SMS Gateway.'
|
13
13
|
spec.email = 'support@seven.io'
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.homepage = 'https://github.com/seven-io/ruby-client'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
spec.name = 'seven_api'
|
18
|
-
spec.required_ruby_version = '>=
|
18
|
+
spec.required_ruby_version = '>= 3.1.0'
|
19
19
|
spec.summary = 'Official API Client for the seven SMS Gateway'
|
20
20
|
spec.test_files = Dir['spec/**/*']
|
21
21
|
spec.version = SevenApi::VERSION
|