Class: AcceptableApi::Request
- Inherits:
-
Object
- Object
- AcceptableApi::Request
- Defined in:
- lib/acceptable_api.rb
Instance Method Summary collapse
-
#initialize(rack_request) ⇒ Request
constructor
A new instance of Request.
- #respond_with(resource) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(rack_request) ⇒ Request
Returns a new instance of Request.
125 126 127 |
# File 'lib/acceptable_api.rb', line 125 def initialize rack_request self.request = rack_request end |
Instance Method Details
#respond_with(resource) ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/acceptable_api.rb', line 129 def respond_with resource accepts = Accepts.new request.env mappers = Mapper.for(resource.class).to(accepts) mapper = mappers[0] code, headers, body = mapper.execute resource, self headers["Content-Length"] = body.bytesize.to_s [ code, headers, body ] end |
#uri ⇒ Object
138 139 140 |
# File 'lib/acceptable_api.rb', line 138 def uri request.url end |