From 6ea907ccc0e7590d21932873443836894f409c80 Mon Sep 17 00:00:00 2001 From: Thadeu Esteves Jr Date: Fri, 14 Jul 2023 16:42:33 -0300 Subject: [PATCH 1/3] added support to use proxy via ENV --- lib/mundi_api/http/faraday_client.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mundi_api/http/faraday_client.rb b/lib/mundi_api/http/faraday_client.rb index 2d3acfe..833e676 100644 --- a/lib/mundi_api/http/faraday_client.rb +++ b/lib/mundi_api/http/faraday_client.rb @@ -18,6 +18,7 @@ def initialize(timeout: nil, cache: false, faraday.request :multipart faraday.request :url_encoded faraday.ssl[:ca_file] = Certifi.where + faraday.proxy = ENV['FARADAY_PROXY'] if ENV['FARADAY_PROXY'] faraday.request :retry, max: max_retries, interval: if max_retries && retry_interval retry_interval From 3b0b4564f3d603f710ff8a2686612443cb0bd0dc Mon Sep 17 00:00:00 2001 From: Thadeu Esteves Jr Date: Fri, 14 Jul 2023 16:43:09 -0300 Subject: [PATCH 2/3] required_ruby_version < 3.1 --- mundi_api.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mundi_api.gemspec b/mundi_api.gemspec index 1776adb..f0c66fd 100644 --- a/mundi_api.gemspec +++ b/mundi_api.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.add_dependency('test-unit', '~> 3.1', '>= 3.1.5') s.add_dependency('certifi', '~> 2016') s.add_dependency('faraday-http-cache', '~> 1.2', '>= 1.2.2') - s.required_ruby_version = '~> 2.0' + s.required_ruby_version = '< 3.1' s.files = Dir['{bin,lib,man,test,spec}/**/*', 'README*', 'LICENSE*'] s.require_paths = ['lib'] end From fd93a866b0420428881a10a78c220f3963b64634 Mon Sep 17 00:00:00 2001 From: Thadeu Esteves Jr Date: Fri, 14 Jul 2023 16:54:59 -0300 Subject: [PATCH 3/3] added support to pass proxy in MundiApiClient instance --- lib/mundi_api/configuration.rb | 10 +++++----- lib/mundi_api/http/faraday_client.rb | 10 +++------- lib/mundi_api/mundi_api_client.rb | 13 +++++-------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/mundi_api/configuration.rb b/lib/mundi_api/configuration.rb index 37156a5..6d030dd 100644 --- a/lib/mundi_api/configuration.rb +++ b/lib/mundi_api/configuration.rb @@ -19,13 +19,13 @@ class Configuration # The password to use with basic authentication @basic_auth_password = 'TODO: Replace' + # The proxy server to use for the request + @proxy = nil + # The attribute accessors for public properties. class << self - attr_accessor :array_serialization - attr_accessor :base_uri - attr_accessor :service_referer_name - attr_accessor :basic_auth_user_name - attr_accessor :basic_auth_password + attr_accessor :array_serialization, :base_uri, :service_referer_name, :basic_auth_user_name, + :basic_auth_password, :proxy end end end diff --git a/lib/mundi_api/http/faraday_client.rb b/lib/mundi_api/http/faraday_client.rb index 833e676..a366d13 100644 --- a/lib/mundi_api/http/faraday_client.rb +++ b/lib/mundi_api/http/faraday_client.rb @@ -18,7 +18,7 @@ def initialize(timeout: nil, cache: false, faraday.request :multipart faraday.request :url_encoded faraday.ssl[:ca_file] = Certifi.where - faraday.proxy = ENV['FARADAY_PROXY'] if ENV['FARADAY_PROXY'] + faraday.proxy = Configuration.proxy if Configuration.proxy faraday.request :retry, max: max_retries, interval: if max_retries && retry_interval retry_interval @@ -36,9 +36,7 @@ def execute_as_string(http_request) http_request.query_url ) do |request| request.headers = http_request.headers - unless http_request.parameters.empty? - request.body = http_request.parameters - end + request.body = http_request.parameters unless http_request.parameters.empty? end convert_response(response) end @@ -50,9 +48,7 @@ def execute_as_binary(http_request) http_request.query_url ) do |request| request.headers = http_request.headers - unless http_request.parameters.empty? - request.body = http_request.parameters - end + request.body = http_request.parameters unless http_request.parameters.empty? end convert_response(response) end diff --git a/lib/mundi_api/mundi_api_client.rb b/lib/mundi_api/mundi_api_client.rb index daed90e..5585b0b 100644 --- a/lib/mundi_api/mundi_api_client.rb +++ b/lib/mundi_api/mundi_api_client.rb @@ -73,14 +73,11 @@ def config end # Initializer with authentication and configuration parameters. - def initialize(service_referer_name: nil, basic_auth_user_name: nil, - basic_auth_password: nil) - Configuration.service_referer_name = service_referer_name if - service_referer_name - Configuration.basic_auth_user_name = basic_auth_user_name if - basic_auth_user_name - Configuration.basic_auth_password = basic_auth_password if - basic_auth_password + def initialize(service_referer_name: nil, basic_auth_user_name: nil, basic_auth_password: nil, proxy: nil) + Configuration.service_referer_name = service_referer_name if service_referer_name + Configuration.basic_auth_user_name = basic_auth_user_name if basic_auth_user_name + Configuration.basic_auth_password = basic_auth_password if basic_auth_password + Configuration.proxy = proxy if proxy end end end