Class: Restify::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/restify/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Request

Returns a new instance of Request.



32
33
34
35
36
37
38
39
40
# File 'lib/restify/request.rb', line 32

def initialize(opts = {})
  @method  = opts.fetch(:method, :get).downcase
  @uri     = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' }
  @data    = opts.fetch(:data, nil)
  @timeout = opts.fetch(:timeout, 300)
  @headers = opts.fetch(:headers, {})

  @headers['Content-Type'] ||= 'application/json' if json?
end

Instance Attribute Details

#dataObject (readonly)

Request data.



20
21
22
# File 'lib/restify/request.rb', line 20

def data
  @data
end

#headersObject (readonly)

Request headers



24
25
26
# File 'lib/restify/request.rb', line 24

def headers
  @headers
end

#methodString (readonly)

HTTP method.

Returns:

  • (String)

    HTTP method.



10
11
12
# File 'lib/restify/request.rb', line 10

def method
  @method
end

#timeoutObject (readonly)

Request timeout in seconds

Defaults to 300 seconds.



30
31
32
# File 'lib/restify/request.rb', line 30

def timeout
  @timeout
end

#uriString (readonly)

Request URI.

Returns:

  • (String)

    Request URI.



16
17
18
# File 'lib/restify/request.rb', line 16

def uri
  @uri
end

Instance Method Details

#bodyObject



42
43
44
# File 'lib/restify/request.rb', line 42

def body
  @body ||= json? ? JSON.dump(@data) : @data
end

#to_sObject



46
47
48
# File 'lib/restify/request.rb', line 46

def to_s
  "#<#{self.class} #{method.upcase} #{uri}>"
end