Class: HttpStub::Server::Request::SinatraRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/http_stub/server/request/sinatra_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rack_request, sinatra_parameters) ⇒ SinatraRequest

Returns a new instance of SinatraRequest.


9
10
11
12
13
14
15
16
# File 'lib/http_stub/server/request/sinatra_request.rb', line 9

def initialize(rack_request, sinatra_parameters)
  @base_uri   = rack_request.base_url
  @uri        = rack_request.path_info
  @method     = rack_request.request_method.downcase
  @headers    = HttpStub::Server::Request::Headers.create(rack_request)
  @parameters = HttpStub::Server::Request::Parameters.create(sinatra_parameters)
  @body       = rack_request.body.read.tap { rack_request.body.rewind }
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def base_uri
  @base_uri
end

#bodyObject (readonly)

Returns the value of attribute body


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def method
  @method
end

#parametersObject (readonly)

Returns the value of attribute parameters


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def parameters
  @parameters
end

#uriObject (readonly)

Returns the value of attribute uri


7
8
9
# File 'lib/http_stub/server/request/sinatra_request.rb', line 7

def uri
  @uri
end

Instance Method Details

#to_json(*args) ⇒ Object


18
19
20
# File 'lib/http_stub/server/request/sinatra_request.rb', line 18

def to_json(*args)
  { uri: @uri, method: @method, headers: @headers, parameters: @parameters, body: @body }.to_json(*args)
end