@@ -3,40 +3,31 @@ module Slack
33 module Web
44 module Faraday
55 module Connection
6- def create_connection ( expect_json_response : true )
7- options = {
8- headers : { 'Accept' => 'application/json; charset=utf-8' }
9- }
10- options [ :headers ] [ 'User-Agent' ] = user_agent if user_agent
11- options [ :proxy ] = proxy if proxy
12- options [ :ssl ] = { ca_path : ca_path , ca_file : ca_file } if ca_path || ca_file
6+ include ConnectionOptions
137
14- request_options = { }
15- request_options [ :timeout ] = timeout if timeout
16- request_options [ :open_timeout ] = open_timeout if open_timeout
17- options [ :request ] = request_options if request_options . any?
8+ private
189
19- ::Faraday ::Connection . new ( endpoint , options ) do |connection |
20- connection . request :multipart
21- connection . request :url_encoded
22- connection . use ::Slack ::Web ::Faraday ::Response ::RaiseError if expect_json_response
23- connection . response :mashify , mash_class : Slack ::Messages ::Message
24- connection . response :json , content_type : /\b *$/ if expect_json_response
25- connection . use ::Slack ::Web ::Faraday ::Response ::WrapError
26- connection . response :logger , logger if logger
27- connection . adapter adapter
10+ def options
11+ @options ||= begin
12+ options = connection_options . dup
13+ options [ :headers ] [ 'Accept' ] = 'application/json; charset=utf-8'
14+ options
2815 end
2916 end
3017
3118 def connection
32- @connection ||= create_connection
19+ @connection ||=
20+ ::Faraday ::Connection . new ( endpoint , options ) do |connection |
21+ connection . request :multipart
22+ connection . request :url_encoded
23+ connection . use ::Slack ::Web ::Faraday ::Response ::RaiseError
24+ connection . response :mashify , mash_class : Slack ::Messages ::Message
25+ connection . response :json , content_type : /\b *$/
26+ connection . use ::Slack ::Web ::Faraday ::Response ::WrapError
27+ connection . response :logger , logger if logger
28+ connection . adapter adapter
29+ end
3330 end
34-
35- def connection_without_response_parsing
36- @connection_without_response_parsing ||= create_connection ( expect_json_response : false )
37- end
38-
39- private :create_connection
4031 end
4132 end
4233 end
0 commit comments