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:, value:, tax_id:, duration_per_unit:, service_badge:, service_category:) ⇒ PriceItem

Returns a new instance of PriceItem.



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

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

Instance Attribute Details

#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

#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

.where(location_id:, asset_id:) ⇒ Object



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

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']
    value = body['value']
    tax_id = body['taxID']
    duration_per_unit = body['durationPerUnit']
    service_badge = body['serviceBadge']
    service_category = body['serviceCategory']

    new id: id, price_item: price_item, value: value, tax_id: tax_id, duration_per_unit: duration_per_unit, service_badge: service_badge, service_category: service_category
  end
end