Class: Nsrr::Helpers::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/nsrr/helpers/authorization.rb

Overview

Helper to verify that user is authenticated.

Class Method Summary collapse

Class Method Details

.get_token(token) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nsrr/helpers/authorization.rb', line 10

def self.get_token(token)
  puts  "  Get your token here: " + "#{Nsrr::WEBSITE}/token".bg_gray.blue.underline
  puts  "  Your input is hidden while entering token.".white
  print "     Enter your token: "
  token = STDIN.noecho(&:gets).chomp if token.to_s.strip == ""
  token.strip!
  (response, _status) = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}/api/v1/account/profile.json", auth_token: token)
  if response.is_a?(Hash) && response["authenticated"]
    puts "AUTHORIZED".green + " as " + "#{response["first_name"]} #{response["last_name"]}".white
  else
    puts "UNAUTHORIZED".red + " Public Access Only"
  end
  token
end