Sha256: 697be2736b6c2d97ce955c7c986549e5ab29fdc8e3c5efac4da1c19f0ab7a0d0

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

require 'rakuten_web_service/resource'
require 'rakuten_web_service/books/genre'

module RakutenWebService
  module Books
    class Resource < RakutenWebService::Resource
      set_parser do |response|
        response['Items'].map { |item| self.new(item['Item']) }
      end

      def self.find_resource_by_genre_id(genre_id)
        case genre_id
        when /^001/ then RWS::Books::Book
        when /^002/ then RWS::Books::CD
        when /^003/ then RWS::Books::DVD
        when /^004/ then RWS::Books::Software
        when /^005/ then RWS::Books::ForeignBook
        when /^006/ then RWS::Books::Game
        when /^007/ then RWS::Books::Magazine
        end
      end

      def self.genre_class
        RakutenWebService::Books::Genre
      end

      def genre
        @genre ||= self.books_genre_id.split('/').map do |id|
          Books::Genre.new(id)
        end
      end
      alias genres genre

      def get_attribute(name)
        name = name.to_s
        update_params unless @params[name]
        @params[name] 
      end

      private
      def update_params
        item = self.class.search(update_key => self[update_key]).first
        @params = item.params
      end

      def update_key
        raise 'This method is required to be overwritten in subclasses.'
      end

      protected
      def params
        @params.dup
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rakuten_web_service-1.5.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.4.2 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.4.1 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.4.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.3.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.2.0 lib/rakuten_web_service/books/resource.rb