class Resources::ThirdParty

Constants

EMAIL_REGEX

Public Instance Methods

create() click to toggle source
# File lib/pvdgm-svc-client/resources/third_party.rb, line 36
def create
  params = { 
    third_party: {
      name: prompter.ask("\nName for new third party: ") { |q| q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Third Party Name" },
      key: prompter.ask("\nUnique key for third party: ") { |q| q.validate = /\A[a-zA-Z0-9_-]{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Third Party key" },
      account_id: prompter.ask("\nAccount ID: ") { |q| q.validate = lambda { | a | a.blank? || is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Account ID" },
      contact_email: prompter.ask("\nContact email address for new third party: ") { |q| q.validate = EMAIL_REGEX; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid email address" }
    }
  }
  result = post("services/third_parties", params)
  puts "\nID of new third party: #{result['id']}"
  puts
end
list() click to toggle source
# File lib/pvdgm-svc-client/resources/third_party.rb, line 8
def list
  result = get("services/third_parties")
  puts "\nThird Parties:"
  table = Terminal::Table.new headings: [ 'Name', 'Key', 'Account ID', 'Contact Email' ] do |t|
    result.each do | third_party |
      t << [ third_party['name'], third_party['key'], third_party['account_id'].present? ? "#{third_party['account_name']} (#{third_party['account_id']})" : '' , third_party['contact_email'] ]
    end
  end

  prompter.say table.to_s
  puts
end
show() click to toggle source
# File lib/pvdgm-svc-client/resources/third_party.rb, line 21
def show
  tp_id = third_party_id
  result = get("services/third_parties/#{tp_id}")
  @third_party_name = result['name']
  @third_party_key = result['key']
  @third_party_acct_id = result['account_id']
  @third_party_contact_email = result['contact_email']
  puts "\nThird Party"
  table = Terminal::Table.new headings: [ 'Name', 'Key', 'Account ID', 'Contact Email' ] do |t|
    t << [ result['name'], result['key'], result['account_id'].present? ? "#{result['account_name']} (#{result['account_id']})" : '', result['contact_email'] ]
  end
  puts table
  puts
end
update() click to toggle source
# File lib/pvdgm-svc-client/resources/third_party.rb, line 50
def update
  show
  params = { 
    third_party: {
      name: prompter.ask("\nNew name for third party: ") { |q| q.default = @third_party_name; q.validate = /\A.{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Third Party Name" },
      key: prompter.ask("\nUnique key for third party: ") { |q| q.default = @third_party_key; q.validate = /\A[a-zA-Z0-9_-]{1,255}\z/; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Third Party key" },
      account_id: prompter.ask("\nAccount ID: ") { |q| q.default = @acct_id; q.validate = lambda { | a | a.blank? || is_valid_object?('Account', a) }; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid Account ID" },
      contact_email: prompter.ask("\nNew contact email address for third party: ") { |q| q.default = @third_party_contact_email; q.validate = EMAIL_REGEX; q.responses[:ask_on_error] = :question; q.responses[:not_valid] = "\nNot a valid email address" }
    }
  }
  result = put("services/third_parties/#{third_party_id}", params)
  puts "\nID of updated third party: #{result['id']}"
  puts
end