Module: SmoothOperator::Operators::Faraday

Extended by:
Faraday
Included in:
Faraday
Defined in:
lib/smooth_operator/operators/faraday.rb

Instance Method Summary collapse

Instance Method Details

#generate_connection(adapter = nil, options = nil) ⇒ Object

def generate_parallel_connection

generate_connection(:typhoeus)

end



17
18
19
20
21
22
23
24
25
# File 'lib/smooth_operator/operators/faraday.rb', line 17

def generate_connection(adapter = nil, options = nil)
  adapter ||= :net_http

  ::Faraday.new(url: options[:endpoint]) do |builder|
    builder.options[:timeout] = options[:timeout].to_i unless Helpers.blank?(options[:timeout])
    builder.request :url_encoded
    builder.adapter adapter
  end
end

#make_the_call(http_verb, resource_path, params, body, options) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/smooth_operator/operators/faraday.rb', line 27

def make_the_call(http_verb, resource_path, params, body, options)
  connection, request_options, options = strip_options(options)

  remote_call = begin
    set_basic_authentication(connection, options)

    response = connection.send(http_verb, resource_path) do |request|
      request_configuration(request, request_options, options, params, body)
    end

    RemoteCall::Faraday.new(response)
  rescue ::Faraday::Error::ConnectionFailed
    RemoteCall::Errors::ConnectionFailed.new(response)
  rescue ::Faraday::Error::TimeoutError
    RemoteCall::Errors::Timeout.new(response)
  end

  block_given? ? yield(remote_call) : remote_call
end