Sha256: 3160bccbf7907ff4ed7699e4caf3d20bdcb74bda30530894266d5af6600c97b9

Contents?: true

Size: 800 Bytes

Versions: 6

Compression:

Stored size: 800 Bytes

Contents

module ThirdPartyPrompter

  def third_party_id(allow_none=false)
    return options[:third_party_id] if options[:third_party_id]
    return options[:third_party_id] = ENV['THIRD_PARTY_ID'] if ENV['THIRD_PARTY_ID']
    return options[:third_party_id] = prompt_for_third_party_id(allow_none)
  end

  private

  def prompt_for_third_party_id(allow_none)
    result = get("services/third_parties")

    (puts "No third parties are defined. Cannot continue"; exit 1) if result.empty?

    # Build a menu of the third parties
    puts
    return prompter.choose do | menu |
      menu.prompt = "Select the Third Party: "
      menu.choice("No Selection") { -1 } if allow_none
      result.each do | third_party |
        menu.choice(third_party['name']) { third_party['id'] }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pvdgm-svc-client-0.3.4 lib/pvdgm-svc-client/prompters/third_party_prompter.rb
pvdgm-svc-client-0.3.3 lib/pvdgm-svc-client/prompters/third_party_prompter.rb
pvdgm-svc-client-0.3.2 lib/pvdgm-svc-client/prompters/third_party_prompter.rb
pvdgm-svc-client-0.2.2 lib/pvdgm-svc-client/prompters/third_party_prompter.rb
pvdgm-svc-client-0.2.1 lib/pvdgm-svc-client/prompters/third_party_prompter.rb
pvdgm-svc-client-0.1.6 lib/pvdgm-svc-client/prompters/third_party_prompter.rb