post/get handler added, background section for HTTP request
This commit is contained in:
parent
dce917eb74
commit
153d38f10c
@ -174,3 +174,7 @@ end
|
|||||||
Given /^data is loaded with datastore$/ do
|
Given /^data is loaded with datastore$/ do
|
||||||
@load_method = 'datastore'
|
@load_method = 'datastore'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given /^the HTTP method "([^"]*)"$/ do |method|
|
||||||
|
@http_method = method
|
||||||
|
end
|
||||||
|
@ -9,8 +9,7 @@ When /^I request locate I should get$/ do |table|
|
|||||||
out_node = find_node_by_name row['out']
|
out_node = find_node_by_name row['out']
|
||||||
raise "*** unknown out-node '#{row['out']}" unless out_node
|
raise "*** unknown out-node '#{row['out']}" unless out_node
|
||||||
|
|
||||||
params = @query_params
|
response = request_locate("#{in_node.lat},#{in_node.lon}")
|
||||||
response = request_locate("#{in_node.lat},#{in_node.lon}", params)
|
|
||||||
if response.code == "200" && response.body.empty? == false
|
if response.code == "200" && response.body.empty? == false
|
||||||
json = JSON.parse response.body
|
json = JSON.parse response.body
|
||||||
if json['status'] == 0
|
if json['status'] == 0
|
||||||
|
@ -9,8 +9,7 @@ When /^I request nearest I should get$/ do |table|
|
|||||||
out_node = find_node_by_name row['out']
|
out_node = find_node_by_name row['out']
|
||||||
raise "*** unknown out-node '#{row['out']}" unless out_node
|
raise "*** unknown out-node '#{row['out']}" unless out_node
|
||||||
|
|
||||||
params = @query_params
|
response = request_nearest("#{in_node.lat},#{in_node.lon}")
|
||||||
response = request_nearest("#{in_node.lat},#{in_node.lon}", params)
|
|
||||||
if response.code == "200" && response.body.empty? == false
|
if response.code == "200" && response.body.empty? == false
|
||||||
json = JSON.parse response.body
|
json = JSON.parse response.body
|
||||||
if json['status'] == 0
|
if json['status'] == 0
|
||||||
|
50
features/support/http.rb
Normal file
50
features/support/http.rb
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
require 'net/http'
|
||||||
|
|
||||||
|
def generate_request_url path
|
||||||
|
if @http_method.eql? "POST"
|
||||||
|
pos = path.index('?') - 1
|
||||||
|
service = path[0..pos]
|
||||||
|
uri = URI.parse "#{HOST}/#{service}"
|
||||||
|
else
|
||||||
|
uri = URI.parse "#{HOST}/#{path}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_simple_request uri, path
|
||||||
|
Timeout.timeout(OSRM_TIMEOUT) do
|
||||||
|
if @http_method.eql? "POST"
|
||||||
|
pos = path.index('=') + 1
|
||||||
|
path.slice!(0, pos)
|
||||||
|
response = Net::HTTP.post_form uri, "loc" => path
|
||||||
|
else
|
||||||
|
response = Net::HTTP.get_response uri
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Errno::ECONNREFUSED => e
|
||||||
|
raise "*** osrm-routed is not running."
|
||||||
|
rescue Timeout::Error
|
||||||
|
raise "*** osrm-routed did not respond."
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_request uri, waypoints, timestamps, options
|
||||||
|
@query = uri.to_s
|
||||||
|
Timeout.timeout(OSRM_TIMEOUT) do
|
||||||
|
if @http_method.eql? "POST"
|
||||||
|
datas = {}
|
||||||
|
if waypoints.length > 0
|
||||||
|
datas[:loc] = waypoints.compact.map { |w| "#{w.lat},#{w.lon}" }
|
||||||
|
end
|
||||||
|
if timestamps.length > 0
|
||||||
|
datas[:t] = timestamps.compact.map { |t| "#{t}" }
|
||||||
|
end
|
||||||
|
datas.merge! options
|
||||||
|
response = Net::HTTP.post_form uri, datas
|
||||||
|
else
|
||||||
|
response = Net::HTTP.get_response uri
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Errno::ECONNREFUSED => e
|
||||||
|
raise "*** osrm-routed is not running."
|
||||||
|
rescue Timeout::Error
|
||||||
|
raise "*** osrm-routed did not respond."
|
||||||
|
end
|
@ -1,32 +1,12 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
|
|
||||||
def request_locate_url path, method={}
|
def request_locate_url path
|
||||||
@query = path
|
@query = path
|
||||||
|
|
||||||
if method.has_key?("post")
|
uri = generate_request_url path
|
||||||
request_method = "POST"
|
response = send_simple_request uri, path
|
||||||
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
|
|
||||||
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."
|
|
||||||
rescue Timeout::Error
|
|
||||||
raise "*** osrm-routed did not respond."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_locate a, method
|
def request_locate a
|
||||||
request_locate_url "locate?loc=#{a}", method
|
request_locate_url "locate?loc=#{a}"
|
||||||
end
|
end
|
||||||
|
@ -14,34 +14,7 @@ def request_matching trace=[], timestamps=[], options={}
|
|||||||
params = (trace_params + defaults.merge(options).to_param).join('&')
|
params = (trace_params + defaults.merge(options).to_param).join('&')
|
||||||
params = nil if params==""
|
params = nil if params==""
|
||||||
|
|
||||||
if options.has_key?("post")
|
uri = generate_request_url ("match" + '?' + params)
|
||||||
request_method = "POST"
|
response = send_request uri, trace, timestamps, options
|
||||||
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
|
|
||||||
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."
|
|
||||||
rescue Timeout::Error
|
|
||||||
raise "*** osrm-routed did not respond."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,32 +1,12 @@
|
|||||||
require 'net/http'
|
require 'net/http'
|
||||||
|
|
||||||
def request_nearest_url path, method={}
|
def request_nearest_url path
|
||||||
@query = path
|
@query = path
|
||||||
|
|
||||||
if method.has_key?("post")
|
uri = generate_request_url path
|
||||||
request_method = "POST"
|
response = send_simple_request uri, path
|
||||||
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
|
|
||||||
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."
|
|
||||||
rescue Timeout::Error
|
|
||||||
raise "*** osrm-routed did not respond."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_nearest a, method
|
def request_nearest a
|
||||||
request_nearest_url "nearest?loc=#{a}", method
|
request_nearest_url "nearest?loc=#{a}"
|
||||||
end
|
end
|
||||||
|
@ -16,32 +16,12 @@ def request_path path, waypoints=[], options={}
|
|||||||
params = (locs + options.to_param).join('&')
|
params = (locs + options.to_param).join('&')
|
||||||
params = nil if params==""
|
params = nil if params==""
|
||||||
|
|
||||||
if options.has_key?("post")
|
if params == nil
|
||||||
request_method = "POST"
|
uri = generate_request_url (path)
|
||||||
options.delete("post")
|
|
||||||
else
|
else
|
||||||
request_method = "GET"
|
uri = generate_request_url (path + '?' + params)
|
||||||
end
|
end
|
||||||
if request_method.eql? "GET"
|
response = send_request uri, waypoints, {}, options
|
||||||
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
|
|
||||||
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."
|
|
||||||
rescue Timeout::Error
|
|
||||||
raise "*** osrm-routed did not respond."
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_url path
|
def request_url path
|
||||||
|
@ -3,6 +3,7 @@ Feature: POST request
|
|||||||
|
|
||||||
Background:
|
Background:
|
||||||
Given the profile "testbot"
|
Given the profile "testbot"
|
||||||
|
And the HTTP method "POST"
|
||||||
|
|
||||||
Scenario: Testbot - viaroute POST request
|
Scenario: Testbot - viaroute POST request
|
||||||
Given the node locations
|
Given the node locations
|
||||||
@ -21,9 +22,6 @@ Feature: POST request
|
|||||||
| xy |
|
| xy |
|
||||||
| yz |
|
| yz |
|
||||||
|
|
||||||
And the query options
|
|
||||||
| post | true |
|
|
||||||
|
|
||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | turns |
|
| from | to | route | turns |
|
||||||
| a | c | ab,bc | head,left,destination |
|
| a | c | ab,bc | head,left,destination |
|
||||||
@ -41,9 +39,6 @@ Feature: POST request
|
|||||||
| abcd | yes |
|
| abcd | yes |
|
||||||
| hgfe | yes |
|
| hgfe | yes |
|
||||||
|
|
||||||
And the query options
|
|
||||||
| post | true |
|
|
||||||
|
|
||||||
When I match I should get
|
When I match I should get
|
||||||
| trace | matchings |
|
| trace | matchings |
|
||||||
| dcba | hgfe |
|
| dcba | hgfe |
|
||||||
@ -59,9 +54,6 @@ Feature: POST request
|
|||||||
| xa | |
|
| xa | |
|
||||||
| by | |
|
| by | |
|
||||||
|
|
||||||
And the query options
|
|
||||||
| post | true |
|
|
||||||
|
|
||||||
When I request a travel time matrix I should get
|
When I request a travel time matrix I should get
|
||||||
| | x | y | d | e |
|
| | x | y | d | e |
|
||||||
| x | 0 | 300 | 400 | 300 |
|
| x | 0 | 300 | 400 | 300 |
|
||||||
@ -82,9 +74,6 @@ Feature: POST request
|
|||||||
| nodes |
|
| nodes |
|
||||||
| abc |
|
| abc |
|
||||||
|
|
||||||
And the query options
|
|
||||||
| post | true |
|
|
||||||
|
|
||||||
When I request locate I should get
|
When I request locate I should get
|
||||||
| in | out |
|
| in | out |
|
||||||
| x | a |
|
| x | a |
|
||||||
@ -104,9 +93,6 @@ Feature: POST request
|
|||||||
| nodes |
|
| nodes |
|
||||||
| abc |
|
| abc |
|
||||||
|
|
||||||
And the query options
|
|
||||||
| post | true |
|
|
||||||
|
|
||||||
When I request nearest I should get
|
When I request nearest I should get
|
||||||
| in | out |
|
| in | out |
|
||||||
| x | a |
|
| x | a |
|
||||||
|
Loading…
Reference in New Issue
Block a user