Class: RakutenApi::GenreSearch::Response

Inherits:
Base::Response show all
Defined in:
lib/rakuten_api/genre_search/response.rb

Instance Attribute Summary

Attributes inherited from Base::Response

#body, #status

Instance Method Summary collapse

Methods inherited from Base::Response

#error?, #error_message, #success?

Constructor Details

#initialize(faraday_response = nil) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/rakuten_api/genre_search/response.rb', line 6

def initialize(faraday_response = nil)
  super(faraday_response)
end

Instance Method Details

#cacheObject



10
11
12
# File 'lib/rakuten_api/genre_search/response.rb', line 10

def cache
  @cache ||= {}
end

#childrenObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/rakuten_api/genre_search/response.rb', line 31

def children
  return cache['children'] if cache.key? 'children'
  return [] unless @body.key? 'children'
  cache['children'] = [].tap do |result|
    @body["children"].each do |f|
      next unless f.include? 'child'
      result << Model.from_hash(f['child'])
    end
  end
end

#currentObject



25
26
27
28
29
# File 'lib/rakuten_api/genre_search/response.rb', line 25

def current
  return cache['current'] if cache.key? 'current'
  return nil unless @body.key? 'current'
  cache['current'] = Model.from_hash(@body['current'])
end

#parentsObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/rakuten_api/genre_search/response.rb', line 14

def parents
  return cache['parents'] if cache.key? 'parents'
  return [] unless @body.key? 'parents'
  cache['parents'] = [].tap do |result|
    @body['parents'].each do |f|
      next unless f.include? 'parent'
      result << Model.from_hash(f['parent'])
    end
  end
end