osrm_api 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +37 -0
- data/lib/osrm_api/client.rb +4 -4
- data/lib/osrm_api/version.rb +1 -1
- data/osrm_api.gemspec +2 -0
- data/spec/osrm_api/client_spec.rb +4 -4
- data/spec/osrm_api/response/nearest_object_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a102047d344d59c5fe684fc9e3d6c48774f49a0c
|
4
|
+
data.tar.gz: 0fe7b46ef8d7736fb528b9952479b8d85850abd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa44e3fb76385d4f639ebdeb88f48787b32f99bd704ae313499a7588161a477969d10983b6b322cfb175f6a0d482f3ac9e358fb458f633bf8f9322f09e8031b3
|
7
|
+
data.tar.gz: 80d7510320d118f28b38d42778793a50f1ef7cc1c6c4307a68750e82e9bd58dc2a300aa39180670e8ddb4a10db15be17b27f643e51d4b64b50cc1191c7e29eb8
|
data/README.md
CHANGED
@@ -33,8 +33,45 @@ route = client.route('40.723279,-73.937766', '40.90,-73.10', '40.823279,-73.9377
|
|
33
33
|
locate = client.locate('53.911808, 27.595035')
|
34
34
|
nearest = client.nearest('53.911808, 27.595035')
|
35
35
|
```
|
36
|
+
To connect any special settings it’s necessary to use block construction like the following one:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
route = client.route('40.723279,-73.937766', '40.90,-73.10') do |request|
|
40
|
+
request.add_param 'z', 7
|
41
|
+
end
|
42
|
+
```
|
36
43
|
### Response
|
37
44
|
|
45
|
+
There are 4 types of responses.
|
46
|
+
|
47
|
+
LocateObject extends base class.
|
48
|
+
There arise new property @lat and @lon which contain point position.
|
49
|
+
```ruby
|
50
|
+
lc = client.locate('40.723279,-73.9377')
|
51
|
+
lc.lat # => '40.723274'
|
52
|
+
lc.lon # => '-73.937408'
|
53
|
+
```
|
54
|
+
|
55
|
+
NearestObject extends Locate and adds new property @name, which contains the name of object on the map.
|
56
|
+
```ruby
|
57
|
+
nr = client.nearest('40.723279,-73.9377')
|
58
|
+
nr.lat # => '40.723274'
|
59
|
+
nr.lon # => '-73.937408'
|
60
|
+
nr.name # => 'Anthony Street'
|
61
|
+
```
|
62
|
+
|
63
|
+
DistanceObject contains in the @distance_table property the amount which reflects the distance between the points of the request.
|
64
|
+
```ruby
|
65
|
+
dc = client.distance('40.723279,-73.9377', '40.723279,-73.9877')
|
66
|
+
dc.distance_table # => [[0, 3551], [4116,0]]
|
67
|
+
```
|
68
|
+
|
69
|
+
RouteObject contains geometry, summary, instructions, name properties. If there is a necessity to get other properties of the route, you need to call to them via @orgin_response property of the parent class.
|
70
|
+
```ruby
|
71
|
+
rt = client.route('40.723279,-73.9377', '40.723279,-73.9877')
|
72
|
+
rt.summary['total_time'] # => 355
|
73
|
+
```
|
74
|
+
|
38
75
|
## Contributing
|
39
76
|
|
40
77
|
1. Fork it ( https://github.com/ikantam/osrm-api/fork )
|
data/lib/osrm_api/client.rb
CHANGED
@@ -29,21 +29,21 @@ module OSRM
|
|
29
29
|
# @return [Response::LocateObject]
|
30
30
|
def locate(location)
|
31
31
|
request = Request::LocateRequest.new(location)
|
32
|
-
yield if block_given?
|
32
|
+
request = yield request if block_given?
|
33
33
|
Response::LocateObject.new execute request
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [Response::RouteObject]
|
37
37
|
def route(*locations)
|
38
38
|
request = Request::RouteRequest.new(*locations)
|
39
|
-
yield if block_given?
|
39
|
+
yield request if block_given?
|
40
40
|
Response::RouteObject.new execute request
|
41
41
|
end
|
42
42
|
|
43
43
|
# @return [Response::NearestObject]
|
44
44
|
def nearest(location)
|
45
45
|
request = Request::NearestRequest.new(location)
|
46
|
-
yield if block_given?
|
46
|
+
yield request if block_given?
|
47
47
|
Response::NearestObject.new execute request
|
48
48
|
end
|
49
49
|
|
@@ -52,7 +52,7 @@ module OSRM
|
|
52
52
|
# @return [Response::DistanceObject]
|
53
53
|
def distance(*locations)
|
54
54
|
request = Request::DistanceRequest.new(*locations)
|
55
|
-
yield if block_given?
|
55
|
+
yield request if block_given?
|
56
56
|
Response::DistanceObject.new execute request
|
57
57
|
end
|
58
58
|
|
data/lib/osrm_api/version.rb
CHANGED
data/osrm_api.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
|
+
spec.required_rubygems_version = '>= 1.8.11'
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
25
|
end
|
@@ -3,11 +3,12 @@ require 'rspec'
|
|
3
3
|
require 'osrm_api'
|
4
4
|
|
5
5
|
describe OSRM::Client do
|
6
|
+
TEST_HOST = 'example.com'
|
6
7
|
subject(:factory) { described_class }
|
7
8
|
|
8
9
|
describe '#Instantiate object' do
|
9
|
-
WebMock.disable!
|
10
10
|
it '#with invalid params' do
|
11
|
+
WebMock.disable!
|
11
12
|
obj = factory.new(host: 'bla-bla-bla')
|
12
13
|
expect { obj.route('12.12,-12.1', '123.1,-34.1') }
|
13
14
|
.to raise_error(SocketError)
|
@@ -15,9 +16,8 @@ describe OSRM::Client do
|
|
15
16
|
|
16
17
|
it '#with correct' do
|
17
18
|
WebMock.enable!
|
18
|
-
|
19
|
-
|
20
|
-
stub_request(:any, 'http://' + TEST_HOST + ':5000/' + QUERY_STRING)
|
19
|
+
query_string = 'locate?loc=12.12,-12.12'
|
20
|
+
stub_request(:any, 'http://' + TEST_HOST + ':5000/' + query_string)
|
21
21
|
.to_return(body: JSON.generate(status: 0, mapped_coordinate: [1, 2]))
|
22
22
|
obj = factory.new(host: TEST_HOST)
|
23
23
|
expect(obj.locate('12.12, -12.12')).to_not eq(nil)
|
@@ -4,7 +4,7 @@ describe OSRM::Response::NearestObject do
|
|
4
4
|
subject(:factory) { described_class }
|
5
5
|
describe '#Instantiate' do
|
6
6
|
it '#with valid params' do
|
7
|
-
json = JSON.parse(fixture('nearest.json'))
|
7
|
+
json = JSON.parse(fixture('nearest.json').read)
|
8
8
|
obj = factory.new json
|
9
9
|
expect(obj.name).to eq(json['name'])
|
10
10
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osrm_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IgorPetuh
|
@@ -88,12 +88,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
version:
|
91
|
+
version: 2.0.0
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.8.11
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
99
|
rubygems_version: 2.4.5
|