Class: Flexibee::Product

Inherits:
Object
  • Object
show all
Defined in:
lib/flexibee/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, client) ⇒ Product

Product basic response

{ “id” => “4797”, “lastUpdate” => “2015-09-30T15:42:45.190+02:00”, “kod” => “B0002”, “nazev” => “Dámský zvýhodněný balíček”, “cenaZakl” => “1361.157024”, “cenaZaklBezDph” => “1361.157024”, “cenaZaklVcDph” => “1646.999999”,

"sumDostupMj" =>  "0.0",
"poznam" => "NENÍ FOTO",
"popis" => "",
"eanKod" => "",
"szbDph" => "21.0"

}



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flexibee/product.rb', line 24

def initialize(response, client)
  @id = response['id'].to_i
  @updated_at = response['lastUpdate']
  @code = response['kod']
  @name = response['nazev']
  @price_base = response['cenaZakl'].to_f
  @price_no_vat = response['cenaZaklBezDph'].to_f
  @price_vat = response['cenaZaklVcDph'].to_f
  @stock = response['sumDostupMj'].to_f
  @note = response['poznam']
  @description = response['popis']
  @ean = response['eanKod']
  @vat = response['szbDph'].to_f
  @client = client
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def description
  @description
end

#eanObject

Returns the value of attribute ean.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def ean
  @ean
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def name
  @name
end

#noteObject

Returns the value of attribute note.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def note
  @note
end

#price_baseObject

Returns the value of attribute price_base.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def price_base
  @price_base
end

#price_no_vatObject

Returns the value of attribute price_no_vat.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def price_no_vat
  @price_no_vat
end

#price_vatObject

Returns the value of attribute price_vat.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def price_vat
  @price_vat
end

#stockObject

Returns the value of attribute stock.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def stock
  @stock
end

#updated_atObject

Returns the value of attribute updated_at.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def updated_at
  @updated_at
end

#vatObject

Returns the value of attribute vat.



3
4
5
# File 'lib/flexibee/product.rb', line 3

def vat
  @vat
end

Instance Method Details

#categoryObject

TODO test



41
42
43
44
# File 'lib/flexibee/product.rb', line 41

def category
  uzel_id = find_relationship ? find_relationship['uzel'] : find_relationship
  uzel_id ? @client.tree.find_by_id(uzel_id.to_i).first : nil
end

#find_relationshipObject

TODO test



47
48
49
# File 'lib/flexibee/product.rb', line 47

def find_relationship
  @client.get("/strom-cenik", { detail: 'full' }, "idZaznamu='#{id}'")['winstrom']['strom-cenik'][0]
end