google_distance_matrix 0.1.3 → 0.2.0

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: 059c0da78b14d17f1c6a11d5de3e535b77d652c9
4
- data.tar.gz: 07a291b59c5099c25906fee538f2fd6d7d4685ed
3
+ metadata.gz: 889a735e923a64e646fdd8d62f8b95e9cac813de
4
+ data.tar.gz: aac05a54e40741a24969c3cd7ebc07e24531a535
5
5
  SHA512:
6
- metadata.gz: a0e06fe9215299611134f0fe052484ca84a5c394fba93e142238de1fd07884db3a76ca0f9c2defdd4780fe96de332a852d9db3d5d21c8328f8b19f48b38c5136
7
- data.tar.gz: 4408a0c269ee247801ab790724f96617a8a75f83c27e58f8ebc9ae6f34c21920a6e3d4c23831ff8c769496f13068fdca1daba8ff2687676411697a14341ef2af
6
+ metadata.gz: dae22319ffd3a4c144527985d729c1dfcd87432d830d7c9efa8434d8210285507f7890257a6ace2f26349dbb5f64523abee6599cec44bbd7b476e52b6e60502b
7
+ data.tar.gz: f5d5950aa52c3527be20fe315de87a3f0e10a636d9e0c31d563a9f4d367dbeafab61a19426e477864fc5e4213609443c45ba4e96fb434ca2713cd16bc1d34f91
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -1,14 +1,10 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
3
  - 2.1.0
5
4
  - 2.1.2
6
5
  - 2.1.5
6
+ - 2.2.3
7
7
  - ruby-head
8
- - jruby-19mode
9
- - jruby
10
- - jruby-head
11
8
  matrix:
12
9
  allow_failures:
13
- - rvm: jruby-head
14
10
  - rvm: ruby-head
@@ -1,3 +1,9 @@
1
+ ## v.0.2.0
2
+ * Dropped support for Ruby 1.9.X
3
+ * Added new configuration options: google_api_key,
4
+ transit, transit_mode, arrival_time and departure_time. (by lsanwick)
5
+
6
+
1
7
  ## v.0.1.3
2
8
  * Be optimistic in regards to ActiveSupport and ActiveModel version we support.
3
9
 
data/README.md CHANGED
@@ -41,13 +41,13 @@ but to solve it you may look at http://ai4r.org/.
41
41
  another_point = Point.new lat: 1, lng: 3
42
42
  matrix.origins << another_point
43
43
 
44
- ### Do some configuration - see GoogleDistanceMatrix.default_configuration as well.
44
+ ### Do some configuration - see GoogleDistanceMatrix.configure_defaults as well.
45
45
 
46
46
  matrix.configure do |config|
47
47
  config.mode = 'driving'
48
48
  config.avoid = ['tolls']
49
49
 
50
- # To build signed URLs to use with a Google Business account
50
+ # To build signed URLs to use with a Google Business account. You may also use google_api_key.
51
51
  config.google_business_api_client_id = "123"
52
52
  config.google_business_api_private_key = "your-secret-key"
53
53
  end
@@ -100,7 +100,7 @@ Or install it yourself as:
100
100
 
101
101
  ## Configuration
102
102
 
103
- Configuration is done directly on a matrix or via GoogleDistanceMatrix.default_configuration.
103
+ Configuration is done directly on a matrix or via GoogleDistanceMatrix.configure_defaults.
104
104
  Apart from configuration on requests it is also possible to provide your own logger class and
105
105
  set a cache.
106
106
 
@@ -109,7 +109,7 @@ Or install it yourself as:
109
109
  Given Google's limit to the service you may have the need to cache requests. This is done by simply
110
110
  using URL as cache keys. Cache we'll accept should provide a default ActiveSupport::Cache::Store interface.
111
111
 
112
- GoogleDistanceMatrix.default_configuration do |config|
112
+ GoogleDistanceMatrix.configure_defaults do |config|
113
113
  config.cache = ActiveSupport::Cache.lookup_store :your_store, {
114
114
  expires_in: 12.hours
115
115
  # ..or other options you like for your store
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "google_business_api_url_signer", "~> 0.1.3"
24
24
 
25
25
  spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rspec", "~> 3.1.0"
27
- spec.add_development_dependency "shoulda-matchers", "~> 2.6.2"
28
- spec.add_development_dependency "webmock", "~> 1.18.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3.0"
27
+ spec.add_development_dependency "shoulda-matchers", "~> 3.0.0"
28
+ spec.add_development_dependency "webmock", "~> 1.21.0"
29
29
  spec.add_development_dependency "rake"
30
30
  end
@@ -9,7 +9,7 @@ module GoogleDistanceMatrix
9
9
  class Configuration
10
10
  include ActiveModel::Validations
11
11
 
12
- ATTRIBUTES = %w[sensor mode avoid units language]
12
+ ATTRIBUTES = %w[sensor mode avoid units language departure_time arrival_time transit_mode]
13
13
 
14
14
  API_DEFAULTS = {
15
15
  mode: "driving",
@@ -17,15 +17,20 @@ module GoogleDistanceMatrix
17
17
  }.with_indifferent_access
18
18
 
19
19
  attr_accessor *ATTRIBUTES, :protocol, :logger, :lat_lng_scale
20
- attr_accessor :google_business_api_client_id, :google_business_api_private_key
20
+ attr_accessor :google_business_api_client_id, :google_business_api_private_key, :google_api_key
21
21
  attr_accessor :cache
22
22
 
23
23
 
24
24
  validates :sensor, inclusion: {in: [true, false]}
25
- validates :mode, inclusion: {in: ["driving", "walking", "bicycling"]}, allow_blank: true
25
+ validates :mode, inclusion: {in: ["driving", "walking", "bicycling", "transit"]}, allow_blank: true
26
26
  validates :avoid, inclusion: {in: ["tolls", "highways"]}, allow_blank: true
27
27
  validates :units, inclusion: {in: ["metric", "imperial"]}, allow_blank: true
28
28
 
29
+ validates :departure_time, numericality: true, allow_blank: true
30
+ validates :arrival_time, numericality: true, allow_blank: true
31
+
32
+ validates :transit_mode, inclusion: {in: %w[bus subway train tram rail]}, allow_blank: true
33
+
29
34
  validates :protocol, inclusion: {in: ["http", "https"]}, allow_blank: true
30
35
 
31
36
 
@@ -59,6 +64,10 @@ module GoogleDistanceMatrix
59
64
  out << ['client', google_business_api_client_id]
60
65
  end
61
66
 
67
+ if google_api_key.present?
68
+ out << ['key', google_api_key]
69
+ end
70
+
62
71
  out
63
72
  end
64
73
 
@@ -39,6 +39,10 @@ module GoogleDistanceMatrix
39
39
  configuration.google_business_api_private_key.present?
40
40
  end
41
41
 
42
+ def include_api_key?
43
+ configuration.google_api_key.present?
44
+ end
45
+
42
46
  def get_params_string
43
47
  params.to_a.map { |key_value| key_value.join("=") }.join("&")
44
48
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleDistanceMatrix
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe GoogleDistanceMatrix::Configuration do
4
+ include Shoulda::Matchers::ActiveModel
5
+
4
6
  subject { described_class.new }
5
7
 
6
8
  describe "Validations" do
@@ -24,16 +26,48 @@ describe GoogleDistanceMatrix::Configuration do
24
26
  end
25
27
  end
26
28
 
27
- it { should ensure_inclusion_of(:mode).in_array(["driving", "walking", "bicycling"]) }
29
+ describe 'departure_time' do
30
+ it 'is valid with a timestamp' do
31
+ subject.departure_time = Time.now.to_i
32
+ subject.valid?
33
+ expect(subject.errors[:departure_time].length).to eq 0
34
+ end
35
+
36
+ it 'is invalid with something else' do
37
+ subject.departure_time = 'foo'
38
+ subject.valid?
39
+ expect(subject.errors[:departure_time].length).to eq 1
40
+ end
41
+ end
42
+
43
+ describe 'arrival_time' do
44
+ it 'is valid with a timestamp' do
45
+ subject.arrival_time = Time.now.to_i
46
+ subject.valid?
47
+ expect(subject.errors[:arrival_time].length).to eq 0
48
+ end
49
+
50
+ it 'is invalid with something else' do
51
+ subject.arrival_time = 'foo'
52
+ subject.valid?
53
+ expect(subject.errors[:arrival_time].length).to eq 1
54
+ end
55
+ end
56
+
57
+ it { should validate_inclusion_of(:mode).in_array(["driving", "walking", "bicycling", "transit"]) }
58
+
28
59
  it { should allow_value(nil).for(:mode) }
29
60
 
30
- it { should ensure_inclusion_of(:avoid).in_array(["tolls", "highways"]) }
61
+ it { should validate_inclusion_of(:avoid).in_array(["tolls", "highways"]) }
31
62
  it { should allow_value(nil).for(:avoid) }
32
63
 
33
- it { should ensure_inclusion_of(:units).in_array(["metric", "imperial"]) }
64
+ it { should validate_inclusion_of(:units).in_array(["metric", "imperial"]) }
34
65
  it { should allow_value(nil).for(:units) }
35
66
 
36
- it { should ensure_inclusion_of(:protocol).in_array(["http", "https"]) }
67
+
68
+ it { should validate_inclusion_of(:protocol).in_array(["http", "https"]) }
69
+
70
+ it { should validate_inclusion_of(:transit_mode).in_array(["bus", "subway", "train", "tram", "rail"])}
37
71
  end
38
72
 
39
73
 
@@ -46,8 +80,13 @@ describe GoogleDistanceMatrix::Configuration do
46
80
  it { expect(subject.protocol).to eq 'http' }
47
81
  it { expect(subject.language).to be_nil }
48
82
 
83
+ it { expect(subject.departure_time).to be_nil }
84
+ it { expect(subject.arrival_time).to be_nil }
85
+ it { expect(subject.transit_mode).to be_nil }
86
+
49
87
  it { expect(subject.google_business_api_client_id).to be_nil }
50
88
  it { expect(subject.google_business_api_private_key).to be_nil }
89
+ it { expect(subject.google_api_key).to be_nil }
51
90
 
52
91
  it { expect(subject.logger).to be_nil }
53
92
  it { expect(subject.cache).to be_nil }
@@ -79,5 +118,10 @@ describe GoogleDistanceMatrix::Configuration do
79
118
  subject.google_business_api_client_id = "123"
80
119
  expect(subject.to_param['client']).to eq "123"
81
120
  end
121
+
122
+ it "includes key if google_api_key has been set" do
123
+ subject.google_api_key = "12345"
124
+ expect(subject.to_param['key']).to eq("12345")
125
+ end
82
126
  end
83
127
  end
@@ -84,6 +84,18 @@ describe GoogleDistanceMatrix::UrlBuilder do
84
84
  expect(subject.url).to include "sensor=#{matrix.configuration.sensor}"
85
85
  end
86
86
 
87
+ context 'with google api key set' do
88
+ before do
89
+ matrix.configure do |config|
90
+ config.google_api_key = '12345'
91
+ end
92
+ end
93
+
94
+ it 'includes the api key' do
95
+ expect(subject.url).to include "key=#{matrix.configuration.google_api_key}"
96
+ end
97
+ end
98
+
87
99
  context "with google business client id and private key set" do
88
100
  before do
89
101
  matrix.configure do |config|
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.1.3
4
+ version: 0.2.0
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: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.1.0
75
+ version: 3.3.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 3.1.0
82
+ version: 3.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: shoulda-matchers
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.6.2
89
+ version: 3.0.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.6.2
96
+ version: 3.0.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: webmock
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.18.0
103
+ version: 1.21.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.18.0
110
+ version: 1.21.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".gitignore"
133
- - ".rbenv-version"
133
+ - ".ruby-version"
134
134
  - ".travis.yml"
135
135
  - CHANGELOG.md
136
136
  - Gemfile
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.2.2
189
+ rubygems_version: 2.4.5.1
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Ruby client for The Google Distance Matrix API
@@ -1 +0,0 @@
1
- 2.1.5