Class: Resources::AccountMapping
Instance Attribute Summary
Attributes inherited from BaseResource
#options, #prompter
Instance Method Summary
collapse
#account_mapping_id
#third_party_id
#initialize
Constructor Details
This class inherits a constructor from BaseResource
Instance Method Details
#create ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/pvdgm-svc-client/resources/account_mapping.rb', line 39
def create
tp_id = third_party_id
params = {
account_mapping: {
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" },
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" }
}
}
result = post("services/third_parties/#{tp_id}/account_mappings", params)
puts "\nID of new account mapping: #{result['id']}"
puts
end
|
#destroy ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/pvdgm-svc-client/resources/account_mapping.rb', line 67
def destroy
tp_id = third_party_id
am_id = account_mapping_id
show
if prompter.agree("\nAre you sure you want to destroy this account mapping? (y/n) ", true)
puts
result = delete("services/third_parties/#{tp_id}/account_mappings/#{am_id}")
puts "\nID of deleted account mapping: #{result['id']}"
else
puts "\nCancelled deletion"
end
puts
end
|
#list ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/pvdgm-svc-client/resources/account_mapping.rb', line 7
def list
tp_id = third_party_id
result = get("services/third_parties/#{tp_id}/account_mappings")
puts "\nAccount Mappings for third party: #{tp_id}"
table = Terminal::Table.new headings: [ 'Third Party', 'Account', 'Account Code' ] do |t|
result.each do | account_mapping |
t << [ "#{account_mapping['third_party_name']} (#{account_mapping['third_party_id']})",
"#{account_mapping['account_name']} (#{account_mapping['account_id']})",
account_mapping['account_code'] ]
end
end
prompter.say table.to_s
puts
end
|
#show ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/pvdgm-svc-client/resources/account_mapping.rb', line 22
def show
tp_id = third_party_id
am_id = account_mapping_id
account_mapping = get("services/third_parties/#{tp_id}/account_mappings/#{am_id}")
@am_third_party_id = account_mapping['third_party_id']
@am_account_id = account_mapping['account_id']
@am_account_code = account_mapping['account_code']
puts "\nAccount Mapping for third party: #{tp_id}/#{am_id}"
table = Terminal::Table.new headings: [ 'Third Party', 'Account', 'Account Code' ] do |t|
t << [ "#{account_mapping['third_party_name']} (#{account_mapping['third_party_id']})",
"#{account_mapping['account_name']} (#{account_mapping['account_id']})",
account_mapping['account_code'] ]
end
puts table
puts
end
|
#update ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/pvdgm-svc-client/resources/account_mapping.rb', line 52
def update
tp_id = third_party_id
am_id = account_mapping_id
show
params = {
account_mapping: {
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" },
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" }
}
}
result = put("services/third_parties/#{tp_id}/account_mappings/#{am_id}", params)
puts "\nID of updated account mapping: #{result['id']}"
puts
end
|