osrm_api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 238aeb1689da90fbecf6c1af2deba2058d5e1745
4
- data.tar.gz: bbb3387c67f31b68b7771f1c5acea7c71d7ded9c
3
+ metadata.gz: a102047d344d59c5fe684fc9e3d6c48774f49a0c
4
+ data.tar.gz: 0fe7b46ef8d7736fb528b9952479b8d85850abd0
5
5
  SHA512:
6
- metadata.gz: 6744e8a869f4bdf3108d6c03cf59a3f6d6dbbf0d5711d4dfafc30f2e861ef86065ae74fbd4fb2294c5a026668c731f2dd016e8a35ba26a8428c60951173d6182
7
- data.tar.gz: 10afa72994fbb1c4afd0ae2231af01ca46f530ee9b4c647d1e2f7a365bbf6ceb37814a818f74bdf7cc242f22b46c86f5bfcae5cc20ee0449825e536893133fed
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 )
@@ -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
 
@@ -1,4 +1,4 @@
1
1
  # :nodoc
2
2
  module OSRM
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
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
- TEST_HOST = 'example.com'
19
- QUERY_STRING = 'locate?loc=12.12,-12.12'
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.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: '0'
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: '0'
96
+ version: 1.8.11
97
97
  requirements: []
98
98
  rubyforge_project:
99
99
  rubygems_version: 2.4.5