Class: HCUtil::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/hcutil/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Auth

Returns a new instance of Auth.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hcutil/auth.rb', line 6

def initialize(options = {})
  home_env = ENV['HOME']
  if home_env.nil_or_empty? or not Dir.exist?(ENV['HOME'])
    raise(Errors::AuthError, 'HOME env var not set or dir does not exist')
  end

  auth_file = File.join(ENV['HOME'], '.hcapi')
  if File.exists?(auth_file)
    @auth_token = File.read(auth_file).gsub("\n", ' ').squeeze(' ')
    $stderr.puts("Auth token: #{auth_token}") if options[:verbose]
  else
    raise(Errors::AuthError, 'missing auth token file ~/.hcapi')
  end
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



4
5
6
# File 'lib/hcutil/auth.rb', line 4

def auth_token
  @auth_token
end