google_maps_api-distance_matrix 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/google_maps_api-distance_matrix.gemspec +25 -0
- data/lib/google_maps_api/distance_matrix.rb +16 -0
- data/lib/google_maps_api/distance_matrix/element.rb +17 -0
- data/lib/google_maps_api/distance_matrix/exceptions.rb +5 -0
- data/lib/google_maps_api/distance_matrix/request.rb +111 -0
- data/lib/google_maps_api/distance_matrix/response.rb +35 -0
- data/lib/google_maps_api/distance_matrix/row.rb +19 -0
- data/lib/google_maps_api/distance_matrix/version.rb +5 -0
- data/spec/google_maps_api/distance_matrix/element_spec.rb +14 -0
- data/spec/google_maps_api/distance_matrix/json_response.rb +6 -0
- data/spec/google_maps_api/distance_matrix/request_lets.rb +5 -0
- data/spec/google_maps_api/distance_matrix/request_spec.rb +52 -0
- data/spec/google_maps_api/distance_matrix/response_mock.json +50 -0
- data/spec/google_maps_api/distance_matrix/response_spec.rb +14 -0
- data/spec/google_maps_api/distance_matrix/row_spec.rb +14 -0
- data/spec/google_maps_api/distance_matrix_spec.rb +20 -0
- data/spec/spec_helper.rb +84 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8230528e95229d1d5ec58a06373c01a70cf0ac8
|
4
|
+
data.tar.gz: 224170ed2b98b2da3621aed0f2590a50b84b8185
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 420e1625564b28b2915f741f96934eb1dad6a23c30d117bfa12e3e4cbbf4411080bb885a7c7cd46dd7126f3f0a1a3fb4ab7f87cf6ea6e55e0e00447290c95e3e
|
7
|
+
data.tar.gz: 951feed3a3cdb0528a9e4d57c2f1bd3403e6ab2f7c5876721a51321e6907891611a46b9dbeb7de1e6f668f2370ec57096c6d9f138a9d02a72f9ce0f6c01d2bb9
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Felipe Zavan
|
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,62 @@
|
|
1
|
+
# GoogleMapsAPI::DistanceMatrix
|
2
|
+
|
3
|
+
This is a wrapper around the Google Maps Distance Matrix API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'google_maps_api-distance_matrix'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install google_maps_api-distance_matrix
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
GoogleMapsAPI::DistanceMatrix.calculate(origins, destinations, options = {})
|
23
|
+
```
|
24
|
+
|
25
|
+
Origins and destinations are arrays of strings or anything that supports ```to_ary```.
|
26
|
+
Options is a *Symbols* Hash with optional parameters. (See https://developers.google.com/maps/documentation/distancematrix/#RequestParameters for more information).
|
27
|
+
|
28
|
+
For Google Business/Enterprise requests, include the ```:key```, ```:client``` and optionally, ```:channel``` in the options hash.
|
29
|
+
|
30
|
+
### Examples:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
origins = ["350, 5th Ave, NY", "100, 56th St, NY", [40.764291, -73.979169], ...]
|
34
|
+
destinations = ["673, 45th St, NY", [40.763641,-73.987473], ...]
|
35
|
+
options = {:language => 'pt'}
|
36
|
+
GoogleMapsAPI::DistanceMatrix.calculate(origins, destinations, options)
|
37
|
+
# => #<GoogleMapsAPI::DistanceMatrix::Response:0x00000001f2b510...>
|
38
|
+
```
|
39
|
+
|
40
|
+
The ```GoogleMapsAPI::DistanceMatrix::Response``` object mimics the API JSON structure.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
I am new to Ruby and Testing. We need better specs.
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/zavan/google_maps_api-distance_matrix/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
51
|
+
|
52
|
+
### Important
|
53
|
+
|
54
|
+
* Do not touch the version;
|
55
|
+
* Write specs for new features;
|
56
|
+
* Be independent of Rails stuff;
|
57
|
+
* All specs must pass.
|
58
|
+
|
59
|
+
## Also see
|
60
|
+
|
61
|
+
* [http://github.com/zavan/google_maps_api-core](http://github.com/zavan/google_maps_api-core)
|
62
|
+
* [http://github.com/zavan/google_maps_api-directions](http://github.com/zavan/google_maps_api-directions)
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google_maps_api/distance_matrix/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google_maps_api-distance_matrix"
|
8
|
+
spec.version = GoogleMapsAPI::DistanceMatrix::VERSION
|
9
|
+
spec.authors = ["Felipe Zavan"]
|
10
|
+
spec.email = ["zavan@outlook.com"]
|
11
|
+
spec.summary = %q{Wrapper around the Google Maps Distance Matrix API.}
|
12
|
+
spec.homepage = "https://github.com/zavan/google_maps_api-distance_matrix"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta2", "< 4"
|
23
|
+
|
24
|
+
spec.add_dependency "google_maps_api-core", "~> 0.2"
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "google_maps_api/distance_matrix/version"
|
2
|
+
require "google_maps_api/distance_matrix/request"
|
3
|
+
require "google_maps_api/distance_matrix/response"
|
4
|
+
require "google_maps_api/distance_matrix/row"
|
5
|
+
require "google_maps_api/distance_matrix/element"
|
6
|
+
require "google_maps_api/distance_matrix/exceptions"
|
7
|
+
require "google_maps_api/core"
|
8
|
+
|
9
|
+
module GoogleMapsAPI
|
10
|
+
module DistanceMatrix
|
11
|
+
def self.calculate(origins, destinations, options = {})
|
12
|
+
request = Request.build(origins, destinations, options)
|
13
|
+
request.perform
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class GoogleMapsAPI::DistanceMatrix::Element
|
2
|
+
attr_reader :status, :duration, :distance
|
3
|
+
|
4
|
+
def initialize(status, duration, distance)
|
5
|
+
@status = status
|
6
|
+
@duration = duration
|
7
|
+
@distance = distance
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from_hash(hash)
|
11
|
+
self.new(
|
12
|
+
hash["status"],
|
13
|
+
GoogleMapsAPI::Core::Duration.from_hash(hash["duration"]),
|
14
|
+
GoogleMapsAPI::Core::Distance.from_hash(hash["distance"])
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
class GoogleMapsAPI::DistanceMatrix::Request
|
4
|
+
BASE_PATH = "/maps/api/distancematrix/json"
|
5
|
+
|
6
|
+
attr_accessor :origins, :destinations, :options, :http_adapter
|
7
|
+
|
8
|
+
def initialize(origins, destinations, options = {})
|
9
|
+
@origins = arrays_to_coordinate_string(origins)
|
10
|
+
@destinations = arrays_to_coordinate_string(destinations)
|
11
|
+
@options = options
|
12
|
+
@http_adapter = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.build(origin, destination, options = {})
|
16
|
+
self.new(origin, destination, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
response = http_adapter.get_response(uri)
|
21
|
+
if response.is_a?(Net::HTTPSuccess)
|
22
|
+
return GoogleMapsAPI::DistanceMatrix::Response.from_json(response.body)
|
23
|
+
else
|
24
|
+
msg = "The response was not successful (200). Call #response for datails."
|
25
|
+
exception = GoogleMapsAPI::DistanceMatrix::ResponseError.new(msg)
|
26
|
+
exception.response = response
|
27
|
+
raise exception
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def uri
|
32
|
+
base_host = GoogleMapsAPI::Core::BASE_HOST
|
33
|
+
uri = "#{scheme}://#{base_host}#{BASE_PATH}"
|
34
|
+
query_params = prepared_options.merge(
|
35
|
+
{origins: origins.join("|"), destinations: destinations.join("|")}
|
36
|
+
).reject { |key, value| [:client, :channel].include?(key) }
|
37
|
+
|
38
|
+
if business_account?
|
39
|
+
query_params = query_params.reject { |key, value| [:key].include?(key) }
|
40
|
+
uri = "#{uri}?#{to_query(query_params)}"
|
41
|
+
uri = sign_uri(uri)
|
42
|
+
else
|
43
|
+
uri = URI("#{uri}?#{URI.encode_www_form(query_params)}")
|
44
|
+
end
|
45
|
+
|
46
|
+
uri
|
47
|
+
end
|
48
|
+
|
49
|
+
def scheme
|
50
|
+
options[:https] ? "https" : "http"
|
51
|
+
end
|
52
|
+
|
53
|
+
def http_adapter
|
54
|
+
@http_adapter || Net::HTTP
|
55
|
+
end
|
56
|
+
|
57
|
+
def business_account?
|
58
|
+
options.key?(:key) && options.key?(:client)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def default_options
|
64
|
+
{
|
65
|
+
sensor: false,
|
66
|
+
mode: "driving",
|
67
|
+
language: "en",
|
68
|
+
units: "metric"
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
def prepared_options
|
73
|
+
options = default_options.merge(self.options)
|
74
|
+
|
75
|
+
# Symbolizes the options keys
|
76
|
+
options.keys.each do |key|
|
77
|
+
options[(key.to_sym rescue key) || key] = options.delete(key)
|
78
|
+
end
|
79
|
+
|
80
|
+
options[:departure_time] = time_or_date_to_unix(options[:departure_time])
|
81
|
+
|
82
|
+
options.delete_if { |key, value| value.to_s.strip.empty? }
|
83
|
+
options
|
84
|
+
end
|
85
|
+
|
86
|
+
def time_or_date_to_unix(time_or_date)
|
87
|
+
return time_or_date.to_i if time_or_date.is_a?(Time)
|
88
|
+
return time_or_date.to_time.to_i if time_or_date.is_a?(Date)
|
89
|
+
time_or_date
|
90
|
+
end
|
91
|
+
|
92
|
+
def sign_uri(uri)
|
93
|
+
options = prepared_options
|
94
|
+
GoogleMapsAPI::Core::URISigner.sign(
|
95
|
+
uri.to_s,
|
96
|
+
options[:client],
|
97
|
+
options[:key],
|
98
|
+
options[:channel]
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_query(hash)
|
103
|
+
hash.to_a.map { |x| "#{x[0]}=#{x[1]}" }.join("&")
|
104
|
+
end
|
105
|
+
|
106
|
+
def arrays_to_coordinate_string(items)
|
107
|
+
items.collect do |i|
|
108
|
+
i.respond_to?(:to_ary) ? i.to_ary.join(",") : i
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
class GoogleMapsAPI::DistanceMatrix::Response
|
4
|
+
attr_reader :status, :origin_addresses, :destination_addresses, :rows
|
5
|
+
|
6
|
+
def initialize(status, origin_addresses, destination_addresses, rows)
|
7
|
+
@status = status
|
8
|
+
@origin_addresses = origin_addresses
|
9
|
+
@destination_addresses = destination_addresses
|
10
|
+
@rows = rows
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from_json(json)
|
14
|
+
parsed_json = parse_json(json)
|
15
|
+
rows = build_rows(parsed_json)
|
16
|
+
self.new(
|
17
|
+
parsed_json['status'],
|
18
|
+
parsed_json['origin_addresses'],
|
19
|
+
parsed_json['destination_addresses'],
|
20
|
+
rows
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.parse_json(json)
|
27
|
+
JSON.parse(json)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.build_rows(parsed_json)
|
31
|
+
parsed_json['rows'].collect do |r|
|
32
|
+
GoogleMapsAPI::DistanceMatrix::Row.from_hash(r)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class GoogleMapsAPI::DistanceMatrix::Row
|
2
|
+
attr_reader :elements
|
3
|
+
|
4
|
+
def initialize(elements)
|
5
|
+
@elements = elements
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.from_hash(hash)
|
9
|
+
self.new(build_elements(hash))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.build_elements(hash)
|
15
|
+
hash["elements"].collect do |e|
|
16
|
+
GoogleMapsAPI::DistanceMatrix::Element.from_hash(e)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "google_maps_api/distance_matrix/json_response"
|
3
|
+
|
4
|
+
describe GoogleMapsAPI::DistanceMatrix::Element do
|
5
|
+
include_context "json response"
|
6
|
+
|
7
|
+
subject { GoogleMapsAPI::DistanceMatrix::Element }
|
8
|
+
|
9
|
+
describe ".from_hash" do
|
10
|
+
it "returns a new element" do
|
11
|
+
expect(subject.from_hash(parsed_json["rows"].first["elements"].first)).to be_a(subject)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "google_maps_api/distance_matrix/request_lets"
|
3
|
+
|
4
|
+
describe GoogleMapsAPI::DistanceMatrix::Request do
|
5
|
+
|
6
|
+
include_context "request lets"
|
7
|
+
|
8
|
+
subject { GoogleMapsAPI::DistanceMatrix::Request.new(origins, destinations, options) }
|
9
|
+
|
10
|
+
describe ".build" do
|
11
|
+
subject { GoogleMapsAPI::DistanceMatrix::Request }
|
12
|
+
|
13
|
+
it "builds a new request" do
|
14
|
+
expect(subject.build(origins, destinations, options)).to be_a(subject)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#perform" do
|
19
|
+
it "returns a response" do
|
20
|
+
expect(subject.perform).to be_a(GoogleMapsAPI::DistanceMatrix::Response)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "raises a ResponseError if the response is not successful" do
|
24
|
+
allow(subject.http_adapter).to receive(:get_response).and_return(false)
|
25
|
+
expect { subject.perform }.to raise_error(GoogleMapsAPI::DistanceMatrix::ResponseError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#uri" do
|
30
|
+
it "returns a URI" do
|
31
|
+
expect(subject.uri).to be_a(URI)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#scheme" do
|
36
|
+
context "when https option is true" do
|
37
|
+
subject { GoogleMapsAPI::DistanceMatrix::Request.new(origins, destinations, {https: true}) }
|
38
|
+
|
39
|
+
it "returns 'https'" do
|
40
|
+
expect(subject.scheme).to eq('https')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when https option is false" do
|
45
|
+
subject { GoogleMapsAPI::DistanceMatrix::Request.new(origins, destinations, {https: false}) }
|
46
|
+
|
47
|
+
it "returns 'http'" do
|
48
|
+
expect(subject.scheme).to eq('http')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
{
|
2
|
+
"status": "OK",
|
3
|
+
"origin_addresses": [ "Vancouver, BC, Canada", "Seattle, État de Washington, États-Unis" ],
|
4
|
+
"destination_addresses": [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ],
|
5
|
+
"rows": [ {
|
6
|
+
"elements": [ {
|
7
|
+
"status": "OK",
|
8
|
+
"duration": {
|
9
|
+
"value": 340110,
|
10
|
+
"text": "3 jours 22 heures"
|
11
|
+
},
|
12
|
+
"distance": {
|
13
|
+
"value": 1734542,
|
14
|
+
"text": "1 735 km"
|
15
|
+
}
|
16
|
+
}, {
|
17
|
+
"status": "OK",
|
18
|
+
"duration": {
|
19
|
+
"value": 24487,
|
20
|
+
"text": "6 heures 48 minutes"
|
21
|
+
},
|
22
|
+
"distance": {
|
23
|
+
"value": 129324,
|
24
|
+
"text": "129 km"
|
25
|
+
}
|
26
|
+
} ]
|
27
|
+
}, {
|
28
|
+
"elements": [ {
|
29
|
+
"status": "OK",
|
30
|
+
"duration": {
|
31
|
+
"value": 288834,
|
32
|
+
"text": "3 jours 8 heures"
|
33
|
+
},
|
34
|
+
"distance": {
|
35
|
+
"value": 1489604,
|
36
|
+
"text": "1 490 km"
|
37
|
+
}
|
38
|
+
}, {
|
39
|
+
"status": "OK",
|
40
|
+
"duration": {
|
41
|
+
"value": 14388,
|
42
|
+
"text": "4 heures 0 minutes"
|
43
|
+
},
|
44
|
+
"distance": {
|
45
|
+
"value": 135822,
|
46
|
+
"text": "136 km"
|
47
|
+
}
|
48
|
+
} ]
|
49
|
+
} ]
|
50
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "google_maps_api/distance_matrix/json_response"
|
3
|
+
|
4
|
+
describe GoogleMapsAPI::DistanceMatrix::Response do
|
5
|
+
include_context "json response"
|
6
|
+
|
7
|
+
subject { GoogleMapsAPI::DistanceMatrix::Response }
|
8
|
+
|
9
|
+
describe ".from_json" do
|
10
|
+
it "returns a new response" do
|
11
|
+
expect(subject.from_json(json)).to be_a(subject)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "google_maps_api/distance_matrix/json_response"
|
3
|
+
|
4
|
+
describe GoogleMapsAPI::DistanceMatrix::Row do
|
5
|
+
include_context "json response"
|
6
|
+
|
7
|
+
subject { GoogleMapsAPI::DistanceMatrix::Row }
|
8
|
+
|
9
|
+
describe ".from_hash" do
|
10
|
+
it "returns a new row" do
|
11
|
+
expect(subject.from_hash(parsed_json["rows"].first)).to be_a(subject)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "google_maps_api/distance_matrix/request_lets"
|
3
|
+
|
4
|
+
describe GoogleMapsAPI::DistanceMatrix do
|
5
|
+
subject { GoogleMapsAPI::DistanceMatrix }
|
6
|
+
|
7
|
+
include_context "request lets"
|
8
|
+
|
9
|
+
describe ".calculate" do
|
10
|
+
it "performs a request" do
|
11
|
+
expect_any_instance_of(subject::Request).to receive(:perform).with(no_args)
|
12
|
+
subject.calculate(origins, destinations, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns a response" do
|
16
|
+
expect(subject.calculate(origins, destinations, options)).to be_a(subject::Response)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "google_maps_api/distance_matrix"
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
6
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
7
|
+
#
|
8
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
9
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
10
|
+
# (such as loading up an entire rails app) will add to the boot time of your
|
11
|
+
# test suite on EVERY test run, even for an individual file that may not need
|
12
|
+
# all of that loaded.
|
13
|
+
#
|
14
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
15
|
+
# users commonly want.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# The settings below are suggested to provide a good initial experience
|
20
|
+
# with RSpec, but feel free to customize to your heart's content.
|
21
|
+
=begin
|
22
|
+
# These two settings work together to allow you to limit a spec run
|
23
|
+
# to individual examples or groups you care about by tagging them with
|
24
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
25
|
+
# get run.
|
26
|
+
config.filter_run :focus
|
27
|
+
config.run_all_when_everything_filtered = true
|
28
|
+
|
29
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
30
|
+
# file, and it's useful to allow more verbose output when running an
|
31
|
+
# individual spec file.
|
32
|
+
if config.files_to_run.one?
|
33
|
+
# RSpec filters the backtrace by default so as not to be so noisy.
|
34
|
+
# This causes the full backtrace to be printed when running a single
|
35
|
+
# spec file (e.g. to troubleshoot a particular spec failure).
|
36
|
+
config.full_backtrace = true
|
37
|
+
|
38
|
+
# Use the documentation formatter for detailed output,
|
39
|
+
# unless a formatter has already been configured
|
40
|
+
# (e.g. via a command-line flag).
|
41
|
+
config.formatter = 'doc' if config.formatters.none?
|
42
|
+
end
|
43
|
+
|
44
|
+
# Print the 10 slowest examples and example groups at the
|
45
|
+
# end of the spec run, to help surface which specs are running
|
46
|
+
# particularly slow.
|
47
|
+
config.profile_examples = 10
|
48
|
+
|
49
|
+
# Run specs in random order to surface order dependencies. If you find an
|
50
|
+
# order dependency and want to debug it, you can fix the order by providing
|
51
|
+
# the seed, which is printed after each run.
|
52
|
+
# --seed 1234
|
53
|
+
config.order = :random
|
54
|
+
|
55
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
56
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
57
|
+
# test failures related to randomization by passing the same `--seed` value
|
58
|
+
# as the one that triggered the failure.
|
59
|
+
Kernel.srand config.seed
|
60
|
+
|
61
|
+
# rspec-expectations config goes here. You can use an alternate
|
62
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
63
|
+
# assertions if you prefer.
|
64
|
+
config.expect_with :rspec do |expectations|
|
65
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
66
|
+
# For more details, see:
|
67
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
68
|
+
expectations.syntax = :expect
|
69
|
+
end
|
70
|
+
|
71
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
72
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
73
|
+
config.mock_with :rspec do |mocks|
|
74
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
75
|
+
# For more details, see:
|
76
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
77
|
+
mocks.syntax = :expect
|
78
|
+
|
79
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
80
|
+
# a real object. This is generally recommended.
|
81
|
+
mocks.verify_partial_doubles = true
|
82
|
+
end
|
83
|
+
=end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_maps_api-distance_matrix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Felipe Zavan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-15 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0.beta2
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '4'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 3.0.0.beta2
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '4'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: google_maps_api-core
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.2'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.2'
|
75
|
+
description:
|
76
|
+
email:
|
77
|
+
- zavan@outlook.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rspec"
|
84
|
+
- Gemfile
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- google_maps_api-distance_matrix.gemspec
|
89
|
+
- lib/google_maps_api/distance_matrix.rb
|
90
|
+
- lib/google_maps_api/distance_matrix/element.rb
|
91
|
+
- lib/google_maps_api/distance_matrix/exceptions.rb
|
92
|
+
- lib/google_maps_api/distance_matrix/request.rb
|
93
|
+
- lib/google_maps_api/distance_matrix/response.rb
|
94
|
+
- lib/google_maps_api/distance_matrix/row.rb
|
95
|
+
- lib/google_maps_api/distance_matrix/version.rb
|
96
|
+
- spec/google_maps_api/distance_matrix/element_spec.rb
|
97
|
+
- spec/google_maps_api/distance_matrix/json_response.rb
|
98
|
+
- spec/google_maps_api/distance_matrix/request_lets.rb
|
99
|
+
- spec/google_maps_api/distance_matrix/request_spec.rb
|
100
|
+
- spec/google_maps_api/distance_matrix/response_mock.json
|
101
|
+
- spec/google_maps_api/distance_matrix/response_spec.rb
|
102
|
+
- spec/google_maps_api/distance_matrix/row_spec.rb
|
103
|
+
- spec/google_maps_api/distance_matrix_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: https://github.com/zavan/google_maps_api-distance_matrix
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Wrapper around the Google Maps Distance Matrix API.
|
129
|
+
test_files:
|
130
|
+
- spec/google_maps_api/distance_matrix/element_spec.rb
|
131
|
+
- spec/google_maps_api/distance_matrix/json_response.rb
|
132
|
+
- spec/google_maps_api/distance_matrix/request_lets.rb
|
133
|
+
- spec/google_maps_api/distance_matrix/request_spec.rb
|
134
|
+
- spec/google_maps_api/distance_matrix/response_mock.json
|
135
|
+
- spec/google_maps_api/distance_matrix/response_spec.rb
|
136
|
+
- spec/google_maps_api/distance_matrix/row_spec.rb
|
137
|
+
- spec/google_maps_api/distance_matrix_spec.rb
|
138
|
+
- spec/spec_helper.rb
|