Module: Typhoeus::Request::Operations

Included in:
Typhoeus::Request
Defined in:
lib/typhoeus/request/operations.rb

Overview

This module contains everything what is necessary to make a single request.

Since:

  • 0.5.0

Instance Method Summary collapse

Instance Method Details

#finish(response, bypass_memoization = nil) ⇒ Typhoeus::Response

Sets a response, the request on the response and executes the callbacks.

Parameters:

  • response (Typhoeus::Response)

    The response.

  • bypass_memoization (Boolean) (defaults to: nil)

    Wether to bypass memoization or not. Decides how the response is set.

Returns:

Since:

  • 0.5.0



40
41
42
43
44
45
46
47
48
49
# File 'lib/typhoeus/request/operations.rb', line 40

def finish(response, bypass_memoization = nil)
  if bypass_memoization
    @response = response
  else
    self.response = response
  end
  self.response.request = self
  execute_callbacks
  response
end

#runResponse

Run a request.

Examples:

Run a request.

Typhoeus::Request.new("www.example.com").run

Returns:

Since:

  • 0.5.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/typhoeus/request/operations.rb', line 14

def run
  easy = Typhoeus.get_easy
  begin
    easy.http_request(
      base_url,
      options.fetch(:method, :get),
      options.reject{|k,_| k==:method}
    )
  rescue Ethon::Errors::InvalidOption => e
    help = provide_help(e.message.match(/:\s(\w+)/)[1])
    raise $!, "#{$!}#{help}", $!.backtrace
  end
  easy.perform
  finish(Response.new(easy.to_hash))
  Typhoeus.release_easy(easy)
  response
end