google_distance_matrix 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/README.md +76 -62
- data/lib/google_distance_matrix/configuration.rb +1 -1
- data/lib/google_distance_matrix/version.rb +1 -1
- data/spec/lib/google_distance_matrix/configuration_spec.rb +1 -1
- data/spec/lib/google_distance_matrix/url_builder_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bafa7129b5e8795d2843bf132729e31ac07079e
|
4
|
+
data.tar.gz: ee670023245891199fe478f084b58b1e984ae7b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b407618b92520edcc3a84199f5ab27e9db91598fb8c6e51b851379e6b4fb82f4d2fabe783eed065f4ba3a51ccc3a81abd4b99759546ae77e82ec49efccf954f8
|
7
|
+
data.tar.gz: cffa738e7f599684a5107755d0945924c229dedc320daa14b5cc71f70079409f572fdff199ed04f43a12889ff603df860e9ee04340cf649a058c08fec42d7647
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/Skalar/google_distance_matrix.svg?branch=master)](https://travis-ci.org/Skalar/google_distance_matrix)
|
4
4
|
|
5
|
-
Ruby client for
|
5
|
+
Ruby client for the [Google Distance Matrix API](https://developers.google.com/maps/documentation/distance-matrix/intro).
|
6
6
|
|
7
7
|
This lib makes Google's distance matrix API easy to work with,
|
8
8
|
allowing you to set up some origins and destinations and
|
@@ -12,7 +12,7 @@ Once you have the matrix you can fetch all routes from a given
|
|
12
12
|
origin or to a given destination.
|
13
13
|
|
14
14
|
The matrix may also be used as a data set for traveling salesman problem,
|
15
|
-
but to solve it you may look at http://ai4r.org
|
15
|
+
but to solve it you may look at <http://ai4r.org/>.
|
16
16
|
|
17
17
|
|
18
18
|
|
@@ -21,72 +21,87 @@ but to solve it you may look at http://ai4r.org/.
|
|
21
21
|
|
22
22
|
### Set up a matrix to work with
|
23
23
|
|
24
|
-
|
24
|
+
```ruby
|
25
|
+
matrix = GoogleDistanceMatrix::Matrix.new
|
26
|
+
```
|
25
27
|
|
26
28
|
### Create some places to be used as origins or destinations for the matrix
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
```ruby
|
30
|
+
lat_lng = GoogleDistanceMatrix::Place.new lng: 12, lat: 12
|
31
|
+
address = GoogleDistanceMatrix::Place.new address: "My address, Oslo"
|
32
|
+
dest_address = GoogleDistanceMatrix::Place.new address: "Home, Oppegaard"
|
33
|
+
|
34
|
+
# Just an example of an object responding to lat & lng.
|
35
|
+
# Point class isn't included in this gem, but feel free to
|
36
|
+
# create your own point class or use something like https://github.com/nofxx/georuby
|
37
|
+
point_dest = Point.new lat: 1, lng: 2
|
38
|
+
dest_object = GoogleDistanceMatrix::Place.new point_dest
|
39
|
+
```
|
35
40
|
### Add places to matrix's origins and destinations
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
```ruby
|
42
|
+
matrix.origins << lat_lng << address
|
43
|
+
matrix.destinations << dest_address << dest_object
|
44
|
+
|
45
|
+
# Added objects will be wrapped in a place automatically, so you may skip manyally creating Places.
|
46
|
+
another_point = Point.new lat: 1, lng: 3
|
47
|
+
matrix.origins << another_point
|
48
|
+
```
|
44
49
|
### Do some configuration - see GoogleDistanceMatrix.configure_defaults as well.
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
```ruby
|
51
|
+
matrix.configure do |config|
|
52
|
+
config.mode = 'driving'
|
53
|
+
config.avoid = ['tolls']
|
54
|
+
|
55
|
+
# To build signed URLs to use with a Google Business account.
|
56
|
+
config.google_business_api_client_id = "123"
|
57
|
+
config.google_business_api_private_key = "your-secret-key"
|
58
|
+
|
59
|
+
# If you have an API key, you can specify that as well.
|
60
|
+
config.google_api_key = "YOUR_API_KEY"
|
61
|
+
end
|
62
|
+
```
|
55
63
|
### Get the data for the matrix
|
56
64
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
matrix.data
|
65
|
+
`matrix.data` returns the data, loaded from Google, for this matrix.
|
66
|
+
|
67
|
+
It is a multi dimensional array. Rows are ordered according to the values in the origins.
|
68
|
+
Each row corresponds to an origin, and each element within that row corresponds to a pairing of the origin with a destination.
|
62
69
|
|
63
|
-
### Query the matrix
|
64
70
|
|
65
|
-
|
66
|
-
matrix.routes_for dest_address
|
71
|
+
### Query the matrix
|
67
72
|
|
68
|
-
|
69
|
-
matrix.route_for origin: lat_lng, destination: dest_address
|
73
|
+
Returns an array of Google::DistanceMatrix::Route, all having given origin or destination.
|
70
74
|
|
71
|
-
|
72
|
-
|
75
|
+
```ruby
|
76
|
+
matrix.routes_for dest_address
|
77
|
+
```
|
73
78
|
|
74
|
-
|
75
|
-
# as well asking for routes. This is true for route_for and shortest_route_by_* as well.
|
76
|
-
matrix.routes_for point_dest # Returns routes for dest_object
|
79
|
+
Returns Google::DistanceMatrix::Route with given origin and destination
|
77
80
|
|
78
|
-
|
81
|
+
```ruby
|
82
|
+
matrix.route_for origin: lat_lng, destination: dest_address
|
83
|
+
# Google::DistanceMatrix::Route with one origin and a destination, together with route data
|
84
|
+
matrix.shortest_route_by_distance_to(dest_address)
|
85
|
+
# Google::DistanceMatrix::Route with one origin and a destination, together with route data
|
86
|
+
matrix.shortest_route_by_duration_to(dest_address)
|
87
|
+
```
|
79
88
|
|
89
|
+
In cases where you built the place with an object (not hash with attributes) you may provide that object as well asking for routes. This is true for `route_for` and `shortest_route_by_*` as well.
|
80
90
|
|
91
|
+
```ruby
|
92
|
+
matrix.routes_for point_dest # Returns routes for dest_object
|
93
|
+
```
|
81
94
|
|
95
|
+
You may call query methods with a bang, in which case it will fail with an error if not all of the routes in your result set for the called method are ok.
|
82
96
|
|
83
97
|
|
84
98
|
## Installation
|
85
99
|
|
86
100
|
Add this line to your application's Gemfile:
|
87
101
|
|
88
|
-
|
89
|
-
|
102
|
+
```ruby
|
103
|
+
gem 'google_distance_matrix'
|
104
|
+
```
|
90
105
|
And then execute:
|
91
106
|
|
92
107
|
$ bundle
|
@@ -96,26 +111,25 @@ Or install it yourself as:
|
|
96
111
|
$ gem install google_distance_matrix
|
97
112
|
|
98
113
|
|
99
|
-
|
100
|
-
|
101
114
|
## Configuration
|
102
115
|
|
103
|
-
|
104
|
-
|
105
|
-
|
116
|
+
Configuration is done directly on a matrix or via `GoogleDistanceMatrix.configure_defaults`.
|
117
|
+
Apart from configuration on requests it is also possible to provide your own logger class and
|
118
|
+
set a cache.
|
106
119
|
|
107
120
|
### Request cache
|
108
121
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
122
|
+
Given Google's limit to the service you may have the need to cache requests. This is done by simply
|
123
|
+
using URL as cache keys. Cache we'll accept should provide a default ActiveSupport::Cache::Store interface.
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
GoogleDistanceMatrix.configure_defaults do |config|
|
127
|
+
config.cache = ActiveSupport::Cache.lookup_store :your_store, {
|
128
|
+
expires_in: 12.hours
|
129
|
+
# ..or other options you like for your store
|
130
|
+
}
|
131
|
+
end
|
132
|
+
```
|
119
133
|
|
120
134
|
|
121
135
|
## Contributing
|
@@ -77,7 +77,7 @@ describe GoogleDistanceMatrix::Configuration do
|
|
77
77
|
it { expect(subject.avoid).to be_nil }
|
78
78
|
it { expect(subject.units).to eq "metric" }
|
79
79
|
it { expect(subject.lat_lng_scale).to eq 5 }
|
80
|
-
it { expect(subject.protocol).to eq '
|
80
|
+
it { expect(subject.protocol).to eq 'https' }
|
81
81
|
it { expect(subject.language).to be_nil }
|
82
82
|
|
83
83
|
it { expect(subject.departure_time).to be_nil }
|
@@ -53,12 +53,12 @@ describe GoogleDistanceMatrix::UrlBuilder do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "starts with the base URL" do
|
56
|
-
expect(subject.url).to start_with "
|
56
|
+
expect(subject.url).to start_with "https://" + described_class::BASE_URL
|
57
57
|
end
|
58
58
|
|
59
59
|
it "has a configurable protocol" do
|
60
|
-
matrix.configure { |c| c.protocol = "
|
61
|
-
expect(subject.url).to start_with "
|
60
|
+
matrix.configure { |c| c.protocol = "http" }
|
61
|
+
expect(subject.url).to start_with "http://"
|
62
62
|
end
|
63
63
|
|
64
64
|
it "includes origins" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_distance_matrix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thorbjørn Hermansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|