Skip to content

Commit 6839749

Browse files
authored
Merge pull request #30 from Bandwidth/release/2021-09-17-18-16-53
DX-2204 Voice, Answering Machine Detection
2 parents 49eb70d + 9de287f commit 6839749

File tree

72 files changed

+3060
-1098
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3060
-1098
lines changed

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
source 'https://rubygems.org'
42

53
group :test do

bandwidth.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'bandwidth-sdk'
3-
s.version = '8.0.0'
3+
s.version = '9.0.0'
44
s.summary = 'bandwidth'
55
s.description = 'Bandwidth\'s set of APIs'
66
s.authors = ['APIMatic SDK Generator']
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.add_dependency('builder', '~> 3.2.4')
1616
s.add_development_dependency('minitest', '~> 5.14', '>= 5.14.1')
1717
s.add_development_dependency('minitest-proveit', '~> 1.0')
18-
s.required_ruby_version = '>= 2.0'
18+
s.required_ruby_version = ['>= 2.0']
1919
s.files = Dir['{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*']
2020
s.require_paths = ['lib']
2121
end

lib/bandwidth.rb

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,41 @@
99
require 'certifi'
1010
require 'logging'
1111

12-
require_relative 'bandwidth/api_helper.rb'
13-
require_relative 'bandwidth/client.rb'
12+
require_relative 'bandwidth/api_helper'
13+
require_relative 'bandwidth/client'
1414

1515
# Utilities
16-
require_relative 'bandwidth/utilities/file_wrapper.rb'
17-
require_relative 'bandwidth/utilities/date_time_helper.rb'
16+
require_relative 'bandwidth/utilities/file_wrapper'
17+
require_relative 'bandwidth/utilities/date_time_helper'
1818

1919
# Http
20-
require_relative 'bandwidth/http/api_response.rb'
21-
require_relative 'bandwidth/http/http_call_back.rb'
22-
require_relative 'bandwidth/http/http_client.rb'
23-
require_relative 'bandwidth/http/faraday_client.rb'
24-
require_relative 'bandwidth/http/http_method_enum.rb'
25-
require_relative 'bandwidth/http/http_request.rb'
26-
require_relative 'bandwidth/http/http_response.rb'
20+
require_relative 'bandwidth/http/api_response'
21+
require_relative 'bandwidth/http/http_call_back'
22+
require_relative 'bandwidth/http/http_client'
23+
require_relative 'bandwidth/http/faraday_client'
24+
require_relative 'bandwidth/http/http_method_enum'
25+
require_relative 'bandwidth/http/http_request'
26+
require_relative 'bandwidth/http/http_response'
2727

2828
# Models
29-
require_relative 'bandwidth/models/base_model.rb'
29+
require_relative 'bandwidth/models/base_model'
3030

3131
# Exceptions
32-
require_relative 'bandwidth/exceptions/api_exception.rb'
32+
require_relative 'bandwidth/exceptions/api_exception'
3333

34-
require_relative 'bandwidth/configuration.rb'
34+
require_relative 'bandwidth/configuration'
3535

3636
# Namespaces
3737
require_relative 'bandwidth/messaging_lib/messaging'
38-
require_relative 'bandwidth/http/auth/messaging_basic_auth.rb'
38+
require_relative 'bandwidth/http/auth/messaging_basic_auth'
3939
require_relative 'bandwidth/multi_factor_auth_lib/multi_factor_auth'
40-
require_relative 'bandwidth/http/auth/multi_factor_auth_basic_auth.rb'
40+
require_relative 'bandwidth/http/auth/multi_factor_auth_basic_auth'
4141
require_relative 'bandwidth/phone_number_lookup_lib/phone_number_lookup'
42-
require_relative 'bandwidth/http/auth/phone_number_lookup_basic_auth.rb'
42+
require_relative 'bandwidth/http/auth/phone_number_lookup_basic_auth'
4343
require_relative 'bandwidth/voice_lib/voice'
44-
require_relative 'bandwidth/http/auth/voice_basic_auth.rb'
44+
require_relative 'bandwidth/http/auth/voice_basic_auth'
4545
require_relative 'bandwidth/web_rtc_lib/web_rtc'
46+
require_relative 'bandwidth/http/auth/web_rtc_basic_auth'
4647
require_relative 'bandwidth/http/auth/web_rtc_basic_auth.rb'
4748

4849
# External Files

lib/bandwidth/api_helper.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class APIHelper
1313
def self.serialize_array(key, array, formatting: 'indexed')
1414
tuples = []
1515

16-
if formatting == 'unindexed'
16+
case formatting
17+
when 'unindexed'
1718
tuples += array.map { |element| ["#{key}[]", element] }
18-
elsif formatting == 'indexed'
19+
when 'indexed'
1920
tuples += array.map.with_index do |element, index|
2021
["#{key}[#{index}]", element]
2122
end
22-
elsif formatting == 'plain'
23+
when 'plain'
2324
tuples += array.map { |element| [key, element] }
2425
else
2526
raise ArgumentError, 'Invalid format provided.'
@@ -60,7 +61,7 @@ def self.append_url_with_template_parameters(query_builder, parameters)
6061
end
6162

6263
# Find the template parameter and replace it with its value.
63-
query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
64+
query_builder = query_builder.gsub("{#{key}}", replace_value)
6465
end
6566
query_builder
6667
end
@@ -85,15 +86,16 @@ def self.append_url_with_query_parameters(query_builder, parameters)
8586
unless value.nil?
8687
if value.instance_of? Array
8788
value.compact!
88-
query_builder += if array_serialization == 'csv'
89+
query_builder += case array_serialization
90+
when 'csv'
8991
"#{seperator}#{key}=#{value.map do |element|
9092
CGI.escape(element.to_s)
9193
end.join(',')}"
92-
elsif array_serialization == 'psv'
94+
when 'psv'
9395
"#{seperator}#{key}=#{value.map do |element|
9496
CGI.escape(element.to_s)
9597
end.join('|')}"
96-
elsif array_serialization == 'tsv'
98+
when 'tsv'
9799
"#{seperator}#{key}=#{value.map do |element|
98100
CGI.escape(element.to_s)
99101
end.join("\t")}"
@@ -119,7 +121,7 @@ def self.clean_url(url)
119121
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
120122

121123
# Ensure that the urls are absolute.
122-
matches = url.match(%r{^(https?:\/\/[^\/]+)})
124+
matches = url.match(%r{^(https?://[^/]+)})
123125
raise ArgumentError, 'Invalid Url format.' if matches.nil?
124126

125127
# Get the http protocol match.
@@ -130,7 +132,7 @@ def self.clean_url(url)
130132

131133
# Remove redundant forward slashes.
132134
query = url[protocol.length...(!index.nil? ? index : url.length)]
133-
query.gsub!(%r{\/\/+}, '/')
135+
query.gsub!(%r{//+}, '/')
134136

135137
# Get the parameters.
136138
parameters = !index.nil? ? url[url.index('?')...url.length] : ''
@@ -142,7 +144,7 @@ def self.clean_url(url)
142144
# Parses JSON string.
143145
# @param [String] A JSON string.
144146
def self.json_deserialize(json)
145-
return JSON.parse(json)
147+
JSON.parse(json)
146148
rescue StandardError
147149
raise TypeError, 'Server responded with invalid JSON.'
148150
end
@@ -171,6 +173,7 @@ def self.custom_merge(a, b)
171173
a.each do |key, value_a|
172174
b.each do |k, value_b|
173175
next unless key == k
176+
174177
x[k] = []
175178
if value_a.instance_of? Array
176179
value_a.each do |v|
@@ -215,13 +218,12 @@ def self.form_encode(obj, instance_name, formatting: 'indexed')
215218
elsif obj.instance_of? Array
216219
if formatting == 'indexed'
217220
obj.each_with_index do |value, index|
218-
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
219-
index.to_s + ']'))
221+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]"))
220222
end
221223
elsif serializable_types.map { |x| obj[0].is_a? x }.any?
222224
obj.each do |value|
223225
abc = if formatting == 'unindexed'
224-
APIHelper.form_encode(value, instance_name + '[]',
226+
APIHelper.form_encode(value, "#{instance_name}[]",
225227
formatting: formatting)
226228
else
227229
APIHelper.form_encode(value, instance_name,
@@ -231,14 +233,14 @@ def self.form_encode(obj, instance_name, formatting: 'indexed')
231233
end
232234
else
233235
obj.each_with_index do |value, index|
234-
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
235-
index.to_s + ']', formatting: formatting))
236+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{index}]",
237+
formatting: formatting))
236238
end
237239
end
238240
elsif obj.instance_of? Hash
239241
obj.each do |key, value|
240-
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
241-
key.to_s + ']', formatting: formatting))
242+
retval.merge!(APIHelper.form_encode(value, "#{instance_name}[#{key}]",
243+
formatting: formatting))
242244
end
243245
elsif obj.instance_of? File
244246
retval[instance_name] = UploadIO.new(

lib/bandwidth/configuration.rb

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,13 @@ class Server
2828
# are configured in this class.
2929
class Configuration
3030
# The attribute readers for properties.
31-
attr_reader :http_client
32-
attr_reader :timeout
33-
attr_reader :max_retries
34-
attr_reader :retry_interval
35-
attr_reader :backoff_factor
36-
attr_reader :retry_statuses
37-
attr_reader :retry_methods
38-
attr_reader :environment
39-
attr_reader :base_url
40-
attr_reader :messaging_basic_auth_user_name
41-
attr_reader :messaging_basic_auth_password
42-
attr_reader :multi_factor_auth_basic_auth_user_name
43-
attr_reader :multi_factor_auth_basic_auth_password
44-
attr_reader :phone_number_lookup_basic_auth_user_name
45-
attr_reader :phone_number_lookup_basic_auth_password
46-
attr_reader :voice_basic_auth_user_name
47-
attr_reader :voice_basic_auth_password
48-
attr_reader :web_rtc_basic_auth_user_name
49-
attr_reader :web_rtc_basic_auth_password
31+
attr_reader :http_client, :timeout, :max_retries, :retry_interval, :backoff_factor,
32+
:retry_statuses, :retry_methods, :environment, :base_url,
33+
:messaging_basic_auth_user_name, :messaging_basic_auth_password,
34+
:multi_factor_auth_basic_auth_user_name, :multi_factor_auth_basic_auth_password,
35+
:phone_number_lookup_basic_auth_user_name, :phone_number_lookup_basic_auth_password,
36+
:voice_basic_auth_user_name, :voice_basic_auth_password,
37+
:web_rtc_basic_auth_user_name, :web_rtc_basic_auth_password
5038

5139
class << self
5240
attr_reader :environments

lib/bandwidth/http/faraday_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def initialize(timeout:, max_retries:, retry_interval:,
2727
methods: retry_methods
2828
faraday.adapter Faraday.default_adapter
2929
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
30-
faraday.options[:timeout] = timeout if timeout > 0
30+
faraday.options[:timeout] = timeout if timeout.positive?
3131
end
3232
end
3333

0 commit comments

Comments
 (0)