Skip to content

Instantly share code, notes, and snippets.

@thecocktail
Created August 7, 2015 07:46
Show Gist options
  • Save thecocktail/203c962dc8e71cf33c21 to your computer and use it in GitHub Desktop.
Save thecocktail/203c962dc8e71cf33c21 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# seen on ap 11:22:33:44:55:66 with rssi 24 at Tue Mar 26 11:50:31.836 UTC 2013
require 'rubygems'
require 'sinatra'
require 'json'
if ARGV.size < 2
# The sinatra gem parses the -o and -p options for us.
puts "usage: sample_push_api_server.rb [-o <addr>] [-p <port>] <secret> <validator>"
exit 1
end
SECRET = ARGV[-2]
VALIDATOR = ARGV[-1]
get '/events' do
VALIDATOR
end
post '/events' do
@json = JSON.parse(request.body.read)
#logger.info JSON.pretty_generate @json
apMac = @json['data']['apMac']
logger.info "Access point = #{apMac}"
observations = @json['data']['observations']
for i in observations do
logger.info " --- #{i['clientMac']} #{i['location']['lat']} #{i['location']['lng']}"
end
""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment