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.



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

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

Instance Attribute Details

#dataObject (readonly)

Request data.



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

def data
  @data
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



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

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

#headersObject



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

def headers
  {
    'Content-Type' => 'application/json'
  }
end