-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull_routes
executable file
·46 lines (31 loc) · 919 Bytes
/
pull_routes
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
45
46
#!/usr/bin/ruby -w
require 'net/http'
require 'json'
require 'pp'
GOOGLE_MAPS_URL = "https://maps.googleapis.com/maps/api/directions/json"
GOOGLE_MAPS_KEY = "key=AIzaSyCnNSIiNWSOTO1nHxD7f-MTczEvXeBgAJo"
def build_query( origin, destination)
URI("#{GOOGLE_MAPS_URL}?origin=#{origin}&destination=#{destination}&alternatives=true&#{GOOGLE_MAPS_KEY}")
end
def printHelpAndExit( plaint="Usage:=")
STDERR.puts "
#{plaint}
#{__FILE__} --help
Output this help text
#{__FILE_} origin destination
or
Run as a cgi script, expecting parameters origin and destination
Outputs JSON result to stdout.
"
exit(1)
end
if ARGV.empty?
origin="-43.590887,172.58077"
destination="875%20cashmere%20road,christchurch"
elsif ARGV.size == 2
origin,destination = *ARGV
else
printHelpAndExit( "Incorrect number of arguments #{ARGV.inspect}")
end
query = build_query(origin,destination)
puts Net::HTTP.get(query)