Class: Resources::SltcRegistration

Inherits:
BaseResource show all
Includes:
ServiceDefinitionPrompter, SltcRegistrationPrompter, ThirdPartyPrompter
Defined in:
lib/pvdgm-svc-client/resources/sltc_registration.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#options, #prompter

Instance Method Summary collapse

Methods included from SltcRegistrationPrompter

#sltc_registration_id

Methods included from ServiceDefinitionPrompter

#service_definition_id

Methods included from ThirdPartyPrompter

#third_party_id

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from BaseResource

Instance Method Details

#completeObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pvdgm-svc-client/resources/sltc_registration.rb', line 33

def complete
  tp_id = third_party_id
  sd_id = service_definition_id
  reg_id = sltc_registration_id

  params = {
    third_party_id: tp_id,
    service_definition_id: sd_id,
    account_id: prompter.ask("\nAccount ID: ", Integer) { |q| q.validate = lambda { | a | is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Account ID" },
    baseline_days: prompter.ask("\nNumber of days for baseline: ", Integer) { |q| q.default = 180; q.responses[:not_valid] = "\nNot a valid number of days" }
  }
  result = post("services/sltc_registrations/#{reg_id}/complete", params)
  puts result.inspect
  puts
end

#configureObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pvdgm-svc-client/resources/sltc_registration.rb', line 49

def configure
  tp_id = third_party_id
  sd_id = service_definition_id
  reg_id = sltc_registration_id

  params = {
    third_party_id: tp_id,
    service_definition_id: sd_id,
    account_id: prompter.ask("\nAccount ID: ", Integer) { |q| q.validate = lambda { | a | is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Account ID" },
    configure_only: 'true'
  }
  result = post("services/sltc_registrations/#{reg_id}/complete", params)
  puts result.inspect
  puts
end

#listObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pvdgm-svc-client/resources/sltc_registration.rb', line 8

def list
  status = prompter.choose do | menu |
    menu.prompt = "\nSelect the status to filter with: "

    menu.choice('All', 'Specify no status') { -1 }
    menu.choice('New', 'New registrations') { 0 }
    menu.choice('Completed', 'Completed registrations') { 1 }
  end
  
  filter = status >= 0 ? "?status=#{status}" : ''
  result = get("services/sltc_registrations#{filter}")

  puts "\nSimpleLTC Registrations"
  table = Terminal::Table.new headings: [ 'Status', 'Company Name', 'Initiated By', 'Created At' ] do |t|
    result.each do | registration |
      t << [ registration['status'],
             registration['company_name'],
             registration['initiated_by'],
             registration['created_at'] ]
    end
  end
  prompter.say table.to_s
  puts
end