Class: Resources::AccountMapping

Inherits:
BaseResource show all
Includes:
AccountMappingPrompter, ThirdPartyPrompter
Defined in:
lib/pvdgm-svc-client/resources/account_mapping.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#options, #prompter

Instance Method Summary collapse

Methods included from AccountMappingPrompter

#account_mapping_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

#createObject



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

#destroyObject



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 = 
  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

#listObject



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 |  |
    t << [ "#{['third_party_name']} (#{['third_party_id']})",
           "#{['account_name']} (#{['account_id']})",
           ['account_code'] ]
    end
  end
  prompter.say table.to_s
  puts
end

#showObject



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 = 
   = get("services/third_parties/#{tp_id}/account_mappings/#{am_id}")
  @am_third_party_id = ['third_party_id']
  @am_account_id = ['account_id']
  @am_account_code = ['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 << [ "#{['third_party_name']} (#{['third_party_id']})",
           "#{['account_name']} (#{['account_id']})",
           ['account_code'] ]
  end
  puts table
  puts
end

#updateObject



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 = 
  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