Class: Vng::ServiceType

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

Overview

Provides methods to interact with Vonigo service types.

Constant Summary collapse

PATH =
'/api/v1/resources/serviceTypes/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type:, duration:) ⇒ ServiceType

Returns a new instance of ServiceType.



10
11
12
13
14
# File 'lib/vng/service_type.rb', line 10

def initialize(id:, type:, duration:)
  @id = id
  @type = type
  @duration = duration
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



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

def duration
  @duration
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.allObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vng/service_type.rb', line 16

def self.all
  data = request path: PATH

  data['ServiceTypes'].map do |body|
    id = body['serviceTypeID']
    type = body['serviceType']
    duration = body['duration']

    new id: id, type: type, duration: duration
  end
end

.where(zip:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vng/service_type.rb', line 28

def self.where(zip:)
  body = {
    zip: zip,
  }

  data = request path: PATH, body: body

  data.fetch('ServiceTypes', []).filter do |body|
    body['isActive']
  end.map do |body|
    id = body['serviceTypeID']
    type = body['serviceType']
    duration = body['duration']

    new id: id, type: type, duration: duration
  end
end