Class: VWorkApp::Job

Inherits:
Resource show all
Defined in:
lib/vworkapp_ruby/job.rb

Instance Method Summary collapse

Methods inherited from Resource

bad_response, #create, #delete, find, perform, #perform, #persisted?, resource_name, #resource_name, show, #update

Methods inherited from Base

#attributes, #attributes=, #attributes_eql?, hattr_accessor, hattr_reader, hattr_writer, hattrs, #hattrs, #initialize, #read_attributes, #read_attributes=, read_hattrs, #read_hattrs, #validate_and_raise, #write_attributes, #write_attributes=, #write_hattrs, write_hattrs

Constructor Details

This class inherits a constructor from VWorkApp::Base

Instance Method Details

#==(other) ⇒ Object



46
47
48
49
# File 'lib/vworkapp_ruby/job.rb', line 46

def ==(other)
  attributes_eql?(other, :id, :third_party_id, :customer_name, :template_name, :planned_duration, :planned_start_at, 
    :worker_id, :steps, :custom_fields, :confirmation)
end

#customerObject



20
21
22
23
# File 'lib/vworkapp_ruby/job.rb', line 20

def customer
  return nil if @customer_id.nil?
  @customer ||= Customer.show(@customer_id)
end

#customer_validationObject



13
14
15
16
17
18
# File 'lib/vworkapp_ruby/job.rb', line 13

def customer_validation
  return true if @customer_id || @customer_name
  error_str = "- Either customer_name OR customer_id must be present"
  self.errors.add :customer_name, error_str
  self.errors.add :customer_id, error_str
end

#planned_start_at=(datetime) ⇒ Object

XXX Published at also needs to be set.



31
32
33
34
# File 'lib/vworkapp_ruby/job.rb', line 31

def planned_start_at=(datetime)
  self.published_at = datetime
  @planned_start_at = datetime
end

#to_xml(options = {}) ⇒ Object

XXX Work around for API bug that doesn’t accept a nil contact detail.



37
38
39
40
41
42
43
44
# File 'lib/vworkapp_ruby/job.rb', line 37

def to_xml(options = {})
  except = options[:except] || []
  except << "custom_fields" unless custom_fields
  except << "customer_id" unless customer_id && customer_name.nil?
  except << "confirmation" unless confirmation

  super(:except => except)
end

#workerObject



25
26
27
28
# File 'lib/vworkapp_ruby/job.rb', line 25

def worker
  return nil if @worker_id.nil?
  @worker ||= Worker.show(@worker_id)
end