post tests via query options available
This commit is contained in:
@@ -1,10 +1,25 @@
|
||||
require 'net/http'
|
||||
|
||||
def request_locate_url path
|
||||
def request_locate_url path, method={}
|
||||
@query = path
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
|
||||
if method.has_key?("post")
|
||||
request_method = "POST"
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/locate"
|
||||
end
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
Net::HTTP.get_response uri
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
path.slice!(0, 11)
|
||||
Net::HTTP.post_form uri, "loc" => path
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
@@ -12,6 +27,6 @@ rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_locate a
|
||||
request_locate_url "locate?loc=#{a}"
|
||||
def request_locate a, method
|
||||
request_locate_url "locate?loc=#{a}", method
|
||||
end
|
||||
|
||||
@@ -13,10 +13,31 @@ def request_matching trace=[], timestamps=[], options={}
|
||||
end
|
||||
params = (trace_params + defaults.merge(options).to_param).join('&')
|
||||
params = nil if params==""
|
||||
uri = URI.parse ["#{HOST}/match", params].compact.join('?')
|
||||
|
||||
if options.has_key?("post")
|
||||
request_method = "POST"
|
||||
options.delete("post")
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse ["#{HOST}/match", params].compact.join('?')
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/match"
|
||||
end
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
Net::HTTP.get_response uri
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
datas = {}
|
||||
datas[:loc] = trace.compact.map { |w| "#{w.lat},#{w.lon}" }
|
||||
if ts.length > 0
|
||||
datas[:t] = timestamps.compact.map { |t| "#{t}" }
|
||||
end
|
||||
datas.merge! options
|
||||
Net::HTTP.post_form uri, datas
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
require 'net/http'
|
||||
|
||||
def request_nearest_url path
|
||||
def request_nearest_url path, method={}
|
||||
@query = path
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
|
||||
if method.has_key?("post")
|
||||
request_method = "POST"
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/nearest"
|
||||
end
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
Net::HTTP.get_response uri
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
path.slice!(0, 12)
|
||||
Net::HTTP.post_form uri, "loc" => path
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
@@ -12,6 +27,6 @@ rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
|
||||
def request_nearest a
|
||||
request_nearest_url "nearest?loc=#{a}"
|
||||
def request_nearest a, method
|
||||
request_nearest_url "nearest?loc=#{a}", method
|
||||
end
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
require 'net/http'
|
||||
|
||||
HOST = "http://127.0.0.1:#{OSRM_PORT}"
|
||||
|
||||
def request_post_url service, param_string
|
||||
uri = URI.parse"#{HOST}/#{service}"
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
params = {}
|
||||
values = param_string.split("loc=")
|
||||
locs = []
|
||||
values.each do |value|
|
||||
locs << "#{value}".gsub(/[&]/, '')
|
||||
end
|
||||
locs.reject! { |c| c.empty? }
|
||||
params.merge!(loc: locs)
|
||||
Net::HTTP.post_form uri, params
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
rescue Timeout::Error
|
||||
raise "*** osrm-routed did not respond."
|
||||
end
|
||||
@@ -15,10 +15,28 @@ def request_path path, waypoints=[], options={}
|
||||
locs = waypoints.compact.map { |w| "loc=#{w.lat},#{w.lon}" }
|
||||
params = (locs + options.to_param).join('&')
|
||||
params = nil if params==""
|
||||
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
||||
|
||||
if options.has_key?("post")
|
||||
request_method = "POST"
|
||||
options.delete("post")
|
||||
else
|
||||
request_method = "GET"
|
||||
end
|
||||
if request_method.eql? "GET"
|
||||
uri = URI.parse ["#{HOST}/#{path}", params].compact.join('?')
|
||||
elsif request_method.eql? "POST"
|
||||
uri = URI.parse "#{HOST}/#{path}"
|
||||
end
|
||||
@query = uri.to_s
|
||||
Timeout.timeout(OSRM_TIMEOUT) do
|
||||
Net::HTTP.get_response uri
|
||||
if request_method.eql? "GET"
|
||||
Net::HTTP.get_response uri
|
||||
elsif request_method.eql? "POST"
|
||||
datas = {}
|
||||
datas[:loc] = waypoints.compact.map { |w| "#{w.lat},#{w.lon}" }
|
||||
datas.merge! options
|
||||
Net::HTTP.post_form uri, datas
|
||||
end
|
||||
end
|
||||
rescue Errno::ECONNREFUSED => e
|
||||
raise "*** osrm-routed is not running."
|
||||
|
||||
Reference in New Issue
Block a user