Class: Vng::Lock

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

Overview

Provides methods to interact with Vonigo locks.

Constant Summary collapse

PATH =
'/api/v1/resources/availability/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ Lock

Returns a new instance of Lock.



10
11
12
# File 'lib/vng/lock.rb', line 10

def initialize(id:)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.create(duration:, location_id:, date:, minutes:, route_id:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vng/lock.rb', line 14

def self.create(duration:, location_id:, date:, minutes:, route_id:)
  body = {
    method: '2',
    serviceTypeID: '14', # only create items of serviceType 'Pet Grooming'
    duration: [duration.to_i, 30].max, # or 'duration is not supplied'
    locationID: location_id,
    dayID: date.strftime('%Y%m%d'),
    routeID: route_id,
    startTime: minutes,
  }

  data = request path: Availability::PATH, body: body

  new id: data['Ids']['lockID']
end