Class: Envirobly::AccessToken

Inherits:
Object
  • Object
show all
Defined in:
lib/envirobly/access_token.rb

Instance Method Summary collapse

Constructor Details

#initialize(token = ENV.fetch("ENVIROBLY_ACCESS_TOKEN", nil)) ⇒ AccessToken



5
6
7
8
9
10
11
# File 'lib/envirobly/access_token.rb', line 5

def initialize(token = ENV.fetch("ENVIROBLY_ACCESS_TOKEN", nil))
  if token.nil? && File.exist?(access_token_path)
    @token = File.read(access_token_path)
  else
    @token = token
  end
end

Instance Method Details

#as_http_bearerObject



20
21
22
# File 'lib/envirobly/access_token.rb', line 20

def as_http_bearer
  "Bearer #{@token}"
end

#saveObject



13
14
15
16
17
18
# File 'lib/envirobly/access_token.rb', line 13

def save
  FileUtils.mkdir_p config_root
  File.write access_token_path, @token
  File.chmod 0600, access_token_path
  puts "Access token saved to #{access_token_path}"
end