class DX::Lookup::QRZ

Constants

AGENT
API_VERSION

Attributes

session_key[R]

Public Class Methods

new(username, password, options={}) click to toggle source
# File lib/dx/lookup/qrz.rb, line 18
def initialize(username, password, options={})
  @username, @password = username, password
end

Public Instance Methods

create_session!() click to toggle source
# File lib/dx/lookup/qrz.rb, line 44
def create_session!
  uri = construct_uri(:username => @username, :password => @password, :agent => AGENT)
  response = self.class.get(uri)
  response = response.parsed_response
  check_for_error(response)

  @session_key = response['QRZDatabase']['Session']['Key']
end
get_all_entities() click to toggle source
# File lib/dx/lookup/qrz.rb, line 36
def get_all_entities
  get_entities('all')
end
get_callsign(callsign) click to toggle source
# File lib/dx/lookup/qrz.rb, line 22
def get_callsign(callsign)
  login_if_needed!
  uri = construct_uri(:callsign => callsign)
  response = self.class.get(uri).parsed_response
  check_for_error(response)

  callsign_response = response['QRZDatabase']['Callsign']
  Callsign.from_response(callsign_response)
end
get_callsign_entity(callsign) click to toggle source
# File lib/dx/lookup/qrz.rb, line 40
def get_callsign_entity(callsign)
  get_entities(callsign).first
end
get_dxcc_entity(dxcc) click to toggle source
# File lib/dx/lookup/qrz.rb, line 32
def get_dxcc_entity(dxcc)
  get_entities(dxcc.to_s).first
end

Protected Instance Methods

check_for_error(parsed_response) click to toggle source
# File lib/dx/lookup/qrz.rb, line 64
def check_for_error(parsed_response)
  error = parsed_response['QRZDatabase']['Session']['Error']
  message = parsed_response['QRZDatabase']['Session']['Message']
  raise(APIError, message || error) if error
end
construct_uri(params={}) click to toggle source
# File lib/dx/lookup/qrz.rb, line 55
def construct_uri(params={})
  params = params.merge(:s => session_key) if session_key && !params[:s]
  "?#{params.map { |k, v| "#{k}=#{v}" }.join(';')}"
end
get_entities(callsign) click to toggle source
# File lib/dx/lookup/qrz.rb, line 70
def get_entities(callsign)
  login_if_needed!
  uri = construct_uri(:dxcc => callsign)
  response = self.class.get(uri).parsed_response
  check_for_error(response)
  
  dxccs = [response['QRZDatabase']['DXCC']].flatten
  dxccs.map { |dxcc| Entity.from_response(dxcc) }
end
login_if_needed!() click to toggle source
# File lib/dx/lookup/qrz.rb, line 60
def login_if_needed!
  create_session! unless session_key
end