Class: Slash::Formats::Format
- Inherits:
-
Object
- Object
- Slash::Formats::Format
- Defined in:
- lib/slash/formats.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#mime ⇒ Object
readonly
Returns the value of attribute mime.
Instance Method Summary collapse
-
#initialize(options) ⇒ Format
constructor
A new instance of Format.
- #interpret_response(response) ⇒ Object
- #prepare_request(options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Format
Returns a new instance of Format.
19 20 21 22 |
# File 'lib/slash/formats.rb', line 19 def initialize() @codec = [:codec] @mime = [:mime] || (@codec.respond_to?(:mime) ? @codec.mime : nil) end |
Instance Attribute Details
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
17 18 19 |
# File 'lib/slash/formats.rb', line 17 def codec @codec end |
#mime ⇒ Object (readonly)
Returns the value of attribute mime.
17 18 19 |
# File 'lib/slash/formats.rb', line 17 def mime @mime end |
Instance Method Details
#interpret_response(response) ⇒ Object
35 36 37 38 |
# File 'lib/slash/formats.rb', line 35 def interpret_response(response) bs = response.body_stream bs && codec.decode(bs) end |
#prepare_request(options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/slash/formats.rb', line 24 def prepare_request() headers = [:headers] headers['Accept'] = mime if mime data = .delete(:data) if data [:body] = codec.encode(data) headers['Content-Type'] = mime if mime end end |