Class: Restfulness::Request

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

Overview

Simple, indpendent, request interface for dealing with the incoming information in a request.

Currently wraps around the information provided in a Rack Request object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Request

Returns a new instance of Request.



36
37
38
39
40
41
42
43
# File 'lib/restfulness/request.rb', line 36

def initialize(app)
  @app = app

  # Prepare basics
  self.action  = nil
  self.headers = {}
  self.body    = nil
end

Instance Attribute Details

#actionObject

The HTTP action being handled



13
14
15
# File 'lib/restfulness/request.rb', line 13

def action
  @action
end

#appObject (readonly)

Who does this request belong to?



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

def app
  @app
end

#bodyObject

Raw HTTP body, for POST and PUT requests.



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

def body
  @body
end

#headersObject

Hash of HTTP headers. Keys always normalized to lower-case symbols with underscore.



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

def headers
  @headers
end

#pathObject

Path object of the current URL being accessed



22
23
24
# File 'lib/restfulness/request.rb', line 22

def path
  @path
end

#queryObject

Query parameters included in the URL



28
29
30
# File 'lib/restfulness/request.rb', line 28

def query
  @query
end

#remote_ipObject

Additional useful fields



34
35
36
# File 'lib/restfulness/request.rb', line 34

def remote_ip
  @remote_ip
end

#routeObject

The route, determined from the path, if available!



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

def route
  @route
end

#uriObject

Ruby URI object



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

def uri
  @uri
end

#user_agentObject

Additional useful fields



34
35
36
# File 'lib/restfulness/request.rb', line 34

def user_agent
  @user_agent
end

Instance Method Details

#paramsObject



64
65
66
67
68
69
70
71
72
# File 'lib/restfulness/request.rb', line 64

def params
  return @params if @params || body.nil?
  case headers[:content_type]
  when 'application/json'
    @params = MultiJson.decode(body)
  else
    raise HTTPException.new(406)
  end
end