class NewlineHw::Token

Constants

NETRC_KEY

Public Class Methods

decode(token) click to toggle source
# File lib/newline_hw/token.rb, line 8
def self.decode(token)
  payload = JWT.decode(token, nil, false)
  payload[0]
end
get_for_path() click to toggle source
# File lib/newline_hw/token.rb, line 13
def self.get_for_path
  path_config = YAML.load_file(".path.config")
  path_config["token"]
end
get_for_user() click to toggle source
# File lib/newline_hw/token.rb, line 18
def self.get_for_user
  return ENV["NEWLINE_API_TOKEN"] if ENV["NEWLINE_API_TOKEN"]
  if (netrc = netrc_file[NETRC_KEY])
    netrc["password"]
  else
    raise NewlineHw::AuthenticationError, "No stored credentials or ENV[\"NEWLINE_API_TOKEN\"]"
  end
end

Private Class Methods

netrc_file() click to toggle source
# File lib/newline_hw/token.rb, line 29
def self.netrc_file
  Netrc.read("#{Netrc.home_path}/#{Netrc.netrc_filename}")
end