pvdgm-svc-client 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/Gemfile +17 -0
  4. data/Gemfile.lock +75 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +21 -0
  7. data/Rakefile +50 -0
  8. data/VERSION +1 -0
  9. data/bin/service_mgr +8 -0
  10. data/bin/service_mgr_completion +86 -0
  11. data/bin/valid_commands +16 -0
  12. data/bin/valid_resources +11 -0
  13. data/lib/pvdgm-svc-client/base_resource.rb +118 -0
  14. data/lib/pvdgm-svc-client/prompters/account_mapping_prompter.rb +26 -0
  15. data/lib/pvdgm-svc-client/prompters/configured_account_prompter.rb +30 -0
  16. data/lib/pvdgm-svc-client/prompters/configured_facility_prompter.rb +30 -0
  17. data/lib/pvdgm-svc-client/prompters/facility_mapping_prompter.rb +26 -0
  18. data/lib/pvdgm-svc-client/prompters/public_key_prompter.rb +27 -0
  19. data/lib/pvdgm-svc-client/prompters/service_definition_prompter.rb +30 -0
  20. data/lib/pvdgm-svc-client/prompters/service_prompter.rb +26 -0
  21. data/lib/pvdgm-svc-client/prompters/sltc_provider_prompter.rb +24 -0
  22. data/lib/pvdgm-svc-client/prompters/sltc_registration_prompter.rb +26 -0
  23. data/lib/pvdgm-svc-client/prompters/third_party_prompter.rb +26 -0
  24. data/lib/pvdgm-svc-client/resources/account_mapping.rb +83 -0
  25. data/lib/pvdgm-svc-client/resources/assessment_request.rb +61 -0
  26. data/lib/pvdgm-svc-client/resources/available_file.rb +48 -0
  27. data/lib/pvdgm-svc-client/resources/configured_account.rb +118 -0
  28. data/lib/pvdgm-svc-client/resources/configured_facility.rb +118 -0
  29. data/lib/pvdgm-svc-client/resources/facility_mapping.rb +90 -0
  30. data/lib/pvdgm-svc-client/resources/mds_pull_account.rb +55 -0
  31. data/lib/pvdgm-svc-client/resources/provider.rb +28 -0
  32. data/lib/pvdgm-svc-client/resources/public_key.rb +119 -0
  33. data/lib/pvdgm-svc-client/resources/service.rb +67 -0
  34. data/lib/pvdgm-svc-client/resources/service_definition.rb +147 -0
  35. data/lib/pvdgm-svc-client/resources/sltc_registration.rb +51 -0
  36. data/lib/pvdgm-svc-client/resources/third_party.rb +61 -0
  37. data/lib/pvdgm-svc-client/service_mgr_options.rb +157 -0
  38. data/lib/pvdgm-svc-client.rb +16 -0
  39. data/spec/base_resource_spec.rb +208 -0
  40. data/spec/service_mgr_options_spec.rb +266 -0
  41. data/spec/spec_helper.rb +22 -0
  42. metadata +202 -0
@@ -0,0 +1,26 @@
1
+ module SltcRegistrationPrompter
2
+
3
+ def sltc_registration_id(allow_none=false)
4
+ return options[:sltc_registration_id] if options[:sltc_registration_id]
5
+ return options[:sltc_registration_id] = ENV['SLTC_REGISTRATION_ID'] if ENV['SLTC_REGISTRATION_ID']
6
+ return options[:sltc_registration_id] = prompt_for_sltc_registration_id(allow_none)
7
+ end
8
+
9
+ private
10
+
11
+ def prompt_for_sltc_registration_id(allow_none)
12
+ result = get("services/sltc_registrations?status=0")
13
+
14
+ (puts "No uncompleted SLTC Registrations are available. Cannot continue"; exit 1) if result.empty?
15
+
16
+ # Build a menu of the account mappings
17
+ puts
18
+ return prompter.choose do | menu |
19
+ menu.prompt = "Select the SLTC Registration: "
20
+ menu.choice("No Selection") { -1 } if allow_none
21
+ result.each do | sltc_registration |
22
+ menu.choice("#{sltc_registration['company_name']} (#{sltc_registration['id']})") { sltc_registration['id'] }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module ThirdPartyPrompter
2
+
3
+ def third_party_id(allow_none=false)
4
+ return options[:third_party_id] if options[:third_party_id]
5
+ return options[:third_party_id] = ENV['THIRD_PARTY_ID'] if ENV['THIRD_PARTY_ID']
6
+ return options[:third_party_id] = prompt_for_third_party_id(allow_none)
7
+ end
8
+
9
+ private
10
+
11
+ def prompt_for_third_party_id(allow_none)
12
+ result = get("services/third_parties")
13
+
14
+ (puts "No third parties are defined. Cannot continue"; exit 1) if result.empty?
15
+
16
+ # Build a menu of the third parties
17
+ puts
18
+ return prompter.choose do | menu |
19
+ menu.prompt = "Select the Third Party: "
20
+ menu.choice("No Selection") { -1 } if allow_none
21
+ result.each do | third_party |
22
+ menu.choice(third_party['name']) { third_party['id'] }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,83 @@
1
+ module Resources
2
+
3
+ class AccountMapping < BaseResource
4
+ include ThirdPartyPrompter
5
+ include AccountMappingPrompter
6
+
7
+ def list
8
+ tp_id = third_party_id
9
+ result = get("services/third_parties/#{tp_id}/account_mappings")
10
+ puts "\nAccount Mappings for third party: #{tp_id}"
11
+ table = Terminal::Table.new headings: [ 'Third Party', 'Account', 'Account Code' ] do |t|
12
+ result.each do | account_mapping |
13
+ t << [ "#{account_mapping['third_party_name']} (#{account_mapping['third_party_id']})",
14
+ "#{account_mapping['account_name']} (#{account_mapping['account_id']})",
15
+ account_mapping['account_code'] ]
16
+ end
17
+ end
18
+ prompter.say table.to_s
19
+ puts
20
+ end
21
+
22
+ def show
23
+ tp_id = third_party_id
24
+ am_id = account_mapping_id
25
+ account_mapping = get("services/third_parties/#{tp_id}/account_mappings/#{am_id}")
26
+ @am_third_party_id = account_mapping['third_party_id']
27
+ @am_account_id = account_mapping['account_id']
28
+ @am_account_code = account_mapping['account_code']
29
+ puts "\nAccount Mapping for third party: #{tp_id}/#{am_id}"
30
+ table = Terminal::Table.new headings: [ 'Third Party', 'Account', 'Account Code' ] do |t|
31
+ t << [ "#{account_mapping['third_party_name']} (#{account_mapping['third_party_id']})",
32
+ "#{account_mapping['account_name']} (#{account_mapping['account_id']})",
33
+ account_mapping['account_code'] ]
34
+ end
35
+ puts table
36
+ puts
37
+ end
38
+
39
+ def create
40
+ tp_id = third_party_id
41
+ params = {
42
+ account_mapping: {
43
+ account_id: prompter.ask("\nabaqis Account 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" },
44
+ account_code: prompter.ask("\nThird party Account Code: ") { |q| q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid third party account ID" }
45
+ }
46
+ }
47
+ result = post("services/third_parties/#{tp_id}/account_mappings", params)
48
+ puts "\nID of new account mapping: #{result['id']}"
49
+ puts
50
+ end
51
+
52
+ def update
53
+ tp_id = third_party_id
54
+ am_id = account_mapping_id
55
+ show
56
+ params = {
57
+ account_mapping: {
58
+ account_id: prompter.ask("\nabaqis Account ID: ", Integer) { |q| q.default = @am_account_id; q.validate = lambda { | a | is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid account ID" },
59
+ account_code: prompter.ask("\nThird party Account Code: ") { |q| q.default = @am_account_code; q.validate = /\A.{1,255}\z/; q.responses[:not_valid] = "\nNot a valid third party account ID" }
60
+ }
61
+ }
62
+ result = put("services/third_parties/#{tp_id}/account_mappings/#{am_id}", params)
63
+ puts "\nID of updated account mapping: #{result['id']}"
64
+ puts
65
+ end
66
+
67
+ def destroy
68
+ tp_id = third_party_id
69
+ am_id = account_mapping_id
70
+ show
71
+ if prompter.agree("\nAre you sure you want to destroy this account mapping? (y/n) ", true)
72
+ puts
73
+ result = delete("services/third_parties/#{tp_id}/account_mappings/#{am_id}")
74
+ puts "\nID of deleted account mapping: #{result['id']}"
75
+ else
76
+ puts "\nCancelled deletion"
77
+ end
78
+ puts
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,61 @@
1
+ module Resources
2
+
3
+ class AssessmentRequest < BaseResource
4
+ include ThirdPartyPrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredAccountPrompter
7
+ include SltcProviderPrompter
8
+
9
+ def list
10
+ result = get("services/assessment_requests#{status_prompt}")
11
+ puts "\nSLTC Assessment Requests:"
12
+ table = Terminal::Table.new headings: [ 'Provider ID', 'Request ID', 'From', 'To', 'Status', 'Created', 'Updated' ] do |t|
13
+ result.each do | assessment_request |
14
+ t << [ assessment_request['facility_code'],
15
+ assessment_request['request_id'],
16
+ assessment_request['pull_from'],
17
+ assessment_request['pull_to'],
18
+ assessment_request['status'],
19
+ assessment_request['created_at'],
20
+ assessment_request['updated_at'] ]
21
+ end
22
+ end
23
+ prompter.say table.to_s
24
+ puts
25
+ end
26
+
27
+ def create
28
+ tp_id = third_party_id
29
+ sd_id = service_definition_id
30
+ ca_id = configured_account_id
31
+ provider_id = sltc_provider_id
32
+ uploaded_after = prompter.ask("\nStart date for the requested assessments (YYYY-MM-DD(THH:MM:SS)?): ") { |q| q.validate = lambda { |a| is_valid_date?(a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid date" }
33
+ uploaded_before = prompter.ask("\nEnd date for the requested assessments (YYYY-MM-DD(THH:MM:SS)?): ") { |q| q.validate = lambda { |a| is_valid_date?(a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid date" }
34
+
35
+ result = post("services/assessment_requests",
36
+ { configured_account_id: ca_id,
37
+ provider_id: provider_id,
38
+ uploaded_after: uploaded_after,
39
+ uploaded_before: uploaded_before })
40
+
41
+ list
42
+ end
43
+
44
+ private
45
+
46
+ def status_prompt
47
+ puts
48
+ status = prompter.choose do | menu |
49
+ menu.prompt = "Select the status to filter the results with: "
50
+ menu.choice("Do not filter by status") { -1 }
51
+ menu.choice("Available") { 0 }
52
+ menu.choice("Downloaded") { 1 }
53
+ menu.choice("Empty") { 2 }
54
+ menu.choice("Error") { 3 }
55
+ end
56
+ status < 0 ? "" : "?status=#{status}"
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,48 @@
1
+ module Resources
2
+
3
+ class AvailableFile < BaseResource
4
+ include ThirdPartyPrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredAccountPrompter
7
+
8
+ def list
9
+ tp_id = third_party_id
10
+ sd_id = service_definition_id
11
+ ca_id = configured_account_id
12
+
13
+ puts
14
+ status = prompter.choose do | menu |
15
+ menu.prompt = "Select the status to filter with: "
16
+
17
+ menu.choice('All', 'Specify no status') { -1 }
18
+ menu.choice('Available', 'All files that are ready to be pulled from the source') { 0 }
19
+ menu.choice('Downloaded', 'All files that have been downloaded from the source') { 1 }
20
+ menu.choice('Invalid', 'All files that have been marked as invalid') { 3 }
21
+ menu.choice('Missing', 'All files that could not be found on the file system') { 4 }
22
+ menu.choice('Uploaded', 'All files that have been uploaded to abaqis') { 5 }
23
+ menu.choice('Upload Error', 'All files that had an error uploading to abaqis') { 6 }
24
+ menu.choice('Deleted', 'All files that have been deleted from the file system') { 7 }
25
+ menu.choice('Cleared', 'All files that have been cleared from the source') { 2 }
26
+
27
+ end
28
+ filter = status >= 0 ? "?status=#{status}" : ''
29
+ result = get("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts/#{ca_id}/available_files#{filter}")
30
+
31
+ puts "\nAvailable files for third party: #{tp_id}, service definition: #{sd_id}"
32
+ table = Terminal::Table.new headings: [ 'Request ID', 'File Name', 'Status', 'Downloaded At', 'CMP File Name', 'Error' ] do |t|
33
+ result.each do | available_file |
34
+ t << [ available_file['request_id'],
35
+ available_file['filename'],
36
+ available_file['status'],
37
+ available_file['downloaded_at'],
38
+ available_file['composite_file_name'],
39
+ available_file['error'],
40
+ available_file['created_at'],
41
+ available_file['updated_at'] ]
42
+ end
43
+ end
44
+ prompter.say table.to_s
45
+ puts
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,118 @@
1
+ module Resources
2
+
3
+ class ConfiguredAccount < BaseResource
4
+ include ThirdPartyPrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredAccountPrompter
7
+
8
+ def list
9
+ tp_id = third_party_id
10
+ sd_id = service_definition_id
11
+ result = get("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts")
12
+ puts "\nConfigured accounts for third party: #{tp_id}, service definition: #{sd_id}"
13
+ table = Terminal::Table.new headings: [ 'Service Def Id', 'Account ID', 'User name', 'Enabled', 'Password', 'Token' ] do |t|
14
+ result.each do | configured_account |
15
+ t << [ configured_account['service_definition_id'],
16
+ "#{configured_account['account_name']} (#{configured_account['account_id']})",
17
+ configured_account['username'],
18
+ configured_account['enabled'],
19
+ configured_account['password'],
20
+ configured_account['token'] ]
21
+ end
22
+ end
23
+ prompter.say table.to_s
24
+ puts
25
+ end
26
+
27
+ def show
28
+ tp_id = third_party_id
29
+ sd_id = service_definition_id
30
+ ca_id = configured_account_id
31
+ configured_account = get("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts/#{ca_id}")
32
+ @ca_account_id = configured_account['account_id']
33
+ @ca_username = configured_account['username']
34
+ @ca_enabled = configured_account['enabled']
35
+ @ca_password = configured_account['password']
36
+ @ca_token = configured_account['token']
37
+ puts "\nConfigured account for third party: #{tp_id}/#{options[:id]}"
38
+ table = Terminal::Table.new headings: [ 'Service Def Id', 'Account ID', 'User name', 'Enabled', 'Password', 'Token' ] do |t|
39
+ t << [ configured_account['service_definition_id'],
40
+ "#{configured_account['account_name']} (#{configured_account['account_id']})",
41
+ configured_account['username'],
42
+ configured_account['enabled'],
43
+ configured_account['password'],
44
+ configured_account['token'] ]
45
+ end
46
+ puts table
47
+ puts
48
+ end
49
+
50
+ def create
51
+ tp_id = third_party_id
52
+ sd_id = service_definition_id
53
+ params = {
54
+ configured_account: {
55
+ 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" },
56
+ username: prompter.ask("\nUser name: ") { |q| q.validate = /\A.{0,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid user name" },
57
+ enabled: prompter.agree("\nEnabled? (y/n) ", true)
58
+ }
59
+ }
60
+ puts
61
+ password = prompter.ask("\nPassword: ")
62
+ token = prompter.ask("\nToken: ")
63
+ if (password && password.size > 0) || (token && token.size > 0)
64
+ params[:credential] = {
65
+ }
66
+ params[:credential][:password] = password if password && password.size > 0
67
+ params[:credential][:token] = token if token && token.size > 0
68
+ end
69
+ result = post("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts", params)
70
+ puts "\nID of new configured account: #{result['id']}"
71
+ puts
72
+ end
73
+
74
+ def update
75
+ clear_default = ->(field) { field == "^" ? '' : field }
76
+ tp_id = third_party_id
77
+ sd_id = service_definition_id
78
+ ca_id = configured_account_id
79
+ show
80
+ params = {
81
+ configured_account: {
82
+ account_id: prompter.ask("\nAccount ID: ", Integer) { |q| q.default = @ca_account_id; q.validate = lambda { | a | is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Account ID" },
83
+ username: prompter.ask("\nUser name (^ to clear): ", clear_default) { |q| q.default = @ca_username; q.validate = /\A.{0,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid user name" },
84
+ enabled: prompter.agree("\nEnabled? ", true) { |q| q.default = @ca_enabled }
85
+ }
86
+ }
87
+ puts
88
+ password = prompter.ask("\nPassword (^ to clear): ", clear_default) { |q| q.default = @ca_password }
89
+ token = prompter.ask("\nToken (^ to clear): ", clear_default) { |q| q.default = @ca_token }
90
+ if (password && password.size > 0) || (token && token.size > 0)
91
+ params[:credential] = {
92
+ }
93
+ params[:credential][:password] = password if password && password.size > 0
94
+ params[:credential][:token] = token if token && token.size > 0
95
+ end
96
+ result = put("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts/#{ca_id}", params)
97
+ puts "\nID of updated configured account: #{result['id']}"
98
+ puts
99
+ end
100
+
101
+ def destroy
102
+ tp_id = third_party_id
103
+ sd_id = service_definition_id
104
+ ca_id = configured_account_id
105
+ show
106
+ if prompter.agree("\nAre you sure you want to destroy this configured account? (y/n) ", true)
107
+ puts
108
+ result = delete("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_accounts/#{ca_id}")
109
+ puts "\nID of deleted configured account: #{result['id']}"
110
+ else
111
+ puts "\nCancelled deletion"
112
+ end
113
+ puts
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,118 @@
1
+ module Resources
2
+
3
+ class ConfiguredFacility < BaseResource
4
+ include ThirdPartyPrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredFacilityPrompter
7
+
8
+ def list
9
+ tp_id = third_party_id
10
+ sd_id = service_definition_id
11
+ result = get("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_facilities")
12
+ puts "\nConfigured facilities for third party: #{tp_id}, service definition: #{sd_id}"
13
+ table = Terminal::Table.new headings: [ 'Service Def Id', 'Facility ID', 'User name', 'Enabled', 'Password', 'Token' ] do |t|
14
+ result.each do | configured_facility |
15
+ t << [ configured_facility['service_definition_id'],
16
+ "#{configured_facility['facility_name']} (#{configured_facility['facility_id']})",
17
+ configured_facility['username'],
18
+ configured_facility['enabled'],
19
+ configured_facility['password'],
20
+ configured_facility['token'] ]
21
+ end
22
+ end
23
+ prompter.say table.to_s
24
+ puts
25
+ end
26
+
27
+ def show
28
+ tp_id = third_party_id
29
+ sd_id = service_definition_id
30
+ cf_id = configured_facility_id
31
+ configured_facility = get("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_facilities/#{cf_id}")
32
+ @cf_facility_id = configured_facility['facility_id']
33
+ @cf_username = configured_facility['username']
34
+ @cf_enabled = configured_facility['enabled']
35
+ @cf_password = configured_facility['password']
36
+ @cf_token = configured_facility['token']
37
+ puts "\nConfigured facility for third party: #{tp_id}/#{options[:id]}"
38
+ table = Terminal::Table.new headings: [ 'Service Def Id', 'Facility ID', 'User name', 'Enabled', 'Password', 'Token' ] do |t|
39
+ t << [ configured_facility['service_definition_id'],
40
+ "#{configured_facility['facility_name']} (#{configured_facility['facility_id']})",
41
+ configured_facility['username'],
42
+ configured_facility['enabled'],
43
+ configured_facility['password'],
44
+ configured_facility['token'] ]
45
+ end
46
+ puts table
47
+ puts
48
+ end
49
+
50
+ def create
51
+ tp_id = third_party_id
52
+ sd_id = service_definition_id
53
+ params = {
54
+ configured_facility: {
55
+ facility_id: prompter.ask("\nFacility ID: ", Integer) { |q| q.validate = lambda { | f | is_valid_object?('Facility', f) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Facility ID" },
56
+ username: prompter.ask("\nUser name: ") { |q| q.validate = /\A.{0,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid user name" },
57
+ enabled: prompter.agree("\nEnabled? (y/n) ", true)
58
+ }
59
+ }
60
+ puts
61
+ password = prompter.ask("\nPassword: ")
62
+ token = prompter.ask("\nToken: ")
63
+ if (password && password.size > 0) || (token && token.size > 0)
64
+ params[:credential] = {
65
+ }
66
+ params[:credential][:password] = password if password && password.size > 0
67
+ params[:credential][:token] = token if token && token.size > 0
68
+ end
69
+ result = post("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_facilities", params)
70
+ puts "\nID of new configured facility: #{result['id']}"
71
+ puts
72
+ end
73
+
74
+ def update
75
+ clear_default = ->(field) { field == "^" ? '' : field }
76
+ tp_id = third_party_id
77
+ sd_id = service_definition_id
78
+ cf_id = configured_facility_id
79
+ show
80
+ params = {
81
+ configured_facility: {
82
+ facility_id: prompter.ask("\nFacility ID: ", Integer) { |q| q.default = @cf_facility_id; q.validate = lambda { | f | is_valid_object?('Facility', f) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Facility ID" },
83
+ username: prompter.ask("\nUser name (^ to clear): ", clear_default) { |q| q.default = @cf_username; q.validate = /\A.{0,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nInvalid user name" },
84
+ enabled: prompter.agree("\nEnabled? ", true) { |q| q.default = @cf_enabled }
85
+ }
86
+ }
87
+ puts
88
+ password = prompter.ask("\nPassword (^ to clear): ", clear_default) { |q| q.default = @cf_password }
89
+ token = prompter.ask("\nToken (^ to clear): ", clear_default) { |q| q.default = @cf_token }
90
+ if (password && password.size > 0) || (token && token.size > 0)
91
+ params[:credential] = {
92
+ }
93
+ params[:credential][:password] = password if password && password.size > 0
94
+ params[:credential][:token] = token if token && token.size > 0
95
+ end
96
+ result = put("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_facilities/#{cf_id}", params)
97
+ puts "\nID of updated configured facility: #{result['id']}"
98
+ puts
99
+ end
100
+
101
+ def destroy
102
+ tp_id = third_party_id
103
+ sd_id = service_definition_id
104
+ cf_id = configured_facility_id
105
+ show
106
+ if prompter.agree("\nAre you sure you want to destroy this configured facility? (y/n) ", true)
107
+ puts
108
+ result = delete("services/third_parties/#{tp_id}/service_definitions/#{sd_id}/configured_facilities/#{cf_id}")
109
+ puts "\nID of deleted configured facility: #{result['id']}"
110
+ else
111
+ puts "\nCancelled deletion"
112
+ end
113
+ puts
114
+ end
115
+
116
+ end
117
+
118
+ end
@@ -0,0 +1,90 @@
1
+ module Resources
2
+
3
+ class FacilityMapping < BaseResource
4
+ include ThirdPartyPrompter
5
+ include FacilityMappingPrompter
6
+
7
+ def list
8
+ tp_id = third_party_id
9
+ result = get("services/third_parties/#{tp_id}/facility_mappings")
10
+ puts "\nFacility Mappings for third party: #{tp_id}"
11
+ table = Terminal::Table.new headings: [ 'Third Party Id', 'Facility Id', 'Facility Code', 'Top Level' ] do |t|
12
+ result.each do | facility_mapping |
13
+ t << [ "#{facility_mapping['third_party_name']} (#{facility_mapping['third_party_id']})",
14
+ "#{facility_mapping['facility_name']} (#{facility_mapping['facility_id']})",
15
+ facility_mapping['facility_code'],
16
+ facility_mapping['top_level'] ]
17
+ end
18
+ end
19
+ prompter.say table.to_s
20
+ puts
21
+ end
22
+
23
+ def show
24
+ tp_id = third_party_id
25
+ fm_id = facility_mapping_id
26
+ facility_mapping = get("services/third_parties/#{tp_id}/facility_mappings/#{fm_id}")
27
+ @fm_third_party_id = facility_mapping['third_party_id']
28
+ @fm_facility_id = facility_mapping['facility_id']
29
+ @fm_facility_code = facility_mapping['facility_code']
30
+ @fm_top_level = facility_mapping['top_level']
31
+ puts "\nFacility Mapping for third party: #{tp_id}/#{fm_id}"
32
+ table = Terminal::Table.new headings: [ 'Third Party Id', 'Facility Id', 'Facility Code', 'Top Level' ] do |t|
33
+ t << [ "#{facility_mapping['third_party_name']} (#{facility_mapping['third_party_id']})",
34
+ "#{facility_mapping['facility_name']} (#{facility_mapping['facility_id']})",
35
+ facility_mapping['facility_code'],
36
+ facility_mapping['top_level'] ]
37
+ end
38
+ puts table
39
+ puts
40
+ end
41
+
42
+ def create
43
+ tp_id = third_party_id
44
+ params = {
45
+ facility_mapping: {
46
+ facility_id: prompter.ask("\nabaqis Facility ID: ", Integer) { |q| q.validate = lambda { | a | is_valid_object?('Facility', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Facility ID" },
47
+ facility_code: prompter.ask("\nThird party facility id: ") { |q| q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid third party facility ID" },
48
+ top_level: prompter.agree("\nTop Level? ", true)
49
+ }
50
+ }
51
+ puts
52
+ result = post("services/third_parties/#{tp_id}/facility_mappings", params)
53
+ puts "\nID of new facility mapping: #{result['id']}"
54
+ puts
55
+ end
56
+
57
+ def update
58
+ tp_id = third_party_id
59
+ fm_id = facility_mapping_id
60
+ show
61
+ params = {
62
+ facility_mapping: {
63
+ facility_id: prompter.ask("\nabaqis Facility ID: ", Integer) { |q| q.default = @fm_facility_id; q.validate = lambda { | a | is_valid_object?('Facility', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Facility ID" },
64
+ facility_code: prompter.ask("\nThird party facility id: ") { |q| q.default = @fm_facility_code; q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid third party facility ID" },
65
+ top_level: prompter.agree("\nTop level? ", true) { |q| q.default = @fm_top_level }
66
+ }
67
+ }
68
+ puts
69
+ result = put("services/third_parties/#{tp_id}/facility_mappings/#{fm_id}", params)
70
+ puts "\nID of updated facility mapping: #{result['id']}"
71
+ puts
72
+ end
73
+
74
+ def destroy
75
+ tp_id = third_party_id
76
+ fm_id = facility_mapping_id
77
+ show
78
+ if prompter.agree("\nAre you sure you want to destroy this facility mapping? (y/n) ", true)
79
+ puts
80
+ result = delete("services/third_parties/#{tp_id}/facility_mappings/#{fm_id}")
81
+ puts "\nID of deleted facility mapping: #{result['id']}"
82
+ else
83
+ puts "\nCancelled deletion"
84
+ end
85
+ puts
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,55 @@
1
+ module Resources
2
+
3
+ class MdsPullAccount < BaseResource
4
+ include ServicePrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredAccountPrompter
7
+
8
+ def list
9
+ result = nil
10
+ sv_id = service_id
11
+ sd_id = service_definition_id(true)
12
+ if sd_id > 0
13
+ ca_id = configured_account_id(true)
14
+ if ca_id > 0
15
+ result = get("services/services/#{sv_id}/service_definitions/#{sd_id}/configured_accounts/#{ca_id}/mds_pull_accounts#{status_prompt}")
16
+ else
17
+ result = get("services/services/#{sv_id}/service_definitions/#{sd_id}/mds_pull_accounts#{status_prompt}")
18
+ end
19
+ else
20
+ result = get("services/services/#{sv_id}/mds_pull_accounts#{status_prompt}")
21
+ end
22
+ puts "\nMds Pull Accounts"
23
+ table = Terminal::Table.new headings: [ 'CA Id', 'Account', 'Status', 'Attempt', 'Created', 'Updated' ] do |t|
24
+ result.each do | mds_pull_account |
25
+ t << [ mds_pull_account['configured_account_id'],
26
+ "#{mds_pull_account['account_name']} (#{mds_pull_account['account_id']})",
27
+ mds_pull_account['status'],
28
+ mds_pull_account['attempt'],
29
+ mds_pull_account['created_at'],
30
+ mds_pull_account['updated_at'] ]
31
+
32
+ end
33
+ end
34
+ prompter.say table.to_s
35
+ puts
36
+ end
37
+
38
+ def status_prompt
39
+ puts
40
+ status = prompter.choose do | menu |
41
+ menu.prompt = "Select the status to filter the results with: "
42
+ menu.choice("Do not filter by status") { -1 }
43
+ menu.choice("New") { 0 }
44
+ menu.choice("Files Identified") { 1 }
45
+ menu.choice("Files Downloaded") { 2 }
46
+ menu.choice("Submitted to abaqis") { 3 }
47
+ menu.choice("File System Clean") { 4 }
48
+ menu.choice("Remote Clean") { 5 }
49
+ end
50
+ status < 0 ? "" : "?status=#{status}"
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,28 @@
1
+ module Resources
2
+
3
+ class Provider < BaseResource
4
+ include ThirdPartyPrompter
5
+ include ServiceDefinitionPrompter
6
+ include ConfiguredAccountPrompter
7
+
8
+ def list
9
+ tp_id = third_party_id
10
+ sd_id = service_definition_id
11
+ ca_id = configured_account_id
12
+
13
+ result = get("services/sltc_providers?configured_account_id=#{ca_id}")
14
+
15
+ puts "\nProviders for account:"
16
+ table = Terminal::Table.new headings: [ 'id', 'Name' ] do |t|
17
+ result.each do | provider |
18
+ t << [ provider['id'], provider['name'] ]
19
+ end
20
+ end
21
+
22
+ prompter.say table.to_s
23
+ puts
24
+ end
25
+
26
+ end
27
+
28
+ end