class NatasLevelBase

Base class of level

Constants

HOST
LEVEL
LOGIN
PASSWORD_LENGTH
PORT
WEBPASS

Attributes

login[R]
password[RW]

Public Class Methods

new(shell) click to toggle source
# File lib/natas.rb, line 59
def initialize(shell)
  @shell = shell
  @login = LOGIN + self.class::LEVEL.to_s
  @password = nil
  @client = Net::HTTP.new("#{@login}.#{HOST}", PORT)
end

Public Instance Methods

exec() click to toggle source
# File lib/natas.rb, line 66
def exec; end
get(query, headers = {}) click to toggle source
# File lib/natas.rb, line 72
def get(query, headers = {})
  request = Net::HTTP::Get.new(query, headers)
  request.basic_auth(@login, @password)

  response = @client.request(request)

  raise StandardError, 'Unauthorized' if response.instance_of?(Net::HTTPUnauthorized)

  response
end
level() click to toggle source
# File lib/natas.rb, line 68
def level
  self.class::LEVEL
end
post(query, headers = {}, data = nil, multipart: false) click to toggle source
# File lib/natas.rb, line 83
def post(query, headers = {}, data = nil, multipart: false)
  request = Net::HTTP::Post.new(query, headers)
  request.basic_auth(@login, @password)
  unless data.nil?
    request.set_form(
      data,
      multipart ? 'multipart/form-data' : 'application/x-www-form-urlencoded'
    )
  end

  response = @client.request(request)

  raise StandardError, 'Unauthorized' if response.instance_of?(Net::HTTPUnauthorized)

  response
end

Private Instance Methods

found(password) click to toggle source
# File lib/natas.rb, line 106
def found(password)
  log(@shell.console.green('Password found: ') + @shell.console.cyan.bold(password))
  password
end
log(message) click to toggle source
# File lib/natas.rb, line 102
def log(message)
  puts @shell.console.bold.magenta("[#{@login}] ") + message
end
not_found() click to toggle source
# File lib/natas.rb, line 111
def not_found
  raise StandardError, 'Password not found'
end