osrm_api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/script.rb +5 -0
- data/lib/osrm_api/client.rb +69 -0
- data/lib/osrm_api/request/base_request.rb +43 -0
- data/lib/osrm_api/request/distance_request.rb +16 -0
- data/lib/osrm_api/request/locate_request.rb +16 -0
- data/lib/osrm_api/request/nearest_request.rb +16 -0
- data/lib/osrm_api/request/route_request.rb +28 -0
- data/lib/osrm_api/response/base_object.rb +19 -0
- data/lib/osrm_api/response/distance_object.rb +16 -0
- data/lib/osrm_api/response/locate_object.rb +18 -0
- data/lib/osrm_api/response/nearest_object.rb +16 -0
- data/lib/osrm_api/response/route_object.rb +20 -0
- data/lib/osrm_api/version.rb +4 -0
- data/lib/osrm_api.rb +6 -0
- data/osrm_api.gemspec +23 -0
- data/spec/fixtures/distance.json +12 -0
- data/spec/fixtures/invalid_route.json +53 -0
- data/spec/fixtures/nearest.json +8 -0
- data/spec/fixtures/route.json +54 -0
- data/spec/osrm_api/client_spec.rb +26 -0
- data/spec/osrm_api/request/route_request_spec.rb +26 -0
- data/spec/osrm_api/response/distance_object_spec.rb +13 -0
- data/spec/osrm_api/response/nearest_object_spec.rb +12 -0
- data/spec/osrm_api/response/route_object_spec.rb +18 -0
- data/spec/spec_helper.rb +21 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 238aeb1689da90fbecf6c1af2deba2058d5e1745
|
4
|
+
data.tar.gz: bbb3387c67f31b68b7771f1c5acea7c71d7ded9c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6744e8a869f4bdf3108d6c03cf59a3f6d6dbbf0d5711d4dfafc30f2e861ef86065ae74fbd4fb2294c5a026668c731f2dd016e8a35ba26a8428c60951173d6182
|
7
|
+
data.tar.gz: 10afa72994fbb1c4afd0ae2231af01ca46f530ee9b4c647d1e2f7a365bbf6ceb37814a818f74bdf7cc242f22b46c86f5bfcae5cc20ee0449825e536893133fed
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 IgorPetuh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# OsrmApi
|
2
|
+
|
3
|
+
This Gem provides interaction with [OSRM Server API](https://github.com/Project-OSRM/osrm-backend/wiki/Server-api)
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'osrm_api'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install osrm_api
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'osrm_api'
|
26
|
+
|
27
|
+
# Initialize the client.
|
28
|
+
client = OSRM::Client.new(host: 'example.com', port: 5000)
|
29
|
+
|
30
|
+
# Perform the request
|
31
|
+
distance = client.distance('40.723279,-73.937766', '40.90,-73.10', '40.82279,-73.937766')
|
32
|
+
route = client.route('40.723279,-73.937766', '40.90,-73.10', '40.823279,-73.937766')
|
33
|
+
locate = client.locate('53.911808, 27.595035')
|
34
|
+
nearest = client.nearest('53.911808, 27.595035')
|
35
|
+
```
|
36
|
+
### Response
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/ikantam/osrm-api/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/script.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'osrm_api/request/route_request'
|
5
|
+
require 'osrm_api/response/route_object'
|
6
|
+
|
7
|
+
require 'osrm_api/request/locate_request'
|
8
|
+
require 'osrm_api/response/locate_object'
|
9
|
+
|
10
|
+
require 'osrm_api/request/distance_request'
|
11
|
+
require 'osrm_api/response/distance_object'
|
12
|
+
|
13
|
+
require 'osrm_api/request/nearest_request'
|
14
|
+
require 'osrm_api/response/nearest_object'
|
15
|
+
|
16
|
+
module OSRM
|
17
|
+
# :nodoc
|
18
|
+
class Client
|
19
|
+
DEFAULT_OPTIONS = {
|
20
|
+
host: 'localhost',
|
21
|
+
port: 5000
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
# @return [OSRM::Client]
|
25
|
+
def initialize(options = {})
|
26
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Response::LocateObject]
|
30
|
+
def locate(location)
|
31
|
+
request = Request::LocateRequest.new(location)
|
32
|
+
yield if block_given?
|
33
|
+
Response::LocateObject.new execute request
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Response::RouteObject]
|
37
|
+
def route(*locations)
|
38
|
+
request = Request::RouteRequest.new(*locations)
|
39
|
+
yield if block_given?
|
40
|
+
Response::RouteObject.new execute request
|
41
|
+
end
|
42
|
+
|
43
|
+
# @return [Response::NearestObject]
|
44
|
+
def nearest(location)
|
45
|
+
request = Request::NearestRequest.new(location)
|
46
|
+
yield if block_given?
|
47
|
+
Response::NearestObject.new execute request
|
48
|
+
end
|
49
|
+
|
50
|
+
# Return casting <Response::DistanceObject>
|
51
|
+
# @param [Array] locations
|
52
|
+
# @return [Response::DistanceObject]
|
53
|
+
def distance(*locations)
|
54
|
+
request = Request::DistanceRequest.new(*locations)
|
55
|
+
yield if block_given?
|
56
|
+
Response::DistanceObject.new execute request
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Method performs given request and returns body response
|
62
|
+
# @param [OSRM::Request::BaseRequest] request
|
63
|
+
def execute(request)
|
64
|
+
uri = request.build_uri @options[:host], @options[:port]
|
65
|
+
res = Net::HTTP.get_response uri
|
66
|
+
JSON.parse(res.body)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'uri/https'
|
2
|
+
module OSRM
|
3
|
+
module Request
|
4
|
+
# :nodoc
|
5
|
+
class BaseRequest
|
6
|
+
LOC_PARAM = :loc
|
7
|
+
|
8
|
+
# Contains service path
|
9
|
+
# @return [Symbol]
|
10
|
+
def service
|
11
|
+
fail 'Specify the PATH to the Service'
|
12
|
+
end
|
13
|
+
|
14
|
+
# Contains default parameters for specially API request
|
15
|
+
# @return [Hash]
|
16
|
+
def default_params
|
17
|
+
@default_params ||= {}
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Array]
|
21
|
+
def params
|
22
|
+
@params ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_param(key, value)
|
26
|
+
params << [key, value]
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [String] host
|
30
|
+
# @param [Fixnum] port
|
31
|
+
# @return [URI]
|
32
|
+
def build_uri(host, port)
|
33
|
+
URI::HTTP.build(
|
34
|
+
host: host,
|
35
|
+
port: port.to_i,
|
36
|
+
path: "/#{service}",
|
37
|
+
query: URI.encode_www_form(params +
|
38
|
+
default_params.map { |key, item| [key, item] })
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'osrm_api/request/base_request'
|
2
|
+
module OSRM
|
3
|
+
module Request
|
4
|
+
# :nodoc
|
5
|
+
class DistanceRequest < BaseRequest
|
6
|
+
def initialize(*locations)
|
7
|
+
locations = locations.compact.reject(&:empty?)
|
8
|
+
locations.each { |item| add_param LOC_PARAM, item.split.join }
|
9
|
+
end
|
10
|
+
|
11
|
+
def service
|
12
|
+
:table
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'osrm_api/request/base_request'
|
2
|
+
|
3
|
+
module OSRM
|
4
|
+
module Request
|
5
|
+
# :nodoc
|
6
|
+
class LocateRequest < BaseRequest
|
7
|
+
def initialize(location)
|
8
|
+
add_param LOC_PARAM, location.split.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def service
|
12
|
+
:locate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'osrm_api/request/base_request'
|
2
|
+
|
3
|
+
module OSRM
|
4
|
+
module Request
|
5
|
+
# :nodoc
|
6
|
+
class NearestRequest < BaseRequest
|
7
|
+
def initialize(location)
|
8
|
+
add_param LOC_PARAM, location.split.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def service
|
12
|
+
:nearest
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'osrm_api/request/base_request'
|
2
|
+
module OSRM
|
3
|
+
module Request
|
4
|
+
# :nodoc
|
5
|
+
class RouteRequest < BaseRequest
|
6
|
+
OUTPUT_PARAM = :output
|
7
|
+
ALT_PARAM = :alt
|
8
|
+
Z_PARAM = :z
|
9
|
+
GEO_PARAM = :geometry
|
10
|
+
|
11
|
+
def service
|
12
|
+
:viaroute
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_params
|
16
|
+
@default_params ||= {
|
17
|
+
OUTPUT_PARAM => :json,
|
18
|
+
ALT_PARAM => :false
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(*locations)
|
23
|
+
locations = locations.compact.reject(&:empty?)
|
24
|
+
locations.each { |item| add_param LOC_PARAM, item.split.join }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module OSRM
|
2
|
+
module Response
|
3
|
+
# :nodoc
|
4
|
+
class BaseObject
|
5
|
+
attr_accessor :origin_response
|
6
|
+
|
7
|
+
def initialize(json)
|
8
|
+
@origin_response = json.freeze
|
9
|
+
cast
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def cast
|
15
|
+
fail 'Method should be implemented'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'osrm_api/response/base_object'
|
2
|
+
|
3
|
+
module OSRM
|
4
|
+
module Response
|
5
|
+
# :nodoc
|
6
|
+
class DistanceObject < BaseObject
|
7
|
+
attr_reader :distance_table
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def cast
|
12
|
+
@distance_table = @origin_response['distance_table']
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'osrm_api/response/base_object'
|
2
|
+
|
3
|
+
module OSRM
|
4
|
+
module Response
|
5
|
+
# :nodoc
|
6
|
+
class LocateObject < BaseObject
|
7
|
+
attr_reader :lat, :lon
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def cast
|
12
|
+
return unless @origin_response['status'] == 0
|
13
|
+
@lat, @lon = @origin_response['mapped_coordinate']
|
14
|
+
yield if block_given?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'osrm_api/response/base_object'
|
2
|
+
|
3
|
+
module OSRM
|
4
|
+
module Response
|
5
|
+
# :nodoc
|
6
|
+
class RouteObject < BaseObject
|
7
|
+
attr_reader :geometry, :summary, :instructions, :name
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def cast
|
12
|
+
return unless @origin_response['status'] == 0
|
13
|
+
@geometry = @origin_response['route_geometry']
|
14
|
+
@summary = @origin_response['route_summary']
|
15
|
+
@name = @origin_response['route_name']
|
16
|
+
@instructions = @origin_response['route_instructions']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/osrm_api.rb
ADDED
data/osrm_api.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'osrm_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'osrm_api'
|
8
|
+
spec.version = OSRM::VERSION
|
9
|
+
spec.authors = ['IgorPetuh']
|
10
|
+
spec.email = ['i.petuh@icloud.com']
|
11
|
+
spec.summary = 'OSRM API'
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://github.com/ikantam/osrm-api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
{
|
2
|
+
"hint_data": {
|
3
|
+
"locations": [
|
4
|
+
"wQ0NACgfGAAAAAAABQAAAAAAAAA5AAAAAAAAAOCbCAAAAAAATrJyAoeHt_sDABEA",
|
5
|
+
"hjYYAIg2GADefQEAAAAAALMAAAAAAAAAZAgAAFMNDAAAAAAA-bJqAiTnl_sAABEA"
|
6
|
+
],
|
7
|
+
"checksum": 361082431
|
8
|
+
},
|
9
|
+
"status_message": "Found route between points",
|
10
|
+
"route_summary": {
|
11
|
+
"end_point": "Fishermem's Way",
|
12
|
+
"start_point": "",
|
13
|
+
"total_time": 9572,
|
14
|
+
"total_distance": 193078
|
15
|
+
},
|
16
|
+
"found_alternative": true,
|
17
|
+
"alternative_summaries": [
|
18
|
+
{
|
19
|
+
"end_point": "Fishermem's Way",
|
20
|
+
"start_point": "",
|
21
|
+
"total_time": 10015,
|
22
|
+
"total_distance": 206532
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"via_points": [
|
26
|
+
[
|
27
|
+
41.071182,
|
28
|
+
-71.858299
|
29
|
+
],
|
30
|
+
[
|
31
|
+
40.547066,
|
32
|
+
-73.930977
|
33
|
+
]
|
34
|
+
],
|
35
|
+
"via_indices": [
|
36
|
+
0,
|
37
|
+
2173
|
38
|
+
],
|
39
|
+
"alternative_indices": [
|
40
|
+
0,
|
41
|
+
2407
|
42
|
+
],
|
43
|
+
"alternative_names": [
|
44
|
+
[
|
45
|
+
"",
|
46
|
+
""
|
47
|
+
]
|
48
|
+
],
|
49
|
+
"route_name": [
|
50
|
+
"",
|
51
|
+
""
|
52
|
+
]
|
53
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"hint_data": {
|
3
|
+
"locations": [
|
4
|
+
"wQ0NACgfGAAAAAAABQAAAAAAAAA5AAAAAAAAAOCbCAAAAAAATrJyAoeHt_sDABEA",
|
5
|
+
"hjYYAIg2GADefQEAAAAAALMAAAAAAAAAZAgAAFMNDAAAAAAA-bJqAiTnl_sAABEA"
|
6
|
+
],
|
7
|
+
"checksum": 361082431
|
8
|
+
},
|
9
|
+
"status_message": "Found route between points",
|
10
|
+
"route_summary": {
|
11
|
+
"end_point": "Fishermem's Way",
|
12
|
+
"start_point": "",
|
13
|
+
"total_time": 9572,
|
14
|
+
"total_distance": 193078
|
15
|
+
},
|
16
|
+
"found_alternative": true,
|
17
|
+
"alternative_summaries": [
|
18
|
+
{
|
19
|
+
"end_point": "Fishermem's Way",
|
20
|
+
"start_point": "",
|
21
|
+
"total_time": 10015,
|
22
|
+
"total_distance": 206532
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"via_points": [
|
26
|
+
[
|
27
|
+
41.071182,
|
28
|
+
-71.858299
|
29
|
+
],
|
30
|
+
[
|
31
|
+
40.547066,
|
32
|
+
-73.930977
|
33
|
+
]
|
34
|
+
],
|
35
|
+
"status": 0,
|
36
|
+
"via_indices": [
|
37
|
+
0,
|
38
|
+
2173
|
39
|
+
],
|
40
|
+
"alternative_indices": [
|
41
|
+
0,
|
42
|
+
2407
|
43
|
+
],
|
44
|
+
"alternative_names": [
|
45
|
+
[
|
46
|
+
"",
|
47
|
+
""
|
48
|
+
]
|
49
|
+
],
|
50
|
+
"route_name": [
|
51
|
+
"",
|
52
|
+
""
|
53
|
+
]
|
54
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec'
|
3
|
+
require 'osrm_api'
|
4
|
+
|
5
|
+
describe OSRM::Client do
|
6
|
+
subject(:factory) { described_class }
|
7
|
+
|
8
|
+
describe '#Instantiate object' do
|
9
|
+
WebMock.disable!
|
10
|
+
it '#with invalid params' do
|
11
|
+
obj = factory.new(host: 'bla-bla-bla')
|
12
|
+
expect { obj.route('12.12,-12.1', '123.1,-34.1') }
|
13
|
+
.to raise_error(SocketError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#with correct' do
|
17
|
+
WebMock.enable!
|
18
|
+
TEST_HOST = 'example.com'
|
19
|
+
QUERY_STRING = 'locate?loc=12.12,-12.12'
|
20
|
+
stub_request(:any, 'http://' + TEST_HOST + ':5000/' + QUERY_STRING)
|
21
|
+
.to_return(body: JSON.generate(status: 0, mapped_coordinate: [1, 2]))
|
22
|
+
obj = factory.new(host: TEST_HOST)
|
23
|
+
expect(obj.locate('12.12, -12.12')).to_not eq(nil)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe OSRM::Request::RouteRequest do
|
5
|
+
subject(:factory) { described_class }
|
6
|
+
HOST = 'ex.com'
|
7
|
+
PORT = 5000
|
8
|
+
|
9
|
+
it 'should contain service' do
|
10
|
+
obj = factory.new('')
|
11
|
+
expect(obj.service.length).not_to eq(0)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should build correct query' do
|
15
|
+
obj = factory.new('12.12,-12.12', '13.13,-13.13')
|
16
|
+
uri = obj.build_uri(HOST, PORT)
|
17
|
+
expect(URI.decode(uri.query).include?('loc=12.12,-12.12&loc=13.13,-13.13')).to eq(true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should can edit default params' do
|
21
|
+
obj = factory.new('12.12,-12.12', '-13.13,13.12')
|
22
|
+
obj.default_params[:z] = 'z'
|
23
|
+
uri = obj.build_uri(HOST, PORT)
|
24
|
+
expect(URI.decode(uri.query).include?('z=z')).to eq(true)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe OSRM::Response::DistanceObject do
|
5
|
+
subject(:factory) { described_class }
|
6
|
+
describe '#Instantiate' do
|
7
|
+
it 'should contain distance array' do
|
8
|
+
json = JSON.parse(fixture('distance.json').read)
|
9
|
+
obj = factory.new json
|
10
|
+
expect(obj.distance_table).to eq(json['distance_table'])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
describe OSRM::Response::NearestObject do
|
4
|
+
subject(:factory) { described_class }
|
5
|
+
describe '#Instantiate' do
|
6
|
+
it '#with valid params' do
|
7
|
+
json = JSON.parse(fixture('nearest.json'))
|
8
|
+
obj = factory.new json
|
9
|
+
expect(obj.name).to eq(json['name'])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe OSRM::Response::RouteObject do
|
5
|
+
subject(:factory) { described_class }
|
6
|
+
|
7
|
+
describe '#Instantiate' do
|
8
|
+
it '#with valid params' do
|
9
|
+
obj = factory.new JSON.parse(fixture('route.json').read)
|
10
|
+
expect(obj.summary.class).to eq(Hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it '#with invalid params' do
|
14
|
+
obj = factory.new JSON.parse(fixture('invalid_route.json').read)
|
15
|
+
expect(obj.summary.class).to eq(NilClass)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
2
|
+
$LOAD_PATH.uniq!
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'json'
|
7
|
+
require 'osrm_api'
|
8
|
+
|
9
|
+
def fixture_path
|
10
|
+
File.expand_path('../fixtures', __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fixture(file)
|
14
|
+
File.new(File.join(fixture_path, '/', file))
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.color = true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
config.raise_errors_for_deprecations!
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osrm_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IgorPetuh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- i.petuh@icloud.com
|
44
|
+
executables:
|
45
|
+
- script.rb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/script.rb
|
55
|
+
- lib/osrm_api.rb
|
56
|
+
- lib/osrm_api/client.rb
|
57
|
+
- lib/osrm_api/request/base_request.rb
|
58
|
+
- lib/osrm_api/request/distance_request.rb
|
59
|
+
- lib/osrm_api/request/locate_request.rb
|
60
|
+
- lib/osrm_api/request/nearest_request.rb
|
61
|
+
- lib/osrm_api/request/route_request.rb
|
62
|
+
- lib/osrm_api/response/base_object.rb
|
63
|
+
- lib/osrm_api/response/distance_object.rb
|
64
|
+
- lib/osrm_api/response/locate_object.rb
|
65
|
+
- lib/osrm_api/response/nearest_object.rb
|
66
|
+
- lib/osrm_api/response/route_object.rb
|
67
|
+
- lib/osrm_api/version.rb
|
68
|
+
- osrm_api.gemspec
|
69
|
+
- spec/fixtures/distance.json
|
70
|
+
- spec/fixtures/invalid_route.json
|
71
|
+
- spec/fixtures/nearest.json
|
72
|
+
- spec/fixtures/route.json
|
73
|
+
- spec/osrm_api/client_spec.rb
|
74
|
+
- spec/osrm_api/request/route_request_spec.rb
|
75
|
+
- spec/osrm_api/response/distance_object_spec.rb
|
76
|
+
- spec/osrm_api/response/nearest_object_spec.rb
|
77
|
+
- spec/osrm_api/response/route_object_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: https://github.com/ikantam/osrm-api
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.5
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: OSRM API
|
103
|
+
test_files:
|
104
|
+
- spec/fixtures/distance.json
|
105
|
+
- spec/fixtures/invalid_route.json
|
106
|
+
- spec/fixtures/nearest.json
|
107
|
+
- spec/fixtures/route.json
|
108
|
+
- spec/osrm_api/client_spec.rb
|
109
|
+
- spec/osrm_api/request/route_request_spec.rb
|
110
|
+
- spec/osrm_api/response/distance_object_spec.rb
|
111
|
+
- spec/osrm_api/response/nearest_object_spec.rb
|
112
|
+
- spec/osrm_api/response/route_object_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
has_rdoc:
|