Class: MercadoLibre::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/mercado_libre/item.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Item

Returns a new instance of Item.



19
20
21
22
23
24
# File 'lib/mercado_libre/item.rb', line 19

def initialize(params = {})
  params = Hash[params.map { |k, v| [k.to_sym, v] }] #Symbolize keys
  self.class.attr_list.each do |k|
    send("#{k}=", params[k]) if params[k]
  end
end

Class Method Details

.attr_listObject



9
10
11
12
13
14
15
# File 'lib/mercado_libre/item.rb', line 9

def self.attr_list
  other_fields = [:id, :start_time, :stop_time, :end_time, :permalink, :thumbnail, 
  :secure_thumbnail, :descriptions, :accepts_mercadopago, :status, :date_created,
  :last_updated, :non_mercado_pago_payment_methods ]
  
  self.publishable_params + other_fields
end

.publishable_paramsObject



3
4
5
6
7
# File 'lib/mercado_libre/item.rb', line 3

def self.publishable_params
  [:site_id, :title, :category_id, :price, :currency_id, :available_quantity,
   :buying_mode, :listing_type_id, :condition, :description, :video_id, :warranty,
   :pictures, :shipping]
end

Instance Method Details

#publishable_hashObject



26
27
28
29
30
31
# File 'lib/mercado_libre/item.rb', line 26

def publishable_hash
  hash = {}
  self.class.publishable_params.each { |k| hash[k] = send(k) }

  hash
end