module Typhoeus::Request::Operations

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

Public Instance Methods

finish(response, bypass_memoization = nil) click to toggle source

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

@param [Typhoeus::Response] response The response. @param [Boolean] bypass_memoization Wether to bypass

memoization or not. Decides how the response is set.

@return [Typhoeus::Response] The response.

# File lib/typhoeus/request/operations.rb, line 41
def finish(response, bypass_memoization = nil)
  if bypass_memoization
    @response = response
  else
    self.response = response
  end
  self.response.request = self
  execute_callbacks
  response
end
run() click to toggle source

Run a request.

@example Run a request.

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

@return [ Response ] The response.

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