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



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smooth_operator/operators/faraday.rb', line 20

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

  # new_connection = ::Faraday.new(url: options[:endpoint]) do |builder|
  new_connection = ::Faraday::Connection.new(options[:endpoint], options[:connection_options]) do |builder|
    builder.options[:timeout] = options[:timeout].to_i unless Helpers.blank?(options[:timeout])

    builder.request :url_encoded
    builder.adapter adapter
  end

  ConnectionWrapper.new new_connection
end

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/smooth_operator/operators/faraday.rb', line 34

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