Class: Abt::Providers::Harvest::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/abt/providers/harvest/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli:) ⇒ Configuration

Returns a new instance of Configuration.



9
10
11
# File 'lib/abt/providers/harvest/configuration.rb', line 9

def initialize(cli:)
  @cli = cli
end

Instance Attribute Details

#cliObject

Returns the value of attribute cli.



7
8
9
# File 'lib/abt/providers/harvest/configuration.rb', line 7

def cli
  @cli
end

Instance Method Details

#access_tokenObject



33
34
35
36
37
38
39
40
41
42
# 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_idObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/abt/providers/harvest/configuration.rb', line 44

def 
  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) ⇒ Object



29
30
31
# 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) ⇒ Object



25
26
27
# 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?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/abt/providers/harvest/configuration.rb', line 13

def local_available?
  git.available?
end

#pathObject



17
18
19
# 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) ⇒ Object



21
22
23
# File 'lib/abt/providers/harvest/configuration.rb', line 21

def path=(new_path)
  git["path"] = new_path
end

#user_idObject



55
56
57
58
59
# 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