class CardmarketCLI::Entities::WantslistItem
see api.cardmarket.com/ws/documentation/API_2.0:Wantslist_Item
Constants
- PARAMS
Attributes
product[R]
Public Class Methods
from_hash(account, hash)
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 58 def from_hash(account, hash) product = create_product(account, hash) hash.transform_keys! { |key| key.underscore.to_sym } hash[:min_condition] &&= hash[:min_condition].to_sym hash[:languages] = hash[:id_language] WantslistItem.new(hash[:id_want], product, account, hash) end
new(id, product, account, params = {})
click to toggle source
Calls superclass method
CardmarketCLI::Entities::Changeable::new
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 18 def initialize(id, product, account, params = {}) params = { count: 1, min_condition: :PO, wish_price: 0.0, mail_alert: false, languages: [1], is_foil: nil, is_altered: nil, is_playset: nil, is_signed: nil, is_first_ed: nil, from_price: nil }.merge!(params) super(id, account, params.slice(*PARAMS)) @product = product end
Private Class Methods
create_product(account, hash)
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 68 def create_product(account, hash) if hash['type'] == 'metaproduct' MetaProduct.from_hash(account, hash['metaproduct']) else Product.from_hash(account, hash.slice(*%w[rarity expansionName countArticles countFoils]) .merge!(hash['product'])) end end
Public Instance Methods
add_product_id(hash)
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 35 def add_product_id(hash) return if hash['idWant'] if @product.meta? hash[:idMetaproduct] = @product.id else hash[:idProduct] = @product.id end end
languages()
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 49 def languages params[:languages]&.uniq! end
languages=(value)
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 53 def languages=(value) params[:languages] = value.uniq end
meta?()
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 45 def meta? product.meta? end
to_xml_hash()
click to toggle source
# File lib/cardmarket_cli/entities/wantslist_item.rb, line 25 def to_xml_hash hash = params.compact.transform_keys! { |key| key.to_s.camelize } hash['idLanguage'] = hash.delete('languages')&.uniq! hash['idWant'] = id hash.delete_if { |_, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) } add_product_id(hash) hash end