Class: Vng::PriceItem

Inherits:
Resource show all
Defined in:
lib/vng/price_item.rb

Overview

Provides methods to interact with Vonigo price items.

Constant Summary collapse

PATH =
'/api/v1/data/priceLists/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, price_item:, index:, description:, value:, tax_id:, duration_per_unit:, service_badge:, service_category:, price_block_id:) ⇒ PriceItem

Returns a new instance of PriceItem.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vng/price_item.rb', line 10

def initialize(id:, price_item:, index:, description:, value:, tax_id:, duration_per_unit:, service_badge:, service_category:, price_block_id:)
  @id = id
  @price_item = price_item
  @index = index
  @description = description
  @value = value
  @tax_id = tax_id
  @duration_per_unit = duration_per_unit
  @service_badge = service_badge
  @service_category = service_category
  @price_block_id = price_block_id
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def description
  @description
end

#duration_per_unitObject (readonly)

Returns the value of attribute duration_per_unit.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def duration_per_unit
  @duration_per_unit
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def id
  @id
end

#indexObject (readonly)

Returns the value of attribute index.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def index
  @index
end

#price_block_idObject (readonly)

Returns the value of attribute price_block_id.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def price_block_id
  @price_block_id
end

#price_itemObject (readonly)

Returns the value of attribute price_item.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def price_item
  @price_item
end

#service_badgeObject (readonly)

Returns the value of attribute service_badge.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def service_badge
  @service_badge
end

#service_categoryObject (readonly)

Returns the value of attribute service_category.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def service_category
  @service_category
end

#tax_idObject (readonly)

Returns the value of attribute tax_id.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def tax_id
  @tax_id
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/vng/price_item.rb', line 8

def value
  @value
end

Class Method Details

.for_price_list_id(price_list_id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vng/price_item.rb', line 23

def self.for_price_list_id(price_list_id)
  body = {
    method: '1',
    priceListID: price_list_id,
  }

  data = request path: '/api/v1/resources/priceItems/', body: body, returning: 'PriceItems'

  data.filter_map do |body|
    next unless body['isOnline'] && body['isActive']

    id = body['priceItemID']
    price_item = body['priceItem']
    index = body['sequence']
    description = body['descriptionHelp']
    value = body['value']
    tax_id = body['taxID']
    duration_per_unit = body['durationPerUnit']
    service_badge = body['serviceBadge']
    service_category = body['serviceCategory']
    price_block_id = body['priceBlockID']

    new id: id, price_item: price_item, index: index, description: description, value: value, tax_id: tax_id, duration_per_unit: duration_per_unit, service_badge: service_badge, service_category: service_category, price_block_id: price_block_id
  end
end

.where(location_id:, asset_id:) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vng/price_item.rb', line 49

def self.where(location_id:, asset_id:)
  body = {
    method: '2',
    serviceTypeID: '14', # only return items of serviceType 'Pet Grooming'
    locationID: location_id,
    assetID: asset_id,
  }

  data = request path: PATH, body: body

  data['PriceItems'].filter do |body|
    body['isOnline'] && body['isActive']
  end.map do |body|
    id = body['priceItemID']
    price_item = body['priceItem']
    index = body['sequence']
    description = body['descriptionHelp']
    value = body['value']
    tax_id = body['taxID']
    duration_per_unit = body['durationPerUnit']
    service_badge = body['serviceBadge']
    service_category = body['serviceCategory']
    price_block_id = body['priceBlockID']

    new id: id, price_item: price_item, index: index, description: description, value: value, tax_id: tax_id, duration_per_unit: duration_per_unit, service_badge: service_badge, service_category: service_category, price_block_id: price_block_id
  end
end