class Abt::Providers::Harvest::Configuration

Attributes

cli[RW]

Public Class Methods

new(cli:) click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 9
def initialize(cli:)
  @cli = cli
end

Public Instance Methods

access_token() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 33
def access_token
  return git_global["accessToken"] unless git_global["accessToken"].nil?

  git_global["accessToken"] = cli.prompt.text([
    "Please provide your personal access token for Harvest.",
    "If you don't have one, create one here: https://id.getharvest.com/developers",
    "",
    "Enter access token"
  ].join("\n"))
end
account_id() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 44
def account_id
  return git_global["accountId"] unless git_global["accountId"].nil?

  git_global["accountId"] = cli.prompt.text([
    "Please provide harvest account id.",
    "This information is shown next to your generated access token",
    "",
    "Enter account id"
  ].join("\n"))
end
clear_global(verbose: true) click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 29
def clear_global(verbose: true)
  git_global.clear(output: verbose ? cli.err_output : nil)
end
clear_local(verbose: true) click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 25
def clear_local(verbose: true)
  git.clear(output: verbose ? cli.err_output : nil)
end
local_available?() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 13
def local_available?
  git.available?
end
path() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 17
def path
  Path.new(local_available? && git["path"] || cli.directory_config.dig("harvest", "path") || "")
end
path=(new_path) click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 21
def path=(new_path)
  git["path"] = new_path
end
user_id() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 55
def user_id
  return git_global["userId"] unless git_global["userId"].nil?

  git_global["userId"] = api.get("users/me")["id"].to_s
end

Private Instance Methods

api() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 71
def api
  @api ||= Api.new(access_token: access_token, account_id: account_id)
end
git() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 63
def git
  @git ||= GitConfig.new("local", "abt.harvest")
end
git_global() click to toggle source
# File lib/abt/providers/harvest/configuration.rb, line 67
def git_global
  @git_global ||= GitConfig.new("global", "abt.harvest")
end