Class: Vng::WorkOrder

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

Overview

Provides methods to interact with Vonigo work orders.

Constant Summary collapse

PATH =
'/api/v1/data/WorkOrders/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ WorkOrder

Returns a new instance of WorkOrder.



10
11
12
# File 'lib/vng/work_order.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/work_order.rb', line 8

def id
  @id
end

Class Method Details

.create(lock_id:, client_id:, contact_id:, location_id:, duration:, summary:, line_items:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vng/work_order.rb', line 14

def self.create(lock_id:, client_id:, contact_id:, location_id:, duration:, summary:, line_items:)
  body = {
    method: '3',
    serviceTypeID: '14', # only return items of serviceType 'Pet Grooming'
    lockID: lock_id,
    clientID: client_id,
    contactID: contact_id,
    locationID: location_id,
    Fields: [
      { fieldID: 200, fieldValue: summary },
      { fieldID: 186, fieldValue: duration.to_i },
      { fieldID: 201, optionID: '9537' } # label: Online Tentative
    ],
    Charges: charges_for(line_items)
  }

  data = request path: PATH, body: body

  new id: data['WorkOrder']['objectID']
end

Instance Method Details

#urlObject

Returns the URL to manage the work order in the Vonigo UI.



36
37
38
# File 'lib/vng/work_order.rb', line 36

def url
  "https://#{self.class.host}/Schedule/Job/Job_Main.aspx?woID=#{id}"
end