Class: Typhoeus::Request

Inherits:
Object
  • Object
show all
Extended by:
Actions
Includes:
Before, BlockConnection, Callbacks, Callbacks::Types, Marshal, Memoizable, Operations, Responseable, Stubbable
Defined in:
lib/typhoeus/request.rb,
lib/typhoeus/request/before.rb,
lib/typhoeus/request/actions.rb,
lib/typhoeus/request/marshal.rb,
lib/typhoeus/request/callbacks.rb,
lib/typhoeus/request/stubbable.rb,
lib/typhoeus/request/memoizable.rb,
lib/typhoeus/request/operations.rb,
lib/typhoeus/request/responseable.rb,
lib/typhoeus/request/block_connection.rb

Overview

This class represents a request.

Examples:

Make a request with the shortcut.

response = Typhoeus.get("www.example.com")

Simplest request.

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

Request with url parameters.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1}
).run

Request with a body.

response = Typhoeus::Request.new(
  "www.example.com",
  body: {b: 2}
).run

Request with parameters and body.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1},
  body: {b: 2}
).run

Create a request and allow follow redirections.

response = Typhoeus::Request.new(
  "www.example.com",
  followlocation: true
).run

See Also:

Since:

  • 0.5.0

Defined Under Namespace

Modules: Actions, Before, BlockConnection, Callbacks, Marshal, Memoizable, Operations, Responseable, Stubbable

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actions

delete, get, head, patch, post, put

Methods included from Before

#run

Methods included from Stubbable

#run

Methods included from BlockConnection

#blocked?, #run

Methods included from Memoizable

#memoizable?, #response=

Methods included from Responseable

#response, #response=

Methods included from Operations

#finish, #run

Methods included from Marshal

#marshal_dump, #marshal_load

Methods included from Callbacks

#execute_callbacks

Methods included from Callbacks::Types

#on_complete, #on_failure, #on_success

Constructor Details

#initialize(url, options = {}) ⇒ Typhoeus::Request

Note:

See Ethon::Easy#initialize for more options.

Create a new request.

Examples:

Simplest request.

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

Request with url parameters.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1}
).run

Request with a body.

response = Typhoeus::Request.new(
  "www.example.com",
  body: {b: 2}
).run

Request with parameters and body.

response = Typhoeus::Request.new(
  "www.example.com",
  params: {a: 1},
  body: {b: 2}
).run

Create a request and allow follow redirections.

response = Typhoeus::Request.new(
  "www.example.com",
  followlocation: true
).run

Parameters:

  • url (String)

    The url to request.

  • options (options) (defaults to: {})

    The options.

Options Hash (options):

  • :params (Hash)

    Translated into url parameters.

  • :body (Hash)

    Translated into HTTP POST request body.

See Also:

Since:

  • 0.5.0



107
108
109
110
111
112
113
# File 'lib/typhoeus/request.rb', line 107

def initialize(url, options = {})
  @url = url
  @original_options = options
  @options = options.dup

  set_defaults
end

Instance Attribute Details

#block_connectionBoolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.5.0



60
61
62
# File 'lib/typhoeus/request.rb', line 60

def block_connection
  @block_connection
end

#hydraTyphoeus::Hydra

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the hydra the request ran into if any.

Returns:

Since:

  • 0.5.0



48
49
50
# File 'lib/typhoeus/request.rb', line 48

def hydra
  @hydra
end

#optionsHash

Returns options, which includes default parameters.

Returns:

  • (Hash)

Since:

  • 0.5.0



41
42
43
# File 'lib/typhoeus/request.rb', line 41

def options
  @options
end

#original_optionsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the original options provided.

Returns:

  • (Hash)

Since:

  • 0.5.0



55
56
57
# File 'lib/typhoeus/request.rb', line 55

def original_options
  @original_options
end

#urlString

Returns the provided url.

Returns:

  • (String)

Since:

  • 0.5.0



36
37
38
# File 'lib/typhoeus/request.rb', line 36

def url
  @url
end

Instance Method Details

#eql?(other) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns wether other is equal to self.

Examples:

Are request equal?

request.eql?(other_request)

Parameters:

  • other (Object)

    The object to check.

Returns:

  • (Boolean)

    Returns true if equals, else false.

Since:

  • 0.5.0



125
126
127
128
129
# File 'lib/typhoeus/request.rb', line 125

def eql?(other)
  self.class == other.class &&
    self.url == other.url &&
    fuzzy_hash_eql?(self.options, other.options)
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overrides Object#hash.

Returns:

  • (Integer)

    The integer representing the request.

Since:

  • 0.5.0



136
137
138
# File 'lib/typhoeus/request.rb', line 136

def hash
  [ self.class, self.url, self.options ].hash
end