Class: GrapeClient::ResponseParser
- Inherits:
-
Object
- Object
- GrapeClient::ResponseParser
- Defined in:
- lib/grape_client/response_parser.rb
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(response, receiver) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #parse ⇒ Object
Constructor Details
#initialize(response, receiver) ⇒ ResponseParser
Returns a new instance of ResponseParser.
5 6 7 8 |
# File 'lib/grape_client/response_parser.rb', line 5 def initialize(response, receiver) @response = response @receiver = receiver end |
Instance Method Details
#collection ⇒ Object
28 29 30 |
# File 'lib/grape_client/response_parser.rb', line 28 def collection parsed[@receiver.entity_name.pluralize] if parsed.is_a? Hash end |
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grape_client/response_parser.rb', line 10 def parse if @receiver.is_a? Class elements = collection if elements.nil? if parsed.present? @receiver.new(parsed) else @response end else Collection.new(@receiver, elements, @receiver.connection.headers) end else @receiver.attributes = parsed end end |