Sha256: 1990922c515af5907988e825af29e1eac0a6863acf1b2e84d4494c0e7009de27

Contents?: true

Size: 802 Bytes

Versions: 4

Compression:

Stored size: 802 Bytes

Contents

# frozen_string_literal: true

require 'yaml'

class RenuoCliConfig
  CONFIG_FILE_PATH = "#{File.expand_path('~')}/.renuo_cli".freeze

  class << self
    def redmine_api_key
      get_config_value('REDMINE_API_KEY', 'https://redmine.renuo.ch/my/account')
    end

    def toggl_api_token
      get_config_value('TOGGL_API_TOKEN', 'https://toggl.com/app/profile')
    end

    private

    def get_config_value(name, open_url)
      FileUtils.touch(CONFIG_FILE_PATH)
      config = YAML.load_file(CONFIG_FILE_PATH, fallback: {})
      value = config[name]
      return value if value

      system("open #{open_url}")
      value = ask("You haven't set your #{name}, yet. Please provide one:")
      config[name] = value
      File.write(CONFIG_FILE_PATH, config.to_yaml)
      value
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
renuo-cli-4.5.0 lib/renuo/cli/app/services/renuo_cli_config.rb
renuo-cli-4.3.0 lib/renuo/cli/app/services/renuo_cli_config.rb
renuo-cli-4.2.1 lib/renuo/cli/app/services/renuo_cli_config.rb
renuo-cli-4.2.0 lib/renuo/cli/app/services/renuo_cli_config.rb