wavix-sdk-ruby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +124 -0
  4. data/lib/middleware/follow_redirects_middleware.rb +15 -0
  5. data/lib/services/fields_validator.rb +26 -0
  6. data/lib/wavix-sdk-ruby.rb +5 -0
  7. data/lib/wavix_api/base_methods.rb +180 -0
  8. data/lib/wavix_api/v1/base_destroy.rb +31 -0
  9. data/lib/wavix_api/v1/base_find.rb +31 -0
  10. data/lib/wavix_api/v1/base_search.rb +31 -0
  11. data/lib/wavix_api/v1/billing/invoices/find.rb +44 -0
  12. data/lib/wavix_api/v1/billing/invoices/search.rb +21 -0
  13. data/lib/wavix_api/v1/billing/transactions/search.rb +39 -0
  14. data/lib/wavix_api/v1/buy/carts/checkout.rb +23 -0
  15. data/lib/wavix_api/v1/buy/carts/find.rb +23 -0
  16. data/lib/wavix_api/v1/buy/carts/update.rb +34 -0
  17. data/lib/wavix_api/v1/buy/cities/search.rb +47 -0
  18. data/lib/wavix_api/v1/buy/countries/search.rb +31 -0
  19. data/lib/wavix_api/v1/buy/dids/search.rb +41 -0
  20. data/lib/wavix_api/v1/buy/regions/search.rb +33 -0
  21. data/lib/wavix_api/v1/call/recordings/destroy.rb +23 -0
  22. data/lib/wavix_api/v1/call/recordings/month_statistics/details.rb +35 -0
  23. data/lib/wavix_api/v1/call/recordings/month_statistics/search.rb +35 -0
  24. data/lib/wavix_api/v1/call/recordings/recording_settings.rb +40 -0
  25. data/lib/wavix_api/v1/call/recordings/retention_policy.rb +23 -0
  26. data/lib/wavix_api/v1/call/recordings/search.rb +55 -0
  27. data/lib/wavix_api/v1/call/recordings/update_recording_settings.rb +48 -0
  28. data/lib/wavix_api/v1/call/recordings/update_retention_policy.rb +37 -0
  29. data/lib/wavix_api/v1/call/transcriptions/find.rb +31 -0
  30. data/lib/wavix_api/v1/call/transcriptions/retranscribe.rb +35 -0
  31. data/lib/wavix_api/v1/cdrs/advanced_search.rb +67 -0
  32. data/lib/wavix_api/v1/cdrs/common_vars.rb +22 -0
  33. data/lib/wavix_api/v1/cdrs/metrics.rb +29 -0
  34. data/lib/wavix_api/v1/cdrs/search.rb +35 -0
  35. data/lib/wavix_api/v1/e911_records/create.rb +47 -0
  36. data/lib/wavix_api/v1/e911_records/destroy.rb +31 -0
  37. data/lib/wavix_api/v1/e911_records/search.rb +33 -0
  38. data/lib/wavix_api/v1/e911_records/validate_address.rb +44 -0
  39. data/lib/wavix_api/v1/mydids/cities.rb +32 -0
  40. data/lib/wavix_api/v1/mydids/destroy.rb +55 -0
  41. data/lib/wavix_api/v1/mydids/find.rb +21 -0
  42. data/lib/wavix_api/v1/mydids/search.rb +35 -0
  43. data/lib/wavix_api/v1/mydids/update.rb +40 -0
  44. data/lib/wavix_api/v1/mydids/update_destinations.rb +73 -0
  45. data/lib/wavix_api/v1/mydids/update_sms_enabled.rb +32 -0
  46. data/lib/wavix_api/v1/papers/create.rb +65 -0
  47. data/lib/wavix_api/v1/papers/find.rb +42 -0
  48. data/lib/wavix_api/v1/profile/account_config.rb +21 -0
  49. data/lib/wavix_api/v1/profile/find.rb +21 -0
  50. data/lib/wavix_api/v1/profile/update.rb +58 -0
  51. data/lib/wavix_api/v1/sub_organizations/create.rb +36 -0
  52. data/lib/wavix_api/v1/sub_organizations/find.rb +19 -0
  53. data/lib/wavix_api/v1/sub_organizations/search.rb +31 -0
  54. data/lib/wavix_api/v1/sub_organizations/transactions.rb +39 -0
  55. data/lib/wavix_api/v1/sub_organizations/update.rb +40 -0
  56. data/lib/wavix_api/v1/trunks/create.rb +76 -0
  57. data/lib/wavix_api/v1/trunks/destroy.rb +19 -0
  58. data/lib/wavix_api/v1/trunks/find.rb +19 -0
  59. data/lib/wavix_api/v1/trunks/search.rb +30 -0
  60. data/lib/wavix_api/v1/trunks/update.rb +85 -0
  61. data/lib/wavix_api/v1/voice_campaigns/create.rb +39 -0
  62. data/lib/wavix_api/v1/voice_campaigns/find.rb +21 -0
  63. data/lib/wavix_api/v2/base_destroy.rb +10 -0
  64. data/lib/wavix_api/v2/base_find.rb +10 -0
  65. data/lib/wavix_api/v2/base_search.rb +10 -0
  66. data/lib/wavix_api/v2/messages/all.rb +23 -0
  67. data/lib/wavix_api/v2/messages/async_create.rb +23 -0
  68. data/lib/wavix_api/v2/messages/attachments/find.rb +59 -0
  69. data/lib/wavix_api/v2/messages/common_vars.rb +50 -0
  70. data/lib/wavix_api/v2/messages/create.rb +24 -0
  71. data/lib/wavix_api/v2/messages/find.rb +19 -0
  72. data/lib/wavix_api/v2/messages/opt_outs/create.rb +34 -0
  73. data/lib/wavix_api/v2/messages/search.rb +23 -0
  74. data/lib/wavix_api/v2/messages/sender_ids/create.rb +40 -0
  75. data/lib/wavix_api/v2/messages/sender_ids/destroy.rb +21 -0
  76. data/lib/wavix_api/v2/messages/sender_ids/find.rb +21 -0
  77. data/lib/wavix_api/v2/messages/sender_ids/restrictions.rb +32 -0
  78. data/lib/wavix_api/v2/messages/sender_ids/search.rb +21 -0
  79. data/lib/wavix_api/v3/messages/sender_ids/create.rb +51 -0
  80. data/lib/wavix_api/v3/messages/sender_ids/find.rb +21 -0
  81. data/lib/wavix_api/v3/messages/sender_ids/search.rb +21 -0
  82. data/lib/wavix_api.rb +155 -0
  83. data/wavix-sdk-ruby.gemspec +40 -0
  84. metadata +204 -0
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ class Find < ::WavixApi::V2::BaseFind
7
+ @params_schema = ::WavixApi::BaseMethods::ONLY_UUID_SCHEMA
8
+
9
+ class << self
10
+ private
11
+
12
+ def path
13
+ 'v2/messages'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ module OptOuts
7
+ class Create
8
+ include WavixApi::BaseMethods
9
+
10
+ @params_schema = {
11
+ type: 'object',
12
+ properties: {
13
+ number: { type: 'string' }.freeze,
14
+ sender_id: { type: 'string' }.freeze
15
+ }.freeze,
16
+ required: %i[
17
+ number
18
+ ].freeze
19
+ }.freeze
20
+
21
+ class << self
22
+ def call(params = {})
23
+ instance = new(params)
24
+
25
+ instance.validate!
26
+
27
+ instance.post('v2/messages/opt-outs')
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'wavix_api'
4
+
5
+ module WavixApi
6
+ module V2
7
+ module Messages
8
+ class Search < ::WavixApi::V2::BaseSearch
9
+ include ::WavixApi::V1::Messages::CommonVars
10
+
11
+ @params_schema = ::WavixApi::V1::Messages::CommonVars::SEARCH_PARAMS_SCHEMA
12
+
13
+ class << self
14
+ private
15
+
16
+ def path
17
+ 'v2/messages'
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ module SenderIds
7
+ class Create
8
+ include WavixApi::BaseMethods
9
+
10
+ @params_schema = {
11
+ type: 'object',
12
+ properties: {
13
+ type: { enum: %w[numeric alphanumeric] }.freeze,
14
+ sender_id: { type: 'string' }.freeze,
15
+ countries: {
16
+ type: 'array',
17
+ items: { type: 'string' }.freeze
18
+ }
19
+ }.freeze,
20
+ required: %i[
21
+ type
22
+ sender_id
23
+ countries
24
+ ].freeze
25
+ }.freeze
26
+
27
+ class << self
28
+ def call(params = {})
29
+ instance = new(params)
30
+
31
+ instance.validate!
32
+
33
+ instance.post('v2/messages/sender-ids')
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ module SenderIds
7
+ class Destroy < ::WavixApi::V2::BaseDestroy
8
+ @params_schema = ::WavixApi::BaseMethods::ONLY_UUID_SCHEMA
9
+
10
+ class << self
11
+ private
12
+
13
+ def path
14
+ 'v2/messages/sender-ids'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ module SenderIds
7
+ class Find < ::WavixApi::V2::BaseFind
8
+ @params_schema = ::WavixApi::BaseMethods::ONLY_UUID_SCHEMA
9
+
10
+ class << self
11
+ private
12
+
13
+ def path
14
+ 'v2/messages/sender-ids'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V2
5
+ module Messages
6
+ module SenderIds
7
+ class Restrictions
8
+ include WavixApi::BaseMethods
9
+
10
+ @params_schema = {
11
+ type: 'object',
12
+ properties: {
13
+ country: { type: 'string' }.freeze,
14
+ type: { enum: %w[numeric alphanumeric] }.freeze
15
+ }.freeze,
16
+ required: %i[country type].freeze
17
+ }.freeze
18
+
19
+ class << self
20
+ def call(params = {})
21
+ instance = new(params)
22
+
23
+ instance.validate!
24
+
25
+ instance.get('v2/messages/sender-ids/restrictions')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'wavix_api'
4
+
5
+ module WavixApi
6
+ module V2
7
+ module Messages
8
+ module SenderIds
9
+ class Search < ::WavixApi::V2::BaseSearch
10
+ class << self
11
+ private
12
+
13
+ def path
14
+ 'v2/messages/sender-ids'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V3
5
+ module Messages
6
+ module SenderIds
7
+ class Create
8
+ include WavixApi::BaseMethods
9
+
10
+ MONTHLY_VOLUMES = ['1-1000', '1001-20000', '20001-50000',
11
+ '50001-100000', 'More than 100000'].freeze
12
+ USECASES = %w[transactional promo authentication].freeze
13
+
14
+ @params_schema = {
15
+ type: 'object',
16
+ properties: {
17
+ type: { enum: %w[numeric alphanumeric] }.freeze,
18
+ sender_id: { type: 'string' }.freeze,
19
+ countries: {
20
+ type: 'array',
21
+ items: { type: 'string' }.freeze
22
+ },
23
+ usecase: { enum: USECASES }.freeze,
24
+ monthly_volume: { enum: MONTHLY_VOLUMES }.freeze,
25
+ samples: {
26
+ type: 'array',
27
+ items: { type: 'string' }.freeze
28
+ }
29
+ }.freeze,
30
+ required: %i[
31
+ type
32
+ sender_id
33
+ countries
34
+ usecase
35
+ samples
36
+ ].freeze
37
+ }.freeze
38
+ class << self
39
+ def call(params = {})
40
+ instance = new(params)
41
+
42
+ instance.validate!
43
+
44
+ instance.post('v3/messages/sender-ids')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WavixApi
4
+ module V3
5
+ module Messages
6
+ module SenderIds
7
+ class Find < ::WavixApi::V2::BaseFind
8
+ @params_schema = ::WavixApi::BaseMethods::ONLY_UUID_SCHEMA
9
+
10
+ class << self
11
+ private
12
+
13
+ def path
14
+ 'v3/messages/sender-ids'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'wavix_api'
4
+
5
+ module WavixApi
6
+ module V3
7
+ module Messages
8
+ module SenderIds
9
+ class Search < ::WavixApi::V2::BaseSearch
10
+ class << self
11
+ private
12
+
13
+ def path
14
+ 'v3/messages/sender-ids'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/wavix_api.rb ADDED
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
5
+ require 'faraday/multipart'
6
+ require_relative 'middleware/follow_redirects_middleware'
7
+
8
+ module WavixApi
9
+ class << self
10
+ DEFAULT_HOST = 'api.wavix.com'
11
+
12
+ attr_accessor :api_key, :host
13
+
14
+ def client
15
+ Client.new(host: @host, api_key: @api_key)
16
+ end
17
+ end
18
+
19
+ module HTTPMethods
20
+ DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze
21
+ Response = Struct.new(:status, :status_str, :body, :parsed_body, 'success?', :filename)
22
+ CONTENT_TYPES = {
23
+ 'jpeg' => 'image/jpeg',
24
+ 'jpg' => 'image/jpeg',
25
+ 'gif' => 'image/gif',
26
+ 'png' => 'image/png',
27
+ 'pdf' => 'application/pdf',
28
+ 'bmp' => 'image/bmp',
29
+ 'tiff' => 'image/tiff',
30
+ 'doc' => 'application/msword',
31
+ 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
32
+ 'dib' => 'image/dib',
33
+ 'amr' => 'audio/amr',
34
+ '3g' => 'audio/3gpp',
35
+ 'wav' => 'audio/wav',
36
+ 'wave' => 'audio/wav',
37
+ 'mp3' => 'audio/mpeg',
38
+ 'aac' => 'audio/aac',
39
+ 'gcp' => 'audio/gcp',
40
+ 'midi' => 'audio/midi',
41
+ 'midp' => 'audio/midi'
42
+ }.freeze
43
+ FILE_NAMES = %i[attachment paper invoice].freeze
44
+
45
+ def request(method, path, params: {}, body: nil, headers: {})
46
+ connection = Faraday.new(
47
+ url: "https://#{@host}",
48
+ params: { appid: @api_key },
49
+ headers: DEFAULT_HEADERS.merge(headers)
50
+ ) do |builder|
51
+ yield(builder) if block_given?
52
+
53
+ builder.use FollowRedirectsMiddleware
54
+ builder.adapter Faraday.default_adapter
55
+ end
56
+
57
+ response =
58
+ if %w[GET DELETE].index(method)
59
+ connection.send(method.downcase, path, params)
60
+ else
61
+ connection.send(method.downcase, path) do |request|
62
+ (params || {}).each { |k, v| request.params[k] = v }
63
+ request.body = body if body
64
+ end
65
+ end
66
+
67
+ parsed_body = begin
68
+ JSON.parse(response.body)
69
+ rescue JSON::ParserError
70
+ {}
71
+ end
72
+
73
+ Response.new(
74
+ response.status,
75
+ response.reason_phrase,
76
+ response.body,
77
+ parsed_body,
78
+ response.success?,
79
+ filename(response.env.response_headers, path)
80
+ )
81
+ end
82
+
83
+ def filename(response_headers, path)
84
+ file_by_disposition = response_headers['content-disposition']&.match(/filename="(.+)"/)
85
+
86
+ return file_by_disposition[1] if file_by_disposition
87
+
88
+ content_type = CONTENT_TYPES.key(response_headers[:content_type])
89
+
90
+ return unless content_type
91
+
92
+ "#{FILE_NAMES.find { |el| path.include?(el) }}_#{Time.now.to_i}.#{content_type}"
93
+ end
94
+ end
95
+
96
+ class Client
97
+ include HTTPMethods
98
+
99
+ def initialize(host:, api_key:)
100
+ @host = host.empty? ? DEFAULT_HOST : host
101
+ @api_key = api_key
102
+ end
103
+
104
+ def get(path, params: {}, headers: {})
105
+ request('GET', path, params: params, headers: HTTPMethods::DEFAULT_HEADERS.merge(headers))
106
+ end
107
+
108
+ def patch(path, body: {}, params: {})
109
+ request('PATCH', path, params: params, body: body.to_json)
110
+ end
111
+
112
+ def delete(path, params: {})
113
+ request('DELETE', path, params: params)
114
+ end
115
+
116
+ def put(path, body: {}, params: {})
117
+ request('PUT', path, params: params, body: body.to_json)
118
+ end
119
+
120
+ def post(path, body: {}, params: {}, with_file: false,
121
+ headers: { 'Content-Type' => 'application/json' })
122
+ body = body.to_json unless with_file
123
+ headers['Content-Type'] = 'multipart/form-data' if with_file
124
+
125
+ request('POST', path, params: params, body: body, headers: headers) do |builder|
126
+ builder.request :multipart if with_file
127
+ end
128
+ end
129
+
130
+ def download(path, headers: {}, params: {}, save_path: nil)
131
+ if save_path
132
+ dirname = File.dirname(save_path)
133
+ dir_parts = dirname.split(%r{[/\\]}).reject(&:empty?)
134
+
135
+ (1..dir_parts.size).each do |n|
136
+ dir = dir_parts[0...n].join('/')
137
+ Dir.mkdir("/#{dir}") unless Dir.exist?("/#{dir}")
138
+ end
139
+ end
140
+
141
+ response = request('GET', path, params: params, headers: headers)
142
+
143
+ return response if save_path.nil? || !response.success? || response.filename.nil?
144
+
145
+ filename = if CONTENT_TYPES.keys.find { |el| save_path.include?(".#{el}") }
146
+ save_path
147
+ else
148
+ "#{save_path}/#{response.filename}"
149
+ end
150
+
151
+ File.open(filename, 'wb') { |f| f.write response.body }
152
+ response
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'wavix-sdk-ruby'
8
+ s.version = '1.0.0'
9
+ s.authors = ['Wavix']
10
+ s.email = ['support@wavix.com']
11
+ s.summary = 'Wavix Public API SDK for Ruby'
12
+ s.homepage = 'https://wavix.com'
13
+ s.license = 'MIT'
14
+ s.metadata = {
15
+ 'homepage_uri' => 'http://wavix.com/',
16
+ 'changelog_uri' => 'https://ci.unitedline.net/wavix/wavix-sdk-ruby/-/tree/master/CHANGELOG.md',
17
+ 'source_code_uri' => 'https://ci.unitedline.net/wavix/wavix-sdk-ruby/-/tree/master',
18
+ 'bug_tracker_uri' => 'https://ci.unitedline.net/wavix/wavix-sdk-ruby/-/issues'
19
+ }
20
+ s.files = %w[LICENSE README.md wavix-sdk-ruby.gemspec] + Dir['lib/**/*.rb']
21
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
+ s.require_paths = ['lib']
24
+ s.bindir = 'bin'
25
+
26
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
27
+ s.rdoc_options = ['--charset=UTF-8']
28
+
29
+ s.required_ruby_version = '>= 2.5.5'
30
+
31
+ s.add_runtime_dependency 'faraday', '>= 0.17.6'
32
+ s.add_dependency 'faraday-multipart', '~> 1.0.4'
33
+ s.add_dependency 'json-schema', '~> 2.8.1'
34
+ s.add_development_dependency 'rspec', '~> 3.13.0'
35
+ s.add_development_dependency 'rubocop', '~> 1.60.2'
36
+
37
+ s.description = <<-DESC.gsub(/^ /, '')
38
+ Ruby integrations for Wavix Public API
39
+ DESC
40
+ end