class Holistics::AuthApiClient

Public Instance Methods

auth_info() click to toggle source
# File lib/holistics/auth_api_client.rb, line 7
def auth_info
  @auth_info ||= Helpers::AuthInfo.new
end
authenticate(token) click to toggle source
# File lib/holistics/auth_api_client.rb, line 27
def authenticate(token)
  url = auth_info.api_url_for('users/info.json', {})
  response = Helpers::HttpRequest.new.simple_get url, token
  return response, (response.code == 200)
end
login(token) click to toggle source
# File lib/holistics/auth_api_client.rb, line 11
def login token
  puts 'Logging in...'
  response, ok = authenticate(token)
  if ok
    parsed = JSON.parse(response.body)
    puts 'Authentication successful. Info:'
    puts "- ID: #{parsed['id']}"
    puts "- Email: #{parsed['email']}"

    write_token_to_gconfig(token)
  else
    puts 'Error logging in. Please check your token again.'
    puts response
  end
end
write_token_to_gconfig(token) click to toggle source
# File lib/holistics/auth_api_client.rb, line 33
def write_token_to_gconfig(token)
  file_path = File.join(ENV['HOME'], '.holistics.yml')
  h = {'token' => token}
  File.write(file_path, h.to_yaml)
end