Class: HCUtil::Auth
- Inherits:
-
Object
- Object
- HCUtil::Auth
- Defined in:
- lib/hcutil/auth.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Auth
constructor
A new instance of Auth.
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( = {}) 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 [:verbose] else raise(Errors::AuthError, 'missing auth token file ~/.hcapi') end end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
4 5 6 |
# File 'lib/hcutil/auth.rb', line 4 def auth_token @auth_token end |