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.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.idea/.gitignore +8 -0
  4. data/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. data/.idea/modules.xml +8 -0
  6. data/.idea/ruby-client.iml +18 -0
  7. data/.idea/vcs.xml +6 -0
  8. data/Gemfile +3 -0
  9. data/LICENSE +22 -0
  10. data/README.md +41 -0
  11. data/Rakefile +6 -0
  12. data/doc/Sms77/Client.html +230 -0
  13. data/doc/Sms77/Contacts/Action.html +131 -0
  14. data/doc/Sms77/Contacts.html +126 -0
  15. data/doc/Sms77/Endpoint.html +187 -0
  16. data/doc/Sms77/Hooks/Action.html +131 -0
  17. data/doc/Sms77/Hooks/EventType.html +146 -0
  18. data/doc/Sms77/Hooks/RequestMethod.html +131 -0
  19. data/doc/Sms77/Hooks/Validator.html +598 -0
  20. data/doc/Sms77/Hooks.html +126 -0
  21. data/doc/Sms77/Journal/Type.html +136 -0
  22. data/doc/Sms77/Journal/Validator.html +394 -0
  23. data/doc/Sms77/Journal.html +126 -0
  24. data/doc/Sms77/Lookup/Type.html +136 -0
  25. data/doc/Sms77/Lookup.html +126 -0
  26. data/doc/Sms77/Resource.html +870 -0
  27. data/doc/Sms77/Resources/Analytics.html +263 -0
  28. data/doc/Sms77/Resources/Balance.html +246 -0
  29. data/doc/Sms77/Resources/Contacts.html +449 -0
  30. data/doc/Sms77/Resources/Hooks.html +457 -0
  31. data/doc/Sms77/Resources/Journal.html +261 -0
  32. data/doc/Sms77/Resources/Lookup.html +540 -0
  33. data/doc/Sms77/Resources/Pricing.html +263 -0
  34. data/doc/Sms77/Resources/Sms.html +261 -0
  35. data/doc/Sms77/Resources/Status.html +261 -0
  36. data/doc/Sms77/Resources/Subaccounts.html +651 -0
  37. data/doc/Sms77/Resources/ValidateForVoice.html +261 -0
  38. data/doc/Sms77/Resources/Voice.html +261 -0
  39. data/doc/Sms77/Resources.html +128 -0
  40. data/doc/Sms77/Sms/Type.html +126 -0
  41. data/doc/Sms77/Sms.html +126 -0
  42. data/doc/Sms77/Subaccounts/Action.html +141 -0
  43. data/doc/Sms77/Subaccounts/Validator.html +490 -0
  44. data/doc/Sms77/Subaccounts.html +126 -0
  45. data/doc/Sms77/Util.html +1033 -0
  46. data/doc/Sms77.html +146 -0
  47. data/doc/_index.html +444 -0
  48. data/doc/class_list.html +51 -0
  49. data/doc/css/common.css +1 -0
  50. data/doc/css/full_list.css +58 -0
  51. data/doc/css/style.css +497 -0
  52. data/doc/file.README.html +112 -0
  53. data/doc/file_list.html +56 -0
  54. data/doc/frames.html +17 -0
  55. data/doc/index.html +112 -0
  56. data/doc/js/app.js +314 -0
  57. data/doc/js/full_list.js +216 -0
  58. data/doc/js/jquery.js +4 -0
  59. data/doc/method_list.html +563 -0
  60. data/doc/top-level-namespace.html +110 -0
  61. data/lib/seven_api/client.rb +30 -0
  62. data/lib/seven_api/contacts.rb +10 -0
  63. data/lib/seven_api/endpoint.rb +17 -0
  64. data/lib/seven_api/hooks.rb +67 -0
  65. data/lib/seven_api/journal.rb +39 -0
  66. data/lib/seven_api/lookup.rb +11 -0
  67. data/lib/seven_api/resource.rb +94 -0
  68. data/lib/seven_api/resources/analytics.rb +21 -0
  69. data/lib/seven_api/resources/balance.rb +20 -0
  70. data/lib/seven_api/resources/contacts.rb +39 -0
  71. data/lib/seven_api/resources/hooks.rb +41 -0
  72. data/lib/seven_api/resources/journal.rb +21 -0
  73. data/lib/seven_api/resources/lookup.rb +48 -0
  74. data/lib/seven_api/resources/pricing.rb +21 -0
  75. data/lib/seven_api/resources/sms.rb +21 -0
  76. data/lib/seven_api/resources/status.rb +21 -0
  77. data/lib/seven_api/resources/subaccounts.rb +66 -0
  78. data/lib/seven_api/resources/validate_for_voice.rb +21 -0
  79. data/lib/seven_api/resources/voice.rb +21 -0
  80. data/lib/seven_api/sms.rb +9 -0
  81. data/lib/seven_api/subaccounts.rb +55 -0
  82. data/lib/seven_api/util.rb +69 -0
  83. data/lib/seven_api/version.rb +5 -0
  84. data/lib/seven_api.rb +6 -0
  85. data/release.sh +5 -0
  86. data/seven_api.gemspec +22 -0
  87. data/spec/EnvKeyStore.rb +15 -0
  88. data/spec/matchers.rb +23 -0
  89. data/spec/seven_api/balance_spec.rb +12 -0
  90. data/spec/seven_api/client_spec.rb +15 -0
  91. data/spec/seven_api/contacts_spec.rb +129 -0
  92. data/spec/seven_api/hooks_spec.rb +109 -0
  93. data/spec/seven_api/instance_spec.rb +22 -0
  94. data/spec/seven_api/journal_spec.rb +86 -0
  95. data/spec/seven_api/lookup_spec.rb +179 -0
  96. data/spec/seven_api/pricing_spec.rb +76 -0
  97. data/spec/seven_api/sms_spec.rb +103 -0
  98. data/spec/seven_api/subaccounts_spec.rb +121 -0
  99. data/spec/seven_api/validate_for_voice_spec.rb +19 -0
  100. data/spec/seven_api/voice_spec.rb +51 -0
  101. data/spec/seven_api_spec.rb +9 -0
  102. data/spec/spec_helper.rb +53 -0
  103. metadata +215 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resources/analytics'
4
+ require 'seven_api/resources/balance'
5
+ require 'seven_api/resources/contacts'
6
+ require 'seven_api/resources/hooks'
7
+ require 'seven_api/resources/journal'
8
+ require 'seven_api/resources/lookup'
9
+ require 'seven_api/resources/pricing'
10
+ require 'seven_api/resources/sms'
11
+ require 'seven_api/resources/status'
12
+ require 'seven_api/resources/subaccounts'
13
+ require 'seven_api/resources/validate_for_voice'
14
+ require 'seven_api/resources/voice'
15
+ require 'seven_api/util'
16
+
17
+ module SevenApi
18
+ class Client
19
+ # @param resource [SevenApi::Resource]
20
+ def initialize(resource)
21
+ SevenApi::Util::get_namespace_classes(SevenApi::Resources).each do |cls|
22
+ name = cls.name.split('::').last
23
+
24
+ instance_variable_set("@#{name}", cls.new(resource))
25
+
26
+ singleton_class.instance_eval("attr_reader :#{name}")
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module holds all utilities related to the /contacts endpoint.
4
+ module SevenApi::Contacts
5
+ module Action
6
+ DEL = 'del'
7
+ READ = 'read'
8
+ WRITE = 'write'
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module exposes the endpoints covered by this client.
4
+ module SevenApi::Endpoint
5
+ ANALYTICS = 'analytics'
6
+ BALANCE = 'balance'
7
+ CONTACTS = 'contacts'
8
+ HOOKS = 'hooks'
9
+ JOURNAL = 'journal'
10
+ LOOKUP = 'lookup'
11
+ PRICING = 'pricing'
12
+ SMS = 'sms'
13
+ STATUS = 'status'
14
+ SUBACCOUNTS = 'subaccounts'
15
+ VALIDATE_FOR_VOICE = 'validate_for_voice'
16
+ VOICE = 'voice'
17
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module holds all utilities related to the /hooks endpoint.
4
+ module SevenApi::Hooks
5
+ module Action
6
+ READ = 'read'
7
+ SUBSCRIBE = 'subscribe'
8
+ UNSUBSCRIBE = 'unsubscribe'
9
+ end
10
+
11
+ module EventType
12
+ ALL = 'all'
13
+ NEW_INBOUND_SMS = 'sms_mo'
14
+ SMS_STATUS_UPDATE = 'dlr'
15
+ TRACKING = 'tracking'
16
+ VOICE_CALL = 'voice_call'
17
+ VOICE_STATUS_UPDATE = 'voice_status'
18
+ end
19
+
20
+ module RequestMethod
21
+ GET = 'GET'
22
+ JSON = 'JSON'
23
+ POST = 'POST'
24
+ end
25
+
26
+ module Validator
27
+ def self.validate(params)
28
+ action = params[:action]
29
+
30
+ raise "Unknown action #{action}" unless SevenApi::Hooks::Validator::is_action?(action)
31
+
32
+ if SevenApi::Hooks::Action::SUBSCRIBE == action
33
+ raise 'Parameter validation failed' unless SevenApi::Hooks::Validator::subscribe(params)
34
+ elsif SevenApi::Hooks::Action::UNSUBSCRIBE == action
35
+ raise 'ID must be a positive integer' unless SevenApi::Hooks::Validator::unsubscribe(params)
36
+ end
37
+ end
38
+
39
+ def self.subscribe(params)
40
+ { :request_method => SevenApi::Hooks::RequestMethod::POST }.merge!(params)
41
+
42
+ self.event_type?(params[:event_type]) &&
43
+ self.request_method?(params[:request_method]) &&
44
+ self.target_url?(params[:target_url])
45
+ end
46
+
47
+ def self.unsubscribe(params)
48
+ SevenApi::Util::is_positive_integer?(params[:id])
49
+ end
50
+
51
+ def self.is_action?(str)
52
+ SevenApi::Util::in_module_constants?(str, SevenApi::Hooks::Action)
53
+ end
54
+
55
+ def self.event_type?(str)
56
+ SevenApi::Util::in_module_constants?(str, SevenApi::Hooks::EventType)
57
+ end
58
+
59
+ def self.request_method?(str)
60
+ SevenApi::Util::in_module_constants?(str, SevenApi::Hooks::RequestMethod)
61
+ end
62
+
63
+ def self.target_url?(str)
64
+ SevenApi::Util::is_valid_url?(str)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module holds all utilities related to the /journal endpoint.
4
+ module SevenApi::Journal
5
+ module Type
6
+ INBOUND = 'inbound'
7
+ OUTBOUND = 'outbound'
8
+ REPLIES = 'replies'
9
+ VOICE = 'voice'
10
+ end
11
+
12
+ module Validator
13
+ def self.validate(params)
14
+ type = params[:type]
15
+ date_from = params[:date_from]
16
+ date_to = params[:date_to]
17
+
18
+ raise "Unknown type #{type}" unless SevenApi::Journal::Validator::is_type?(type)
19
+ raise "Wrong date_from #{date_from}" unless SevenApi::Journal::Validator::is_date?(date_from)
20
+ raise "Wrong date_to #{date_to}" unless SevenApi::Journal::Validator::is_date?(date_to)
21
+ end
22
+
23
+ def self.subscribe(params)
24
+ { :request_method => SevenApi::Hooks::RequestMethod::POST }.merge!(params)
25
+
26
+ self.event_type?(params[:event_type]) &&
27
+ self.request_method?(params[:request_method]) &&
28
+ self.target_url?(params[:target_url])
29
+ end
30
+
31
+ def self.is_type?(str)
32
+ SevenApi::Util::in_module_constants?(str, SevenApi::Journal::Type)
33
+ end
34
+
35
+ def self.is_date?(date)
36
+ date.is_a?(NilClass) || date.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])/)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This module holds all utilities related to the /lookup endpoint.
4
+ module SevenApi::Lookup
5
+ module Type
6
+ CNAM = 'cnam'
7
+ FORMAT = 'format'
8
+ HLR = 'hlr'
9
+ MNP = 'mnp'
10
+ end
11
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+ require 'json'
5
+ require 'faraday'
6
+ require 'seven_api/endpoint'
7
+
8
+ # This module exposes a HTTP client for communication with the API.
9
+ module SevenApi
10
+ class Resource
11
+ attr_reader :api_key, :endpoint, :sent_with, :http_methods, :request_methods, :builder, :conn
12
+
13
+ BASE_PATH = '/api/'
14
+
15
+ def initialize(api_key, sent_with = 'ruby')
16
+ raise 'missing api_key in config' if api_key.to_s.empty?
17
+ raise 'missing sent_with in config' if sent_with.to_s.empty?
18
+
19
+ @api_key = api_key
20
+ @sent_with = sent_with
21
+ @endpoint = self.class.get_endpoint
22
+ @http_methods = self.class.get_http_methods
23
+ @conn = Faraday.new("https://gateway.seven.io#{BASE_PATH}")
24
+ end
25
+
26
+ protected
27
+
28
+ def request(payload = {}, query = {})
29
+ path = @endpoint
30
+ http_method = @http_methods[caller_locations.first.label.to_sym]
31
+
32
+ if :get == http_method
33
+ query = payload
34
+
35
+ payload = {}
36
+ end
37
+
38
+ query.each do |key, val|
39
+ query.store(key, SevenApi::Util::to_numbered_bool(val))
40
+ end
41
+
42
+ payload.each do |key, val|
43
+ payload.store(key, SevenApi::Util::to_numbered_bool(val))
44
+ end
45
+
46
+ unless query.empty?
47
+ path = "#{path}?#{URI.encode_www_form(query)}"
48
+ end
49
+
50
+ headers = Hash[
51
+ Faraday::Request::Authorization::KEY, "Bearer #{@api_key}",
52
+ 'sentWith', @sent_with
53
+ ]
54
+
55
+ res = @conn.run_request(http_method, path, payload, headers)
56
+
57
+ puts JSON.pretty_generate(res.to_hash.merge({
58
+ :method => http_method,
59
+ :path => path,
60
+ :payload => payload,
61
+ :req_headers => headers,
62
+ :query => query,
63
+ }).compact) if ENV['SEVEN_DEBUG']
64
+
65
+ raise "Error requesting (#{self.class.name}) with code #{res.status}" unless 200 == res.status
66
+
67
+ raise 'Unexpected response' unless res.is_a?(Faraday::Response)
68
+
69
+ body = res.body
70
+
71
+ if body.is_a?(String)
72
+ begin
73
+ body = JSON.parse(body, :symbolize_names => true)
74
+ rescue StandardError
75
+ # Ignored
76
+ end
77
+ end
78
+
79
+ body.map! { |hash| hash.transform_keys(&:to_sym) } if body.is_a?(Array)
80
+
81
+ body
82
+ end
83
+
84
+ class << self
85
+ def get_http_methods
86
+ @http_methods
87
+ end
88
+
89
+ def get_endpoint
90
+ @endpoint
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +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 /analytics.
6
+ module SevenApi::Resources
7
+ class Analytics < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::ANALYTICS
9
+ @http_methods = {
10
+ :retrieve => :get,
11
+ }
12
+
13
+ # Retrieve analytics for associated API key
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/analytics/
15
+ # @param params [Hash]
16
+ # @return [Array]
17
+ def retrieve(params = {})
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,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 /balance.
6
+ module SevenApi::Resources
7
+ class Balance < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::BALANCE
9
+ @http_methods = {
10
+ :retrieve => :get,
11
+ }
12
+
13
+ # Retrieve account balance for associated API key
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/credit-balance/
15
+ # @return [Float]
16
+ def retrieve
17
+ request
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resource'
4
+
5
+ # This module exposes the methods for communicating with the API endpoint /contacts.
6
+ module SevenApi::Resources
7
+ class Contacts < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::CONTACTS
9
+ @http_methods = {
10
+ :delete => :post,
11
+ :read => :get,
12
+ :write => :post,
13
+ }
14
+
15
+ # Retrieve contacts associated with the API key
16
+ # read more: https://www.seven.io/en/docs/gateway/http-api/contacts/#read-contacts
17
+ # @param params [Hash]
18
+ # @return [String, Hash]
19
+ def read(params = {})
20
+ request(params.merge({ :action => SevenApi::Contacts::Action::READ }))
21
+ end
22
+
23
+ # Delete an account with given ID
24
+ # read more: https://www.seven.io/en/docs/gateway/http-api/contacts/#delete-contacts
25
+ # @param params [Hash]
26
+ # @return [String, Hash]
27
+ def delete(params)
28
+ request({}, params.merge({ :action => SevenApi::Contacts::Action::DEL }))
29
+ end
30
+
31
+ # Create or update a contact
32
+ # read more: https://www.seven.io/en/docs/gateway/http-api/contacts/#create-and-edit-contacts
33
+ # @param params [Hash]
34
+ # @return [String, Hash]
35
+ def write(params)
36
+ request({}, params.merge({ :action => SevenApi::Contacts::Action::WRITE }))
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resource'
4
+
5
+ # This module exposes the methods for communicating with the API endpoint /hooks.
6
+ # read more: https://www.seven.io/en/docs/gateway/http-api/webhooks/
7
+ module SevenApi::Resources
8
+ class Hooks < SevenApi::Resource
9
+ @endpoint = SevenApi::Endpoint::HOOKS
10
+ @http_methods = {
11
+ :read => :get,
12
+ :subscribe => :post,
13
+ :unsubscribe => :post,
14
+ }
15
+
16
+ # Retrieve all webhooks
17
+ # @param params [Hash]
18
+ # @return [Hash]
19
+ def read(params = {})
20
+ request(params.merge({ :action => SevenApi::Hooks::Action::READ }))
21
+ end
22
+
23
+ # Register a new webhook
24
+ # @param params [Hash]
25
+ # @return [Hash]
26
+ def subscribe(params)
27
+ SevenApi::Hooks::Validator::subscribe(params)
28
+
29
+ request(params.merge({ :action => SevenApi::Hooks::Action::SUBSCRIBE }))
30
+ end
31
+
32
+ # Delete a webhook
33
+ # @param params [Hash]
34
+ # @return [Hash]
35
+ def unsubscribe(params)
36
+ SevenApi::Hooks::Validator::unsubscribe(params)
37
+
38
+ request(params.merge({ :action => SevenApi::Hooks::Action::UNSUBSCRIBE }))
39
+ end
40
+ end
41
+ end
@@ -0,0 +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 /journal.
6
+ module SevenApi::Resources
7
+ class Journal < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::JOURNAL
9
+ @http_methods = {
10
+ :retrieve => :get,
11
+ }
12
+
13
+ # Retrieve the journal for associated API key
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/journal/
15
+ # @param params [Hash]
16
+ # @return [Array]
17
+ def retrieve(params)
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'seven_api/resource'
4
+
5
+ # This module exposes the methods for communicating with the API endpoint /lookup.
6
+ module SevenApi::Resources
7
+ class Lookup < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::LOOKUP
9
+ @http_methods = {
10
+ :cnam => :post,
11
+ :format => :post,
12
+ :hlr => :post,
13
+ :mnp => :post,
14
+ }
15
+
16
+ # Perform a caller name lookup
17
+ # read more: https://www.seven.io/en/docs/gateway/http-api/cnam-lookup/
18
+ # @param params [Hash]
19
+ # @return [Hash,Array]
20
+ def cnam(params)
21
+ request(params.merge({ :type => SevenApi::Lookup::Type::CNAM }))
22
+ end
23
+
24
+ # Retrieve phone number formats
25
+ # read more: https://www.seven.io/en/docs/gateway/http-api/nummernformat-lookup/
26
+ # @param params [Hash]
27
+ # @return [String,Hash]
28
+ def format(params)
29
+ request(params.merge({ :type => SevenApi::Lookup::Type::FORMAT }))
30
+ end
31
+
32
+ # Perform a home location register lookup
33
+ # read more: https://www.seven.io/en/docs/gateway/http-api/hlr-lookup/
34
+ # @param params [Hash]
35
+ # @return [Hash,Array]
36
+ def hlr(params)
37
+ request(params.merge({ :type => SevenApi::Lookup::Type::HLR }))
38
+ end
39
+
40
+ # Perform a mobile number portability lookup
41
+ # read more: https://www.seven.io/en/docs/gateway/http-api/mnp-lookup/
42
+ # @param params [Hash]
43
+ # @return [Hash,Array]
44
+ def mnp(params)
45
+ request(params.merge({ :type => SevenApi::Lookup::Type::MNP }))
46
+ end
47
+ end
48
+ end
@@ -0,0 +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 /pricing.
6
+ module SevenApi::Resources
7
+ class Pricing < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::PRICING
9
+ @http_methods = {
10
+ :retrieve => :get,
11
+ }
12
+
13
+ # Retrieve pricing
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/pricing/
15
+ # @param params [Hash]
16
+ # @return [Hash,String]
17
+ def retrieve(params = {})
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +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 /sms.
6
+ module SevenApi::Resources
7
+ class Sms < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::SMS
9
+ @http_methods = {
10
+ :retrieve => :post,
11
+ }
12
+
13
+ # Send SMS
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/sms-dispatch/
15
+ # @param params [Hash]
16
+ # @return [Integer,String,Hash]
17
+ def retrieve(params)
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +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://www.seven.io/en/docs/gateway/http-api/status-reports/#query-delivery-reports
15
+ # @param params [Hash]
16
+ # @return [String]
17
+ def retrieve(params)
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +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://www.seven.io/en/docs/gateway/http-api/subaccounts/#create-subaccount
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://www.seven.io/en/docs/gateway/http-api/subaccounts/#delete-subaccount
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://www.seven.io/en/docs/gateway/http-api/subaccounts/#read-subaccounts
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://www.seven.io/en/docs/gateway/http-api/subaccounts/#transfer-credit
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://www.seven.io/en/docs/gateway/http-api/subaccounts/#update-automatic-charging-of-the-subaccount
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
66
+ end
@@ -0,0 +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://www.seven.io/en/docs/gateway/http-api/caller-ids/
15
+ # @param params [Hash]
16
+ # @return [Hash]
17
+ def retrieve(params)
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +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 /voice.
6
+ module SevenApi::Resources
7
+ class Voice < SevenApi::Resource
8
+ @endpoint = SevenApi::Endpoint::VOICE
9
+ @http_methods = {
10
+ :send => :post,
11
+ }
12
+
13
+ # Convert text to speech, call number and read voice message out loud.
14
+ # read more: https://www.seven.io/en/docs/gateway/http-api/voice/
15
+ # @param params [Hash]
16
+ # @return [String,Hash]
17
+ def send(params)
18
+ request(params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +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