module NetProspex::QueryMethods

Public Instance Methods

find_people(query) click to toggle source
# File lib/netprospex/query_methods.rb, line 23
def find_people(query)
  # these are boolean but the API wants 0 or 1
  [:calc_found_rows, :preview].each do |k|
    query[k] = 1 if query[k]
  end
  response = get('/person/list.json', query)
  store_balance(response)
  if persons = fetch_key_from_response_hash(:person_list, response)[:persons]
    return persons.map{|p| NetProspex::Api::Person.new(p)}
  else
    return [] #TODO should this raise an error?
  end
end
find_person(query) click to toggle source
# File lib/netprospex/query_methods.rb, line 5
def find_person(query)
  response = get('/person/profile.json', query)
  store_balance(response)
  if p = fetch_key_from_response_hash(:person_profile, response)[:person]
    return NetProspex::Api::Person.new(p)
  else
    return nil
  end
end
find_person_by_email(email) click to toggle source
# File lib/netprospex/query_methods.rb, line 19
def find_person_by_email(email)
  find_person(email: email)
end
find_person_by_id(id) click to toggle source
# File lib/netprospex/query_methods.rb, line 15
def find_person_by_id(id)
  find_person(person_id: id)
end

Protected Instance Methods

store_balance(hash) click to toggle source
# File lib/netprospex/query_methods.rb, line 39
def store_balance(hash)
  balance = fetch_key_from_response_hash(:transaction, hash)[:account_end_balance]
  @account_balance = balance if balance
end

Private Instance Methods

fetch_key_from_response_hash(key, response_hash) click to toggle source
# File lib/netprospex/query_methods.rb, line 46
def fetch_key_from_response_hash(key, response_hash)
  response = response_hash.fetch(:response, {})
  raise UnexpectedResponseError, "Unexpected response: #{response}" unless response.respond_to?(:fetch)
  response.fetch(key, {})
end