module ZendeskAppsTools::Common

Public Instance Methods

api_request(url, request = Faraday.new) click to toggle source
# File lib/zendesk_apps_tools/common.rb, line 5
def api_request(url, request = Faraday.new)
  request.get(url)
end
get_password_from_stdin(prompt) click to toggle source
# File lib/zendesk_apps_tools/common.rb, line 34
def get_password_from_stdin(prompt)
  print "#{prompt} "
  password = STDIN.noecho(&:gets).chomp
  puts
  password
end
get_value_from_stdin(prompt, opts = {}) click to toggle source
# File lib/zendesk_apps_tools/common.rb, line 15
def get_value_from_stdin(prompt, opts = {})
  options = {
    valid_regex: opts[:allow_empty] ? /^.*$/ : /\S+/,
    error_msg: 'Invalid, try again:',
    allow_empty: false
  }.merge(opts)

  while input = ask(prompt)
    return '' if input.empty? && options[:allow_empty]
    if input =~ options[:valid_regex]
      break
    else
      say(options[:error_msg], :red)
    end
  end

  input
end
say_error_and_exit(msg) click to toggle source
# File lib/zendesk_apps_tools/common.rb, line 9
def say_error_and_exit(msg)
  raise msg if ENV.key?('ZAT_DEV')
  say msg, :red
  exit 1
end