Sha256: 40991aa62b4d5d3930c9e7681bb3ea10bf6c79325bbafd5b4279f04f73b08c3d

Contents?: true

Size: 1.34 KB

Versions: 5

Compression:

Stored size: 1.34 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) }
      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

5 entries across 5 versions & 1 rubygems

Version Path
rakuten_web_service-1.9.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.8.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.7.0 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.6.1 lib/rakuten_web_service/books/resource.rb
rakuten_web_service-1.6.0 lib/rakuten_web_service/books/resource.rb