Class: Typhoid::Request

Inherits:
TyphoeusDecorator show all
Defined in:
lib/typhoid/request.rb

Constant Summary collapse

ACCESSOR_OPTIONS =
[
  :method,
  :params,
  :body,
  :headers,
  :cache_key_basis,
  :connect_timeout,
  :timeout,
  :user_agent,
  :response,
  :cache_timeout,
  :follow_location,
  :max_redirects,
  :proxy,
  :proxy_username,
  :proxy_password,
  :disable_ssl_peer_verification,
  :disable_ssl_host_verification,
  :interface,
  :ssl_cert,
  :ssl_cert_type,
  :ssl_key,
  :ssl_key_type,
  :ssl_key_password,
  :ssl_cacert,
  :ssl_capath,
  :ssl_version,
  :verbose,
  :username,
  :password,
  :auth_method,
  :proxy_auth_method,
  :proxy_type
]

Instance Attribute Summary

Attributes inherited from TyphoeusDecorator

#source

Instance Method Summary collapse

Methods inherited from TyphoeusDecorator

#==, #compat, decorate, #initialize, #inspect, inspect, #instance_of?, #kind_of?, method_missing, #method_missing, new, respond_to?, #respond_to?, source_klass

Constructor Details

This class inherits a constructor from Typhoid::TyphoeusDecorator

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Typhoid::TyphoeusDecorator

Instance Method Details

#methodObject

Need to force override, because Object#method



57
58
59
# File 'lib/typhoid/request.rb', line 57

def method
  source.respond_to?(:method) && source.method || options[:method] || :get
end

#optionsObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/typhoid/request.rb', line 61

def options
  if source.respond_to?(:options)
    source.options
  else
    ACCESSOR_OPTIONS.reduce({}) do |hash, key|
      hash[key] = source.send(key) if source.respond_to?(:key)
      hash
    end
  end
end

#responseObject



52
53
54
# File 'lib/typhoid/request.rb', line 52

def response
  compat [:handled_response, :response]
end

#runObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/typhoid/request.rb', line 41

def run
  if Typhoid.typhoeus.major_version == 0
    if Typhoid.typhoeus.minor_version >= 6
      response = source.run
    else
      response = Typhoeus::Request.send(method, url, options)
    end
  end
  Typhoid::Response.new response
end