Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions happi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -23,8 +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-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'

Expand All @@ -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
18 changes: 14 additions & 4 deletions lib/happi/client.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -94,21 +95,30 @@ def param_check(params)
end]
end

def retry_options
{
max: 3,
interval: 0.05,
interval_randomness: 0.5,
backoff_factor: 2
}
end
Copy link
Member Author

@jbat jbat Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now went with retry option examples as per usage doc

Above results in a first interval that is random between 0.05 and 0.075 and a second interval that is random between 0.1 and 0.125.


def connection
@connection ||= Faraday.new(config.host) do |f|
f.use FaradayMiddleware::OAuth2, config.oauth_token, connection_options
f.use JSON, content_type: 'application/json'
f.request :authorization, 'Bearer', -> { config.oauth_token }
f.request :retry, **retry_options
f.use Faraday::FollowRedirects::Middleware # default limit is 3

if self.config.use_json
f.use FaradayMiddleware::EncodeJson
f.request :json
f.response :json
else
f.request :multipart
f.request :url_encoded
end

f.adapter :net_http
f.adapter :http
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/happi/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Happi
VERSION = '1.0.0-rc'
VERSION = '1.0.0-rc2'
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'simplecov'
require 'pry'

SimpleCov.start

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
Expand Down