Class: Jahuty::Response::Handler
- Inherits:
-
Object
- Object
- Jahuty::Response::Handler
- Defined in:
- lib/jahuty/response/handler.rb
Overview
Inspects the response and returns the appropriate resource or collection.
Instance Method Summary collapse
Instance Method Details
#call(action, response) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jahuty/response/handler.rb', line 9 def call(action, response) resource_name = name_resource action, response payload = parse response @resources ||= ::Jahuty::Resource::Factory.new if collection?(payload) payload.map { |data| @resources.call resource_name, data } elsif resource?(payload) @resources.call resource_name, payload else raise ArgumentError, 'Action and payload mismatch' end end |