Sha256: 4ae072d00bbbcfc6631acda3aea7d99bf7a74fdfd92c4658036a6e0096e0d83a

Contents?: true

Size: 938 Bytes

Versions: 5

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

require "nsrr/helpers/color"
require "nsrr/helpers/json_request"

module Nsrr
  module Helpers
    # Helper to verify that user is authenticated.
    class Authorization
      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
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nsrr-8.0.0 lib/nsrr/helpers/authorization.rb
nsrr-7.0.0 lib/nsrr/helpers/authorization.rb
nsrr-6.0.0 lib/nsrr/helpers/authorization.rb
nsrr-5.0.0 lib/nsrr/helpers/authorization.rb
nsrr-5.0.0.rc lib/nsrr/helpers/authorization.rb