module Getauthtoken

Constants

AUTH_PATH
VERSION

Public Class Methods

authenticate(password) click to toggle source
# File lib/getauthtoken.rb, line 8
def self.authenticate(password)
   config = get_config()
   post_credentials(config, password) 
end
get_config() click to toggle source
# File lib/getauthtoken.rb, line 13
def self.get_config()
  file = File.open(File.expand_path("~/.xaptum_config.json"))
  data = JSON.load file
  file.close
  data
end
pbcopy(token) click to toggle source
# File lib/getauthtoken.rb, line 29
def self.pbcopy(token)
  IO.popen('pbcopy', 'w') { |f| f << token }
end
post_credentials(config, password) click to toggle source
# File lib/getauthtoken.rb, line 20
def self.post_credentials(config, password)
  hash = { "username" => config["username"], "token" => password}
  json = JSON.generate(hash)
  response = HTTP.headers("Content-Type": "application/json", "Accept": "application/json")
    .post(config["host"] + AUTH_PATH, body: json)
  
  response.code == 200 ? JSON.parse(response)["data"][0]["token"] : nil
end