Class: Facile::Response::Wrapper
- Inherits:
-
Object
- Object
- Facile::Response::Wrapper
- Defined in:
- lib/facile/response/wrapper.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Class Method Summary collapse
Instance Method Summary collapse
- #content_type_to_class(content_type) ⇒ Object
-
#initialize(body, headers = {}) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #parse ⇒ Object
Constructor Details
#initialize(body, headers = {}) ⇒ Wrapper
Returns a new instance of Wrapper.
12 13 14 |
# File 'lib/facile/response/wrapper.rb', line 12 def initialize(body, headers = {}) @body, @headers = body, headers end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
39 40 41 |
# File 'lib/facile/response/wrapper.rb', line 39 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
39 40 41 |
# File 'lib/facile/response/wrapper.rb', line 39 def headers @headers end |
Class Method Details
.parse(body, options = {}) ⇒ Object
6 7 8 9 10 |
# File 'lib/facile/response/wrapper.rb', line 6 def self.parse(body, = {}) wrapper = new(body, ) wrapper.parse end |
Instance Method Details
#content_type_to_class(content_type) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/facile/response/wrapper.rb', line 30 def content_type_to_class(content_type) case content_type when /application\/json/ 'Json' else 'Raw' end end |
#parse ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/facile/response/wrapper.rb', line 16 def parse wrapper = "Raw" if headers.has_key?('content-type') wrapper = content_type_to_class(headers['content-type']) end klass = "Facile::Response::Wrapper::#{wrapper}".split('::').inject(Object) do |o, c| o.const_get(c) end klass.new(@body).parsed_body end |