Created
September 5, 2013 00:37
-
-
Save drewkerrigan/6444623 to your computer and use it in GitHub Desktop.
query endpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/query/zip3/:zip' do | |
zip = params[:zip] | |
zip3 = zip[0, 3] | |
zips = zip3_idx.get_index(zip3) | |
results = zips.members.to_a | |
if zip.length > 3 | |
results = results.select { |item| item.start_with? zip } | |
end | |
results.sort.to_json | |
end | |
get '/query/:index/:zip' do | |
start = (params.keys.include?('start')) ? params[:start] : 1 | |
zombie = Zombie.new(client) | |
#validate index | |
index = params[:index] | |
return 'Invalid index' unless ['zip_inv', 'zip_bin'].include? index | |
keys = zombie.search_index(params[:index], params[:zip]) | |
results = zombie.fetch_with_pagination(keys, start.to_i) | |
results.to_json | |
end | |
get '/query/geo' do | |
start = (params.keys.include?('start')) ? params[:start] : 1 | |
zombie = Zombie.new(client) | |
zombie.data[:latitude] = params[:lat].to_f | |
zombie.data[:longitude] = params[:lon].to_f | |
keys = zombie.search_index('geohash_inv', zombie.geohash(4)) | |
results = zombie.fetch_with_pagination(keys, start.to_i) | |
results.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment