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.



25
26
27
28
29
30
31
# File 'lib/restify/request.rb', line 25

def initialize(opts = {})
  @method  = opts.fetch(:method, :get).downcase
  @uri     = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' }
  @data    = opts.fetch(:data, nil)
  @headers = opts.fetch(:headers, {}).merge \
    'Content-Type' => 'application/json'
end

Instance Attribute Details

#dataObject (readonly)

Request data.



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

def data
  @data
end

#headersObject (readonly)

Request headers



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

def headers
  @headers
end

#methodString (readonly)

HTTP method.

Returns:

  • (String)

    HTTP method.



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

def method
  @method
end

#uriString (readonly)

Request URI.

Returns:

  • (String)

    Request URI.



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

def uri
  @uri
end

Instance Method Details

#bodyObject



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

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