From 6e51e75b46aaf7bcbfa28f4f33b836613f2b51f4 Mon Sep 17 00:00:00 2001 From: jbat Date: Tue, 8 Jul 2025 08:27:42 +1000 Subject: [PATCH 1/5] [NEP-19931] bump to rc2, add oauth --- happi.gemspec | 1 + lib/happi/client.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/happi.gemspec b/happi.gemspec index efa5630..c99bc14 100644 --- a/happi.gemspec +++ b/happi.gemspec @@ -23,6 +23,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'faraday-follow_redirects', '~> 0.3' spec.add_dependency 'faraday-http', '~> 2.0' spec.add_dependency 'faraday-multipart', '~> 1.1' + spec.add_dependency 'faraday-oauth', '~> 0.1' spec.add_dependency 'activemodel', '>= 6.0' spec.add_dependency 'oauth2', '~> 2.0' spec.add_dependency 'mime-types', '~> 3.7' diff --git a/lib/happi/client.rb b/lib/happi/client.rb index 589f997..bafaa0c 100644 --- a/lib/happi/client.rb +++ b/lib/happi/client.rb @@ -2,6 +2,7 @@ require 'faraday/follow_redirects' require 'faraday/multipart' require 'faraday/http' +require 'faraday/oauth' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/hash' @@ -96,11 +97,11 @@ def param_check(params) def connection @connection ||= Faraday.new(config.host) do |f| - f.use FaradayMiddleware::OAuth2, config.oauth_token, connection_options + f.use Faraday::OAuth, config.oauth_token, connection_options + f.use Faraday::FollowRedirects::Middleware f.use JSON, content_type: 'application/json' if self.config.use_json - f.use FaradayMiddleware::EncodeJson f.request :json f.response :json else @@ -108,7 +109,7 @@ def connection f.request :url_encoded end - f.adapter :net_http + f.adapter :http end end From 190813c38bbac7de6201832204ebefd1b599ae55 Mon Sep 17 00:00:00 2001 From: jbat Date: Thu, 10 Jul 2025 09:28:01 +1000 Subject: [PATCH 2/5] add middleware --- happi.gemspec | 3 +-- lib/happi/client.rb | 6 ++---- lib/happi/version.rb | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/happi.gemspec b/happi.gemspec index c99bc14..e573bdd 100644 --- a/happi.gemspec +++ b/happi.gemspec @@ -23,9 +23,8 @@ Gem::Specification.new do |spec| spec.add_dependency 'faraday-follow_redirects', '~> 0.3' spec.add_dependency 'faraday-http', '~> 2.0' spec.add_dependency 'faraday-multipart', '~> 1.1' - spec.add_dependency 'faraday-oauth', '~> 0.1' + spec.add_dependency 'faraday-retry', '~> 2.3' spec.add_dependency 'activemodel', '>= 6.0' - spec.add_dependency 'oauth2', '~> 2.0' spec.add_dependency 'mime-types', '~> 3.7' spec.add_dependency 'multi_json', '~> 1.15' diff --git a/lib/happi/client.rb b/lib/happi/client.rb index bafaa0c..d156df0 100644 --- a/lib/happi/client.rb +++ b/lib/happi/client.rb @@ -2,7 +2,6 @@ require 'faraday/follow_redirects' require 'faraday/multipart' require 'faraday/http' -require 'faraday/oauth' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/hash' @@ -97,9 +96,8 @@ def param_check(params) def connection @connection ||= Faraday.new(config.host) do |f| - f.use Faraday::OAuth, config.oauth_token, connection_options - f.use Faraday::FollowRedirects::Middleware - f.use JSON, content_type: 'application/json' + f.request :authorization, 'Bearer', -> { config.oauth_token } + f.use Faraday::FollowRedirects::Middleware, limit: 3 if self.config.use_json f.request :json diff --git a/lib/happi/version.rb b/lib/happi/version.rb index 5395065..4a465cd 100644 --- a/lib/happi/version.rb +++ b/lib/happi/version.rb @@ -1,3 +1,3 @@ module Happi - VERSION = '1.0.0-rc' + VERSION = '1.0.0-rc2' end From 0222bda57e523307450fec123d351effbcbff9c4 Mon Sep 17 00:00:00 2001 From: jbat Date: Thu, 10 Jul 2025 09:55:40 +1000 Subject: [PATCH 3/5] add retry with defaults --- happi.gemspec | 2 +- lib/happi/client.rb | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/happi.gemspec b/happi.gemspec index e573bdd..ba43c34 100644 --- a/happi.gemspec +++ b/happi.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.summary = %q{Simple faraday client wrapper preconfigured for specific usecase} spec.homepage = "https://github.com/rdytech/happi" spec.license = "MIT" - spec.required_ruby_version = '>= 3.2.0' + spec.required_ruby_version = '>= 3.2.0' # faraday gem supports only non-EOL versions of Ruby spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } diff --git a/lib/happi/client.rb b/lib/happi/client.rb index d156df0..42f5717 100644 --- a/lib/happi/client.rb +++ b/lib/happi/client.rb @@ -94,10 +94,20 @@ def param_check(params) end] end + def retry_options + { + max: 3, + interval: 0.05, + interval_randomness: 0.5, + backoff_factor: 2 + } + end + def connection @connection ||= Faraday.new(config.host) do |f| f.request :authorization, 'Bearer', -> { config.oauth_token } - f.use Faraday::FollowRedirects::Middleware, limit: 3 + f.request :retry, retry_options + f.use Faraday::FollowRedirects::Middleware # default limit is 3 if self.config.use_json f.request :json From a37cf772f997136b4168aedcb5a92ac116a7a135 Mon Sep 17 00:00:00 2001 From: jbat Date: Thu, 10 Jul 2025 10:32:16 +1000 Subject: [PATCH 4/5] splat retry_options, add pry --- happi.gemspec | 1 + lib/happi/client.rb | 2 +- spec/spec_helper.rb | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/happi.gemspec b/happi.gemspec index ba43c34..3eb780a 100644 --- a/happi.gemspec +++ b/happi.gemspec @@ -34,4 +34,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake' spec.add_development_dependency 'rspec' spec.add_development_dependency 'rack-test' + spec.add_development_dependency 'pry' end diff --git a/lib/happi/client.rb b/lib/happi/client.rb index 42f5717..5175385 100644 --- a/lib/happi/client.rb +++ b/lib/happi/client.rb @@ -106,7 +106,7 @@ def retry_options def connection @connection ||= Faraday.new(config.host) do |f| f.request :authorization, 'Bearer', -> { config.oauth_token } - f.request :retry, retry_options + f.request :retry, **retry_options f.use Faraday::FollowRedirects::Middleware # default limit is 3 if self.config.use_json diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8975320..d49427e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,6 @@ require 'simplecov' +require 'pry' + SimpleCov.start $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) From 68a381827615b0350cb6be607d9e0cc7f7d994ab Mon Sep 17 00:00:00 2001 From: jbat Date: Thu, 10 Jul 2025 11:09:10 +1000 Subject: [PATCH 5/5] add require retry --- lib/happi/client.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/happi/client.rb b/lib/happi/client.rb index 5175385..b8c2c14 100644 --- a/lib/happi/client.rb +++ b/lib/happi/client.rb @@ -1,6 +1,7 @@ require 'faraday' require 'faraday/follow_redirects' require 'faraday/multipart' +require 'faraday/retry' require 'faraday/http' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/hash'