Class: GrapeClient::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_client/response_parser.rb

Instance Method Summary collapse

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

#collectionObject



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

#parseObject



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