-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1502 from agruss/develop
Accepting HTTP Post Request
- Loading branch information
Showing
11 changed files
with
237 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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_request uri, waypoints=[], options={}, timestamps=[] | ||
@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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
require 'net/http' | ||
|
||
def request_locate_url path | ||
def request_locate_url path, node | ||
@query = path | ||
uri = URI.parse "#{HOST}/#{path}" | ||
Timeout.timeout(OSRM_TIMEOUT) do | ||
Net::HTTP.get_response uri | ||
end | ||
rescue Errno::ECONNREFUSED => e | ||
raise "*** osrm-routed is not running." | ||
rescue Timeout::Error | ||
raise "*** osrm-routed did not respond." | ||
|
||
uri = generate_request_url path | ||
response = send_request uri, [node] | ||
end | ||
|
||
def request_locate a | ||
request_locate_url "locate?loc=#{a}" | ||
def request_locate node | ||
request_locate_url "locate?loc=#{node.lat},#{node.lon}", node | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
require 'net/http' | ||
|
||
def request_nearest_url path | ||
def request_nearest_url path, node | ||
@query = path | ||
uri = URI.parse "#{HOST}/#{path}" | ||
Timeout.timeout(OSRM_TIMEOUT) do | ||
Net::HTTP.get_response uri | ||
end | ||
rescue Errno::ECONNREFUSED => e | ||
raise "*** osrm-routed is not running." | ||
rescue Timeout::Error | ||
raise "*** osrm-routed did not respond." | ||
|
||
uri = generate_request_url path | ||
response = send_request uri, [node] | ||
end | ||
|
||
def request_nearest a | ||
request_nearest_url "nearest?loc=#{a}" | ||
def request_nearest node | ||
request_nearest_url "nearest?loc=#{node.lat},#{node.lon}", node | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
@post @testbot | ||
Feature: POST request | ||
|
||
Background: | ||
Given the profile "testbot" | ||
And the HTTP method "POST" | ||
|
||
Scenario: Testbot - viaroute POST request | ||
Given the node locations | ||
| node | lat | lon | | ||
| a | 55.68740 | 12.52430 | | ||
| b | 55.68745 | 12.52409 | | ||
| c | 55.68711 | 12.52383 | | ||
| x | -55.68740 | 12.52430 | | ||
| y | -55.68745 | 12.52409 | | ||
| z | -55.68711 | 12.52383 | | ||
|
||
And the ways | ||
| nodes | | ||
| ab | | ||
| bc | | ||
| xy | | ||
| yz | | ||
|
||
When I route I should get | ||
| from | to | route | turns | | ||
| a | c | ab,bc | head,left,destination | | ||
| c | a | bc,ab | head,right,destination | | ||
| x | z | xy,yz | head,right,destination | | ||
| z | x | yz,xy | head,left,destination | | ||
|
||
Scenario: Testbot - match POST request | ||
Given the node map | ||
| a | b | c | d | | ||
| e | f | g | h | | ||
|
||
And the ways | ||
| nodes | oneway | | ||
| abcd | yes | | ||
| hgfe | yes | | ||
|
||
When I match I should get | ||
| trace | matchings | | ||
| dcba | hgfe | | ||
|
||
Scenario: Testbot - table POST request | ||
Given the node map | ||
| x | a | b | y | | ||
| | d | e | | | ||
|
||
And the ways | ||
| nodes | oneway | | ||
| abeda | yes | | ||
| xa | | | ||
| by | | | ||
|
||
When I request a travel time matrix I should get | ||
| | x | y | d | e | | ||
| x | 0 | 300 | 400 | 300 | | ||
| y | 500 | 0 | 300 | 200 | | ||
| d | 200 | 300 | 0 | 300 | | ||
| e | 300 | 400 | 100 | 0 | | ||
|
||
Scenario: Testbot - locate POST request | ||
Given the node locations | ||
| node | lat | lon | | ||
| a | -85 | -180 | | ||
| b | 0 | 0 | | ||
| c | 85 | 180 | | ||
| x | -84 | -180 | | ||
| y | 84 | 180 | | ||
|
||
And the ways | ||
| nodes | | ||
| abc | | ||
|
||
When I request locate I should get | ||
| in | out | | ||
| x | a | | ||
| y | c | | ||
|
||
Scenario: Testbot - nearest POST request | ||
Given the node locations | ||
| node | lat | lon | | ||
| a | -85 | -180 | | ||
| b | -85 | -160 | | ||
| c | -85 | -140 | | ||
| x | -84.999 | -180 | | ||
| y | -84.999 | -160 | | ||
| z | -84.999 | -140 | | ||
|
||
And the ways | ||
| nodes | | ||
| abc | | ||
|
||
When I request nearest I should get | ||
| in | out | | ||
| x | a | | ||
| y | b | | ||
| z | c | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters