Class: RakutenWebService::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rakuten_web_service/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource_class, json) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/rakuten_web_service/response.rb', line 5

def initialize(resource_class, json)
  @resource_class = resource_class
  @json = json.dup
end

Instance Method Details

#[](key) ⇒ Object



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

def [](key)
  @json[key]
end

#eachObject



14
15
16
17
18
# File 'lib/rakuten_web_service/response.rb', line 14

def each
  resources.each do |resource|
    yield resource
  end
end

#genre_informationObject



27
28
29
30
31
# File 'lib/rakuten_web_service/response.rb', line 27

def genre_information
  return unless @resource_class.respond_to?(:genre_class)
  return if self['GenreInformation'].empty?
  RWS::GenreInformation.new(self['GenreInformation'][0], @resource_class.genre_class)
end

#has_next_page?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/rakuten_web_service/response.rb', line 37

def has_next_page?
  page && (not last_page?)
end

#last_page?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rakuten_web_service/response.rb', line 41

def last_page?
  page >= page_count
end

#resourcesObject



33
34
35
# File 'lib/rakuten_web_service/response.rb', line 33

def resources
  @resources ||= @resource_class.parse_response(@json)
end