Class: Restfulness::Request
- Inherits:
-
Object
- Object
- Restfulness::Request
- 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
-
#action ⇒ Object
The HTTP action being handled.
-
#app ⇒ Object
readonly
Who does this request belong to?.
-
#body ⇒ Object
Raw HTTP body, for POST and PUT requests.
-
#headers ⇒ Object
Hash of HTTP headers.
-
#path ⇒ Object
Path object of the current URL being accessed.
-
#query ⇒ Object
Query parameters included in the URL.
-
#remote_ip ⇒ Object
Additional useful fields.
-
#route ⇒ Object
The route, determined from the path, if available!.
-
#uri ⇒ Object
Ruby URI object.
-
#user_agent ⇒ Object
Additional useful fields.
Instance Method Summary collapse
-
#initialize(app) ⇒ Request
constructor
A new instance of Request.
- #params ⇒ Object
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
#action ⇒ Object
The HTTP action being handled
13 14 15 |
# File 'lib/restfulness/request.rb', line 13 def action @action end |
#app ⇒ Object (readonly)
Who does this request belong to?
10 11 12 |
# File 'lib/restfulness/request.rb', line 10 def app @app end |
#body ⇒ Object
Raw HTTP body, for POST and PUT requests.
31 32 33 |
# File 'lib/restfulness/request.rb', line 31 def body @body end |
#headers ⇒ Object
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 |
#path ⇒ Object
Path object of the current URL being accessed
22 23 24 |
# File 'lib/restfulness/request.rb', line 22 def path @path end |
#query ⇒ Object
Query parameters included in the URL
28 29 30 |
# File 'lib/restfulness/request.rb', line 28 def query @query end |
#remote_ip ⇒ Object
Additional useful fields
34 35 36 |
# File 'lib/restfulness/request.rb', line 34 def remote_ip @remote_ip end |
#route ⇒ Object
The route, determined from the path, if available!
25 26 27 |
# File 'lib/restfulness/request.rb', line 25 def route @route end |
#uri ⇒ Object
Ruby URI object
19 20 21 |
# File 'lib/restfulness/request.rb', line 19 def uri @uri end |
#user_agent ⇒ Object
Additional useful fields
34 35 36 |
# File 'lib/restfulness/request.rb', line 34 def user_agent @user_agent end |
Instance Method Details
#params ⇒ Object
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 |