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.



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

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, {}).merge \
    'Content-Type' => 'application/json'
end

Instance Attribute Details

#dataObject (readonly)

Request data.



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

def data
  @data
end

#headersObject (readonly)

Request headers



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

def headers
  @headers
end

#methodString (readonly)

HTTP method.

Returns:

  • (String)

    HTTP method.



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

def method
  @method
end

#timeoutObject (readonly)

Request timeout in seconds

Defaults to 300 seconds.



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

def timeout
  @timeout
end

#uriString (readonly)

Request URI.

Returns:

  • (String)

    Request URI.



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

def uri
  @uri
end

Instance Method Details

#bodyObject



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

def body
  @body ||= begin
    JSON.dump(data) unless data.nil?
  end
end

#to_sObject



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

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