class EnvironmentBuilder
Attributes
configs[RW]
Public Class Methods
new()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 10 def initialize @config_manager = ConfigManager.new @configs = {} @env = "dev" end
Public Instance Methods
create_environment(name, silent: false)
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 16 def create_environment(name, silent: false) unless silent puts "Hi, I am ApiBot!" print "You can have multiple environments of API requests and easily switch between them. " puts "To create an environment please follow the steps,\n" puts "Note: I have created some default values for easily getting started." puts "Press enter for using default value." end @configs = @config_manager.get_all if File.exist?(Global::ENV_FILE_PATH) set_environment name get_base_url get_auth_token_header_key get_auth_token_header_value save_config_as_json end
delete_environment(name)
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 41 def delete_environment(name) environments = @config_manager.get_all environments.delete(name) @config_manager.save environments end
get_environment(name:)
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 37 def get_environment(name:) @config_manager.get_by_env(env: name) end
list_environments()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 33 def list_environments @config_manager.get_all end
Private Instance Methods
get_auth_token_header_key()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 62 def get_auth_token_header_key puts "Enter the authorization token header key: [Authorization]" env = $stdin.gets.chomp @configs[@env]["token_key"] = env.empty? ? "Authorization" : env end
get_auth_token_header_value()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 68 def get_auth_token_header_value puts "Enter the authorization token header value. Eg., Bearer asda23245tfasd: ['']" env = $stdin.gets.chomp @configs[@env]["token_value"] = env.empty? ? "" : env end
get_base_url()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 56 def get_base_url puts "Enter the Base URL: ['']" env = $stdin.gets.chomp @configs[@env]["base_url"] = env.empty? ? "" : env end
save_config_as_json()
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 74 def save_config_as_json @config_manager.save(@configs) end
set_environment(name)
click to toggle source
# File lib/cadbury/helpers/environment_builder.rb, line 49 def set_environment(name) env = name @env = env unless env.empty? @configs[@env] = {} unless @configs.key?(@env) @configs[@env]["requests"] = {} end