-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathconnection.rb
More file actions
40 lines (36 loc) · 1.52 KB
/
connection.rb
File metadata and controls
40 lines (36 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
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
# frozen_string_literal: true
module Slack
module Web
module Faraday
module Connection
private
def connection
@connection ||=
begin
options = {
headers: { 'Accept' => 'application/json; charset=utf-8' }
}
options[:headers]['User-Agent'] = user_agent if user_agent
options[:proxy] = proxy if proxy
options[:ssl] = { ca_path: ca_path, ca_file: ca_file } if ca_path || ca_file
request_options = {}
request_options[:timeout] = timeout if timeout
request_options[:open_timeout] = open_timeout if open_timeout
options[:request] = request_options if request_options.any?
::Faraday::Connection.new(endpoint, options) do |connection|
connection.use ::Faraday::Request::Multipart
connection.use ::Faraday::Request::UrlEncoded
connection.use ::Slack::Web::Faraday::Response::RaiseError
connection.use ::FaradayMiddleware::Mashify, mash_class: Slack::Messages::Message
connection.use ::FaradayMiddleware::ParseJson
connection.use ::Slack::Web::Faraday::Response::WrapError
connection.use ::Slack::Web::Faraday::Response::StoreScopes, client: self if store_scopes
connection.response :logger, logger if logger
connection.adapter adapter
end
end
end
end
end
end
end