Sha256: b5d402c9905e6c57f8b52c1fbbfd9154b19252bea41e29130b87391fc9276575

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require "cp8_cli/config_store"
require "cp8_cli/trello/base"

module Cp8Cli
  class GlobalConfig
    PATH = ENV["HOME"] + "/.trello_flow"

    def initialize(store = nil)
      @store = store || ConfigStore.new(PATH)
    end

    def trello_key
      @_trello_key ||= store[:key] || configure_trello_key
    end

    def trello_token
      @_trello_token ||= store[:token] || configure_trello_token
    end

    def github_token
      @_github_token ||= store[:github_token] || env_github_token || configure_github_token
    end

    private

      attr_reader :store

      def configure_trello_key
        Command.ask "Press enter to setup Trello for this project (will open public key url)", validate: //
        Command.open_url "https://trello.com/app-key"
        store.save :key, Command.ask("Input Developer API key")
      end

      def configure_trello_token
        Command.open_url trello_authorize_url
        store.save :token, Command.ask("Input member token")
      end

      def env_github_token
        ENV["OCTOKIT_ACCESS_TOKEN"]
      end

      def configure_github_token
        store.save :github_token, Command.ask("Input GitHub token")
      end

      def trello_authorize_url
        "https://trello.com/1/authorize?key=#{trello_key}&name=Trello-Flow&scope=read,write,account&expiration=never&response_type=token"
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cp8_cli-6.0.1 lib/cp8_cli/global_config.rb
cp8_cli-6.0.0 lib/cp8_cli/global_config.rb
cp8_cli-5.0.0 lib/cp8_cli/global_config.rb
cp8_cli-4.2.1 lib/cp8_cli/global_config.rb
cp8_cli-4.2.0 lib/cp8_cli/global_config.rb
cp8_cli-4.1.3 lib/cp8_cli/global_config.rb