class CardmarketCLI::Entities::MetaProduct

See api.cardmarket.com/ws/documentation/API_2.0:Entities:Metaproduct

Constants

PARAMS
PATH_BASE

Attributes

updated_at[R]

Private Class Methods

create(id, account, params = {}) click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 65
def create(id, account, params = {})
  self[id]&.send(:merge_params, params) || new(id, account, params)
end
from_hash(account, hash) click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 56
def from_hash(account, hash)
  hash.transform_keys! { |key| key.underscore.to_sym }
  hash[:products] = []
  hash.delete(:product)&.each do |product|
    hash[:products] << Product.from_hash(account, product)
  end
  MetaProduct.create(hash[:id_metaproduct], account, hash)
end
new(id, account, params = {}) click to toggle source
Calls superclass method CardmarketCLI::Entities::Entity::new
# File lib/cardmarket_cli/entities/meta_product.rb, line 18
def initialize(id, account, params = {})
  super(id, account, { products: [] })
  merge_params(params)
  MetaProduct.send(:add, self)
end
search_all(account, search_string, exact: false) click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 69
def search_all(account, search_string, exact: false)
  start = 0
  products = []
  loop do
    search(account, search_string, products, start, exact: exact)
    break unless products.count == start += 100
  end
  products
end

Public Instance Methods

meta?() click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 24
def meta?
  true
end
products() click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 28
def products
  read unless params[:products]
  params[:products].dup
end
read() click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 33
def read
  LOGGER.debug("Reading Metaproduct #{en_name}(#{id})")
  response = account.get("#{PATH_BASE}/#{id}")
  hash = JSON.parse(response.response_body)
  hash['metaproduct']&.store('product', hash['product'])
  MetaProduct.from_hash(account, hash['metaproduct'])
end

Private Instance Methods

merge_params(params) click to toggle source
# File lib/cardmarket_cli/entities/meta_product.rb, line 43
def merge_params(params)
  self.params[:products] = self.params[:products].union(params[:products] || [])
  self.params.merge!(params.slice(*PARAMS))
  @updated_at = Time.now
  self
end