Skip to main content

Adding Support to Configure Adapter during Client Initialization of Ruby SDKs

ยท 2 min read

APIMatic CodeGen has now added support to configure the default Faraday connection with available Faraday adapters in Ruby SDKs.

Detailsโ€‹

For this support, a new keyword adapter has been added in the client initialization. The adapters default value will be adapter: Faraday.default_adapter which can be overridden with the available adapters listed here.

What has Changed?โ€‹

Changes in Faraday Clientโ€‹

Faraday Client will be configured with the adapter being passed from the Ruby SDK user shown below:

def create_connection(timeout:, max_retries:, retry_interval:,
backoff_factor:, retry_statuses:, retry_methods:,
adapter:, cache: false, verify: true)
Faraday.new do |faraday|
faraday.use Faraday::HttpCache, serializer: Marshal if cache
faraday.use Faraday::FollowRedirects::Middleware
faraday.request :gzip
faraday.request :multipart
faraday.request :url_encoded
faraday.ssl[:ca_file] = Certifi.where
faraday.ssl[:verify] = verify
faraday.request :retry, max: max_retries, interval: retry_interval,
backoff_factor: backoff_factor,
retry_statuses: retry_statuses,
methods: retry_methods,
retry_if: proc { |env, _exc|
env.request.context['forced_retry'] ||= false
}
faraday.adapter adapter
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
faraday.options[:timeout] = timeout if timeout.positive?
end
end

Changes in Configuration and Clientโ€‹

A new keyword adapter has been added in the configuration and client as well.

Configurationโ€‹

def initialize(connection: nil, adapter: Faraday.default_adapter,
timeout: 60, max_retries: 0, retry_interval: 1,
backoff_factor: 2,
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522,524],
retry_methods: %i[get put], environment: 'production',additional_headers: {})

Clientโ€‹

def initialize(connection: nil, adapter: Faraday.default_adapter,
timeout: 60, max_retries: 0, retry_interval: 1,
backoff_factor: 2,
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
retry_methods: %i[get put], environment: 'production',
additional_headers: {}, config: nil)