Class: Faraday::Adapter::EMSynchrony

Inherits:
Faraday::Adapter show all
Includes:
Faraday::Adapter::EMHttp::Options
Defined in:
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

EventMachine Synchrony adapter.

Defined Under Namespace

Classes: ParallelManager

Constant Summary

Constants inherited from Faraday::Adapter

CONTENT_LENGTH

Instance Attribute Summary

Attributes included from Parallelism

#supports_parallel

Attributes included from DependencyLoader

#load_error

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Faraday::Adapter::EMHttp::Options

#configure_compression, #configure_proxy, #configure_socket, #configure_ssl, #configure_timeout, #connection_config, #read_body, #request_config, #request_options

Methods inherited from Faraday::Adapter

#close, #connection, #initialize

Methods included from Faraday::AutoloadHelper

#all_loaded_constants, #autoload_all, #load_autoloaded_constants

Methods included from Parallelism

#inherited, #supports_parallel?

Methods included from DependencyLoader

#dependency, #inherited, #loaded?, #new

Methods included from MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware, #unregister_middleware

Constructor Details

This class inherits a constructor from Faraday::Adapter

Class Method Details

.setup_parallel_manager(_options = nil) ⇒ ParallelManager

Returns:


36
37
38
# File 'lib/faraday/adapter/em_synchrony.rb', line 36

def self.setup_parallel_manager(_options = nil)
  ParallelManager.new
end

Instance Method Details

#call(env) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/faraday/adapter/em_synchrony.rb', line 40

def call(env)
  super
  request = create_request(env)

  http_method = env[:method].to_s.downcase.to_sym

  if env[:parallel_manager]
    # Queue requests for parallel execution.
    execute_parallel_request(env, request, http_method)
  else
    # Execute single request.
    execute_single_request(env, request, http_method)
  end

  @app.call env
rescue Errno::ECONNREFUSED
  raise Faraday::ConnectionFailed, $ERROR_INFO
rescue EventMachine::Connectify::CONNECTError => e
  if e.message.include?('Proxy Authentication Required')
    raise Faraday::ConnectionFailed,
          %(407 "Proxy Authentication Required")
  end

  raise Faraday::ConnectionFailed, e
rescue Errno::ETIMEDOUT => e
  raise Faraday::TimeoutError, e
rescue RuntimeError => e
  if e.message == 'connection closed by server'
    raise Faraday::ConnectionFailed, e
  end

  raise Faraday::TimeoutError, e if e.message.include?('timeout error')

  raise
rescue StandardError => e
  if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
    raise Faraday::SSLError, e
  end

  raise
end

#create_request(env) ⇒ Object


82
83
84
85
86
87
# File 'lib/faraday/adapter/em_synchrony.rb', line 82

def create_request(env)
  EventMachine::HttpRequest.new(
    Utils::URI(env[:url].to_s),
    connection_config(env).merge(@connection_options)
  )
end