Sha256: fc79494e687a89811ad9ad11618ac58fc3ce6a850d654ffcb635615cfbd9bf2f
Contents?: true
Size: 1.51 KB
Versions: 6
Compression:
Stored size: 1.51 KB
Contents
module RakutenWebService module Ichiba class Genre < Resource @@repository = {} class << self def parse_response(response) current = response['current'] if children = response['children'] children = children.map { |child| Genre.new(child['child']) } current.merge!('children' => children) end if parents = response['parents'] parents = parents.map { |parent| Genre.new(parent['parent']) } current.merge!('parents' => parents) end genre = Genre.new(current) [genre] end def new(params) case params when Integer, String Genre[params.to_s] || search(:genre_id => params.to_s).first when Hash super end end def root self.new(0) end def [](id) @@repository[id.to_s] end def []=(id, genre) @@repository[id.to_s] = genre end end endpoint 'https://app.rakuten.co.jp/services/api/IchibaGenre/Search/20120723' attribute :genreId, :genreName, :genreLevel def initialize(params) super Genre[self.id.to_s] = self end def ranking(options={}) RakutenWebService::Ichiba::RankingItem.search(:genre_id => self.id) end def children return @params['children'] if @params['children'] Genre.search(:genre_id => self.id).first.children end end end end
Version data entries
6 entries across 6 versions & 1 rubygems