Skip to content

Commit b91eb4d

Browse files
TN lookup api, voice class renames (#22)
* New deploy * reverted voice/messaging changes * updated version * removed voice files * added tn lookup tests * added include module * added auth * removed specific controller * added auth creds * added more creds * moar creds pls * added voice breaking changes * added webrtc transfer back * updated tests to multi factor auth * fixed tests * updated gem version to reflect breaking changes * Update test_integration.rb * Update test_integration.rb * reverted breaking changes * added creds and used env variable for tn * updated gem version * updated to new spec * fixed method calls Co-authored-by: jmulford-bw <[email protected]>
1 parent d30d153 commit b91eb4d

22 files changed

+2220
-17
lines changed

bandwidth.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Gem::Specification.new do |s|
22
s.name = 'bandwidth-sdk'
3-
s.version = '6.1.0'
3+
s.version = '6.2.0'
44
s.summary = 'bandwidth'
55
s.description = 'Bandwidth\'s set of APIs'
66
s.authors = ['APIMatic SDK Generator']
77
s.email = '[email protected]'
88
s.homepage = 'https://apimatic.io'
99
s.license = 'MIT'
1010
s.add_dependency('logging', '~> 2.3')
11-
s.add_dependency('faraday', '~> 1.0', '>= 1.0.1')
11+
s.add_dependency('faraday', '~> 1.0', '<= 1.3.0')
1212
s.add_dependency('faraday_middleware', '~> 1.0')
1313
s.add_dependency('certifi', '~> 2018.1', '>= 2018.01.18')
1414
s.add_dependency('faraday-http-cache', '~> 2.2')

lib/bandwidth.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
require_relative 'bandwidth/http/auth/messaging_basic_auth.rb'
3838
require_relative 'bandwidth/two_factor_auth_lib/two_factor_auth'
3939
require_relative 'bandwidth/http/auth/two_factor_auth_basic_auth.rb'
40+
require_relative 'bandwidth/phone_number_lookup_lib/phone_number_lookup'
41+
require_relative 'bandwidth/http/auth/phone_number_lookup_basic_auth.rb'
4042
require_relative 'bandwidth/voice_lib/voice'
4143
require_relative 'bandwidth/http/auth/voice_basic_auth.rb'
4244
require_relative 'bandwidth/web_rtc_lib/web_rtc'

lib/bandwidth/api_helper.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def self.append_url_with_template_parameters(query_builder, parameters)
6868
# Appends the given set of parameters to the given query string.
6969
# @param [String] The query string builder to add the query parameters to.
7070
# @param [Hash] The parameters to append.
71-
# @param [String] The format of array parameter serialization.
72-
def self.append_url_with_query_parameters(query_builder, parameters,
73-
array_serialization: 'indexed')
71+
def self.append_url_with_query_parameters(query_builder, parameters)
7472
# Perform parameter validation.
7573
unless query_builder.instance_of? String
7674
raise ArgumentError, 'Given value for parameter \"query_builder\"
@@ -80,6 +78,8 @@ def self.append_url_with_query_parameters(query_builder, parameters,
8078
# Return if there are no parameters to replace.
8179
return query_builder if parameters.nil?
8280

81+
array_serialization = 'indexed'
82+
8383
parameters.each do |key, value|
8484
seperator = query_builder.include?('?') ? '&' : '?'
8585
unless value.nil?
@@ -156,8 +156,8 @@ def self.clean_hash(hash)
156156
# Form encodes a hash of parameters.
157157
# @param [Hash] The hash of parameters to encode.
158158
# @return [Hash] A hash with the same parameters form encoded.
159-
def self.form_encode_parameters(form_parameters,
160-
array_serialization: 'indexed')
159+
def self.form_encode_parameters(form_parameters)
160+
array_serialization = 'indexed'
161161
encoded = {}
162162
form_parameters.each do |key, value|
163163
encoded.merge!(APIHelper.form_encode(value, key, formatting:

lib/bandwidth/client.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def messaging_client
1717
def two_factor_auth_client
1818
@two_factor_auth_client ||= TwoFactorAuth::Client.new(config: config)
1919
end
20+
# Access to phone_number_lookup_client controller.
21+
# @return [PhoneNumberLookup::Client] Returns the client instance.
22+
def phone_number_lookup_client
23+
@phone_number_lookup_client ||= PhoneNumberLookup::Client.new(config: config)
24+
end
2025
# Access to voice_client controller.
2126
# @return [Voice::Client] Returns the client instance.
2227
def voice_client
@@ -29,12 +34,17 @@ def web_rtc_client
2934
end
3035

3136
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
32-
backoff_factor: 1, environment: Environment::PRODUCTION,
37+
backoff_factor: 2,
38+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
39+
retry_methods: %i[get put get put],
40+
environment: Environment::PRODUCTION,
3341
base_url: 'https://www.example.com',
3442
messaging_basic_auth_user_name: 'TODO: Replace',
3543
messaging_basic_auth_password: 'TODO: Replace',
3644
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
3745
two_factor_auth_basic_auth_password: 'TODO: Replace',
46+
phone_number_lookup_basic_auth_user_name: 'TODO: Replace',
47+
phone_number_lookup_basic_auth_password: 'TODO: Replace',
3848
voice_basic_auth_user_name: 'TODO: Replace',
3949
voice_basic_auth_password: 'TODO: Replace',
4050
web_rtc_basic_auth_user_name: 'TODO: Replace',
@@ -43,12 +53,16 @@ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
4353
Configuration.new(timeout: timeout, max_retries: max_retries,
4454
retry_interval: retry_interval,
4555
backoff_factor: backoff_factor,
56+
retry_statuses: retry_statuses,
57+
retry_methods: retry_methods,
4658
environment: environment,
4759
base_url: base_url,
4860
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
4961
messaging_basic_auth_password: messaging_basic_auth_password,
5062
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
5163
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
64+
phone_number_lookup_basic_auth_user_name: phone_number_lookup_basic_auth_user_name,
65+
phone_number_lookup_basic_auth_password: phone_number_lookup_basic_auth_password,
5266
voice_basic_auth_user_name: voice_basic_auth_user_name,
5367
voice_basic_auth_password: voice_basic_auth_password,
5468
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,

lib/bandwidth/configuration.rb

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Server
1818
DEFAULT = 'default'.freeze,
1919
MESSAGINGDEFAULT = 'MessagingDefault'.freeze,
2020
TWOFACTORAUTHDEFAULT = 'TwoFactorAuthDefault'.freeze,
21+
PHONENUMBERLOOKUPDEFAULT = 'PhoneNumberLookupDefault'.freeze,
2122
VOICEDEFAULT = 'VoiceDefault'.freeze,
2223
WEBRTCDEFAULT = 'WebRtcDefault'.freeze
2324
].freeze
@@ -32,12 +33,16 @@ class Configuration
3233
attr_reader :max_retries
3334
attr_reader :retry_interval
3435
attr_reader :backoff_factor
36+
attr_reader :retry_statuses
37+
attr_reader :retry_methods
3538
attr_reader :environment
3639
attr_reader :base_url
3740
attr_reader :messaging_basic_auth_user_name
3841
attr_reader :messaging_basic_auth_password
3942
attr_reader :two_factor_auth_basic_auth_user_name
4043
attr_reader :two_factor_auth_basic_auth_password
44+
attr_reader :phone_number_lookup_basic_auth_user_name
45+
attr_reader :phone_number_lookup_basic_auth_password
4146
attr_reader :voice_basic_auth_user_name
4247
attr_reader :voice_basic_auth_password
4348
attr_reader :web_rtc_basic_auth_user_name
@@ -48,12 +53,17 @@ class << self
4853
end
4954

5055
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
51-
backoff_factor: 1, environment: Environment::PRODUCTION,
56+
backoff_factor: 2,
57+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
58+
retry_methods: %i[get put get put],
59+
environment: Environment::PRODUCTION,
5260
base_url: 'https://www.example.com',
5361
messaging_basic_auth_user_name: 'TODO: Replace',
5462
messaging_basic_auth_password: 'TODO: Replace',
5563
two_factor_auth_basic_auth_user_name: 'TODO: Replace',
5664
two_factor_auth_basic_auth_password: 'TODO: Replace',
65+
phone_number_lookup_basic_auth_user_name: 'TODO: Replace',
66+
phone_number_lookup_basic_auth_password: 'TODO: Replace',
5767
voice_basic_auth_user_name: 'TODO: Replace',
5868
voice_basic_auth_password: 'TODO: Replace',
5969
web_rtc_basic_auth_user_name: 'TODO: Replace',
@@ -71,6 +81,12 @@ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
7181
# by in order to provide backoff
7282
@backoff_factor = backoff_factor
7383

84+
# A list of HTTP statuses to retry
85+
@retry_statuses = retry_statuses
86+
87+
# A list of HTTP methods to retry
88+
@retry_methods = retry_methods
89+
7490
# Current API environment
7591
@environment = String(environment)
7692

@@ -89,6 +105,12 @@ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
89105
# The password to use with basic authentication
90106
@two_factor_auth_basic_auth_password = two_factor_auth_basic_auth_password
91107

108+
# The username to use with basic authentication
109+
@phone_number_lookup_basic_auth_user_name = phone_number_lookup_basic_auth_user_name
110+
111+
# The password to use with basic authentication
112+
@phone_number_lookup_basic_auth_password = phone_number_lookup_basic_auth_password
113+
92114
# The username to use with basic authentication
93115
@voice_basic_auth_user_name = voice_basic_auth_user_name
94116

@@ -106,11 +128,14 @@ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
106128
end
107129

108130
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
109-
backoff_factor: nil, environment: nil, base_url: nil,
131+
backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
132+
environment: nil, base_url: nil,
110133
messaging_basic_auth_user_name: nil,
111134
messaging_basic_auth_password: nil,
112135
two_factor_auth_basic_auth_user_name: nil,
113136
two_factor_auth_basic_auth_password: nil,
137+
phone_number_lookup_basic_auth_user_name: nil,
138+
phone_number_lookup_basic_auth_password: nil,
114139
voice_basic_auth_user_name: nil,
115140
voice_basic_auth_password: nil,
116141
web_rtc_basic_auth_user_name: nil,
@@ -119,12 +144,16 @@ def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
119144
max_retries ||= self.max_retries
120145
retry_interval ||= self.retry_interval
121146
backoff_factor ||= self.backoff_factor
147+
retry_statuses ||= self.retry_statuses
148+
retry_methods ||= self.retry_methods
122149
environment ||= self.environment
123150
base_url ||= self.base_url
124151
messaging_basic_auth_user_name ||= self.messaging_basic_auth_user_name
125152
messaging_basic_auth_password ||= self.messaging_basic_auth_password
126153
two_factor_auth_basic_auth_user_name ||= self.two_factor_auth_basic_auth_user_name
127154
two_factor_auth_basic_auth_password ||= self.two_factor_auth_basic_auth_password
155+
phone_number_lookup_basic_auth_user_name ||= self.phone_number_lookup_basic_auth_user_name
156+
phone_number_lookup_basic_auth_password ||= self.phone_number_lookup_basic_auth_password
128157
voice_basic_auth_user_name ||= self.voice_basic_auth_user_name
129158
voice_basic_auth_password ||= self.voice_basic_auth_password
130159
web_rtc_basic_auth_user_name ||= self.web_rtc_basic_auth_user_name
@@ -133,11 +162,14 @@ def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
133162
Configuration.new(
134163
timeout: timeout, max_retries: max_retries,
135164
retry_interval: retry_interval, backoff_factor: backoff_factor,
165+
retry_statuses: retry_statuses, retry_methods: retry_methods,
136166
environment: environment, base_url: base_url,
137167
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
138168
messaging_basic_auth_password: messaging_basic_auth_password,
139169
two_factor_auth_basic_auth_user_name: two_factor_auth_basic_auth_user_name,
140170
two_factor_auth_basic_auth_password: two_factor_auth_basic_auth_password,
171+
phone_number_lookup_basic_auth_user_name: phone_number_lookup_basic_auth_user_name,
172+
phone_number_lookup_basic_auth_password: phone_number_lookup_basic_auth_password,
141173
voice_basic_auth_user_name: voice_basic_auth_user_name,
142174
voice_basic_auth_password: voice_basic_auth_password,
143175
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
@@ -148,7 +180,9 @@ def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
148180
def create_http_client
149181
FaradayClient.new(timeout: timeout, max_retries: max_retries,
150182
retry_interval: retry_interval,
151-
backoff_factor: backoff_factor)
183+
backoff_factor: backoff_factor,
184+
retry_statuses: retry_statuses,
185+
retry_methods: retry_methods)
152186
end
153187

154188
# All the environments the SDK can run in.
@@ -157,13 +191,15 @@ def create_http_client
157191
Server::DEFAULT => 'api.bandwidth.com',
158192
Server::MESSAGINGDEFAULT => 'https://messaging.bandwidth.com/api/v2',
159193
Server::TWOFACTORAUTHDEFAULT => 'https://mfa.bandwidth.com/api/v1',
194+
Server::PHONENUMBERLOOKUPDEFAULT => 'https://numbers.bandwidth.com/api/v1',
160195
Server::VOICEDEFAULT => 'https://voice.bandwidth.com',
161196
Server::WEBRTCDEFAULT => 'https://api.webrtc.bandwidth.com/v1'
162197
},
163198
Environment::CUSTOM => {
164199
Server::DEFAULT => '{base_url}',
165200
Server::MESSAGINGDEFAULT => '{base_url}',
166201
Server::TWOFACTORAUTHDEFAULT => '{base_url}',
202+
Server::PHONENUMBERLOOKUPDEFAULT => '{base_url}',
167203
Server::VOICEDEFAULT => '{base_url}',
168204
Server::WEBRTCDEFAULT => '{base_url}'
169205
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# bandwidth
2+
#
3+
# This file was automatically generated by APIMATIC v2.0
4+
# ( https://apimatic.io ).
5+
6+
require 'base64'
7+
8+
module Bandwidth
9+
# Utility class for basic authorization.
10+
class PhoneNumberLookupBasicAuth
11+
# Add basic authentication to the request.
12+
# @param [HttpRequest] The HttpRequest object to which authentication will
13+
# be added.
14+
def self.apply(config, http_request)
15+
username = config.phone_number_lookup_basic_auth_user_name
16+
password = config.phone_number_lookup_basic_auth_password
17+
value = Base64.strict_encode64("#{username}:#{password}")
18+
header_value = "Basic #{value}"
19+
http_request.headers['Authorization'] = header_value
20+
end
21+
end
22+
end

lib/bandwidth/http/faraday_client.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module Bandwidth
1111
class FaradayClient < HttpClient
1212
# The constructor.
1313
def initialize(timeout:, max_retries:, retry_interval:,
14-
backoff_factor:, cache: false, verify: true)
14+
backoff_factor:, retry_statuses:, retry_methods:,
15+
cache: false, verify: true)
1516
@connection = Faraday.new do |faraday|
1617
faraday.use Faraday::HttpCache, serializer: Marshal if cache
1718
faraday.use FaradayMiddleware::FollowRedirects
@@ -21,7 +22,9 @@ def initialize(timeout:, max_retries:, retry_interval:,
2122
faraday.ssl[:ca_file] = Certifi.where
2223
faraday.ssl[:verify] = verify
2324
faraday.request :retry, max: max_retries, interval: retry_interval,
24-
backoff_factor: backoff_factor
25+
backoff_factor: backoff_factor,
26+
retry_statuses: retry_statuses,
27+
methods: retry_methods
2528
faraday.adapter Faraday.default_adapter
2629
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
2730
faraday.options[:timeout] = timeout if timeout > 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# bandwidth
2+
#
3+
# This file was automatically generated by APIMATIC v2.0
4+
# ( https://apimatic.io ).
5+
6+
7+
require_relative 'phone_number_lookup/client.rb'
8+
9+
# Models
10+
require_relative 'phone_number_lookup/models/order_request.rb'
11+
require_relative 'phone_number_lookup/models/order_response.rb'
12+
require_relative 'phone_number_lookup/models/order_status.rb'
13+
require_relative 'phone_number_lookup/models/result.rb'
14+
15+
# Exceptions
16+
require_relative 'phone_number_lookup/exceptions/accounts_tnlookup400_error' \
17+
'_exception.rb'
18+
# Controllers
19+
require_relative 'phone_number_lookup/controllers/base_controller.rb'
20+
require_relative 'phone_number_lookup/controllers/api_controller.rb'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# bandwidth
2+
#
3+
# This file was automatically generated by APIMATIC v2.0
4+
# ( https://apimatic.io ).
5+
6+
module Bandwidth
7+
module PhoneNumberLookup
8+
# bandwidth client class.
9+
class Client
10+
attr_reader :config
11+
12+
# Access to client controller.
13+
# @return [APIController] Returns the controller instance.
14+
def client
15+
@client ||= APIController.new config
16+
end
17+
18+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
19+
backoff_factor: 2,
20+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
21+
retry_methods: %i[get put get put],
22+
environment: Environment::PRODUCTION,
23+
base_url: 'https://www.example.com',
24+
messaging_basic_auth_user_name: 'TODO: Replace',
25+
messaging_basic_auth_password: 'TODO: Replace',
26+
multi_factor_auth_basic_auth_user_name: 'TODO: Replace',
27+
multi_factor_auth_basic_auth_password: 'TODO: Replace',
28+
phone_number_lookup_basic_auth_user_name: 'TODO: Replace',
29+
phone_number_lookup_basic_auth_password: 'TODO: Replace',
30+
voice_basic_auth_user_name: 'TODO: Replace',
31+
voice_basic_auth_password: 'TODO: Replace',
32+
web_rtc_basic_auth_user_name: 'TODO: Replace',
33+
web_rtc_basic_auth_password: 'TODO: Replace',
34+
config: nil)
35+
@config = if config.nil?
36+
Configuration.new(timeout: timeout,
37+
max_retries: max_retries,
38+
retry_interval: retry_interval,
39+
backoff_factor: backoff_factor,
40+
retry_statuses: retry_statuses,
41+
retry_methods: retry_methods,
42+
environment: environment,
43+
base_url: base_url,
44+
messaging_basic_auth_user_name: messaging_basic_auth_user_name,
45+
messaging_basic_auth_password: messaging_basic_auth_password,
46+
multi_factor_auth_basic_auth_user_name: multi_factor_auth_basic_auth_user_name,
47+
multi_factor_auth_basic_auth_password: multi_factor_auth_basic_auth_password,
48+
phone_number_lookup_basic_auth_user_name: phone_number_lookup_basic_auth_user_name,
49+
phone_number_lookup_basic_auth_password: phone_number_lookup_basic_auth_password,
50+
voice_basic_auth_user_name: voice_basic_auth_user_name,
51+
voice_basic_auth_password: voice_basic_auth_password,
52+
web_rtc_basic_auth_user_name: web_rtc_basic_auth_user_name,
53+
web_rtc_basic_auth_password: web_rtc_basic_auth_password)
54+
else
55+
config
56+
end
57+
end
58+
end
59+
end
60+
end

0 commit comments

Comments
 (0)