Module: SmoothOperator::Operators::Typhoeus

Extended by:
Typhoeus
Included in:
Typhoeus
Defined in:
lib/smooth_operator/operators/typhoeus.rb

Instance Method Summary collapse

Instance Method Details

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



16
17
18
# File 'lib/smooth_operator/operators/typhoeus.rb', line 16

def generate_connection(adapter = nil, options = nil)
  ConnectionWrapper.new(::Typhoeus::Hydra::hydra)
end

#generate_parallel_connectionObject



12
13
14
# File 'lib/smooth_operator/operators/typhoeus.rb', line 12

def generate_parallel_connection
  generate_connection
end

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smooth_operator/operators/typhoeus.rb', line 20

def make_the_call(http_verb, resource_path, params, body, options)
  request = ::Typhoeus::Request.new *typhoeus_request_args(http_verb, resource_path, params, body, options)

  hydra = (options[:connection] || generate_connection).connection

  request_result = nil

  hydra.queue(request)

  request.on_complete do |typhoeus_response|
    remote_call = remote_call(typhoeus_response)

    if block_given?
      request_result = yield(remote_call)
    else
      request_result = remote_call
    end
  end

  hydra.run if Helpers.blank?(options[:connection])

  request_result
end