Class: Resources::UserMapping
  
  
  
  Instance Attribute Summary
  
  Attributes inherited from BaseResource
  #options, #prompter
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #user_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/user_mapping.rb', line 39
def create
  tp_id = third_party_id
  params = { 
    user_mapping: {
      user_id: prompter.ask("\nabaqis User ID: ", Integer) { |q| q.validate = lambda { | a | is_valid_object?('User', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid user ID" },
      user_code: prompter.ask("\nThird party User Code: ") { |q| q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid third party user ID" }
    }
  }
  result = post("services/third_parties/#{tp_id}/user_mappings", params)
  puts "\nID of new user 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/user_mapping.rb', line 67
def destroy
  tp_id = third_party_id
  um_id = user_mapping_id
  show
  if prompter.agree("\nAre you sure you want to destroy this user mapping? (y/n) ", true)
    puts
    result = delete("services/third_parties/#{tp_id}/user_mappings/#{um_id}")
    puts "\nID of deleted user 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/user_mapping.rb', line 7
def list
  tp_id = third_party_id
  result = get("services/third_parties/#{tp_id}/user_mappings")
  puts "\nUser Mappings for third party: #{tp_id}"
  table = Terminal::Table.new headings: [ 'Third Party', 'User', 'User Code' ] do |t|
  result.each do | user_mapping |
    t << [ "#{user_mapping['third_party_name']} (#{user_mapping['third_party_id']})",
           "#{user_mapping['user_name']} (#{user_mapping['user_id']})",
           user_mapping['user_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/user_mapping.rb', line 22
def show
  tp_id = third_party_id
  um_id = user_mapping_id
  user_mapping = get("services/third_parties/#{tp_id}/user_mappings/#{um_id}")
  @um_third_party_id = user_mapping['third_party_id']
  @um_user_id = user_mapping['user_id']
  @um_user_code = user_mapping['user_code']
  puts "\nUser Mapping for third party: #{tp_id}/#{um_id}"
  table = Terminal::Table.new headings: [ 'Third Party', 'User', 'User Code' ] do |t|
    t << [ "#{user_mapping['third_party_name']} (#{user_mapping['third_party_id']})",
           "#{user_mapping['user_name']} (#{user_mapping['user_id']})",
           user_mapping['user_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/user_mapping.rb', line 52
def update
  tp_id = third_party_id
  um_id = user_mapping_id
  show
  params = { 
    user_mapping: {
      user_id: prompter.ask("\nabaqis User ID: ", Integer) { |q| q.default = @um_user_id; q.validate = lambda { | a | is_valid_object?('User', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid user ID" },
      user_code: prompter.ask("\nThird party User Code: ")  { |q| q.default = @um_user_code; q.validate = /\A.{1,255}\z/; q.responses[:not_valid] = "\nNot a valid third party user ID" }
    }
  }
  result = put("services/third_parties/#{tp_id}/user_mappings/#{um_id}", params)
  puts "\nID of updated user mapping: #{result['id']}"
  puts
end |