Module: Sinew::Connection
- Defined in:
- lib/sinew/connection.rb,
lib/sinew/connection/rate_limit.rb,
lib/sinew/connection/log_formatter.rb
Defined Under Namespace
Classes: LogFormatter, RateLimit
Class Method Summary collapse
Class Method Details
.create(options:, runtime_options:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sinew/connection.rb', line 10 def self.create(options:, runtime_options:) = {} [:ssl] = { verify: false } if .insecure Faraday.new(nil, ) do _1.use RateLimit, rate_limit: .rate_limit # auto-encode form bodies _1.request :url_encoded # Before httpdisk so each redirect segment is cached # Keep track of redirect status for logger _1.response :follow_redirects, callback: ->(_old_env, new_env) { new_env[:redirect] = true } # set Ruby string encoding based on Content-Type (should be above httpdisk) _1.response :encoding # disk caching = { dir: [:cache], force: [:force], force_errors: [:force_errors], }.merge(.) _1.use :httpdisk, # After httpdisk so that only non-cached requests are logged. # Before retry so that we don't log each retry attempt. _1.response :logger, nil, formatter: LogFormatter if ![:quiet] # After httpdisk so transient failures are not cached = { interval: .rate_limit, max: .retries, methods: %w[delete get head options patch post put trace], retry_statuses: (500..600).to_a, retry_if: ->(_env, _err) { true }, } _1.request :retry, end end |