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
|
# File 'lib/remove_bg/http_connection.rb', line 17
def self.build(api_url = RemoveBg::Api::URL)
retry_options = {
max: 2,
interval: 0.2,
backoff_factor: 2,
methods: [:post],
exceptions: Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed],
}
request_options = Faraday::RequestOptions.new.tap do |req_options|
req_options.timeout = HTTP_BASE_TIMEOUT
req_options.open_timeout = HTTP_BASE_TIMEOUT
req_options.write_timeout = HTTP_WRITE_TIMEOUT
end
http_options = {
headers: { "User-Agent" => USER_AGENT },
request: request_options,
}
Faraday.new(api_url, http_options) do |f|
f.request :multipart
f.request :url_encoded
f.request :retry, retry_options
f.adapter :net_http
end
end
|