-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathapp.rb
44 lines (43 loc) · 1.58 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'sinatra'
require 'json'
require 'net/http'
require 'httparty'
get '/' do
erb :map
end
get '/cabs/:latitude/:longitude' do
time = Time.now
result = HTTParty.post("https://97.64.114.226/",
:body => { :_LOCALE_ => 'en_GB',
:app => 'client',
:device => 'android',
:version => '2.7.6',
:language => 'en_GB',
:timestamp => time.strftime("%Y-%m-%d %H:%M:%S"),
:epoch => time.to_i*1000,
:latitude => params[:latitude].to_f,
:longitude => params[:longitude].to_f,
:deviceModel => 'Nexus 4',
:deviceOS => '4.2.2',
:deviceId => ENV['uberdevid'],
:vehicleViewId => 1,
:messageType => 'PingClient',
:token => ENV['ubertoken']
}.to_json)
results = result["nearbyVehicles"]
cablist = results.map do |ctype|
if ctype[1]["sorryMsg"].nil?
ctype[1]["vehiclePaths"].map do |c|
cab = c[1][0]
{ :latitude => cab["latitude"], :longitude => cab["longitude"] }
end
end
end
cablist = cablist.reject{|k,v| v.nil?}
if cablist.empty?
status 404
@latslongs = { :error_msg => "No cabs found" }.to_json
else
@latslongs = cablist.to_json
end
end