google_maps_geocoder 0.5.0 → 0.6.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: 060caf858407bc718955028bc0edc35a518b2f63
4
- data.tar.gz: 616a78c20c6ff0926380a413b51094fe8b824bf1
3
+ metadata.gz: 92a146ad04baf20283ba5a60779df8febfe4e73c
4
+ data.tar.gz: 69643ee376cd858858a514a47e047214d3d01212
5
5
  SHA512:
6
- metadata.gz: 6aebec357d9d33fbba4586cc7c09cceebcd3d159ecc7cd648b1548e6f80810838208f486fba1c526b81e73c40d30eb7e9cffed58912a8d1c1462aa6977d961a2
7
- data.tar.gz: a624fd613c2c84ed5641186c1549135760d545976c4f83e12fce3c05322bdc24e7be9929e3f96020bc19f42608992af2de6d5035e23e070f6e9102bba9705017
6
+ metadata.gz: 897ee589156b6be42b27c2d3dfce893686b6dbe34d7d0620cbcf6fe569ed157f5e68723190f534285866ce90f4465315fccb94e529abf9e3a3a869a1863a9549
7
+ data.tar.gz: 86ca105f64c38e9acbe2b5e2e54317abaf9d69b6663f04868958a14e13ec71e9a7adde2432097f8c77ea36dc096b9be6e422906e9bbb93f121cbff72b8e78833
@@ -0,0 +1,22 @@
1
+ # How to contribute
2
+
3
+ ## **Did you find a bug?**
4
+
5
+ 1. **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/ivanoblomov/google_maps_geocoder/issues).
6
+
7
+ 2. If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/ivanoblomov/google_maps_geocoder/issues/new). Be sure to include:
8
+ 1. a **title and clear description**
9
+ 2. as much **relevant information** as possible
10
+ 3. a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
11
+
12
+ ## **Did you write a patch that fixes a bug or adds a new feature?**
13
+
14
+ 1. **Add specs** that either reproduces the bug or covers the new feature. In the former's case, *make sure it fails without the fix!*
15
+
16
+ 2. **Confirm your last build passes** on [Travis CI](https://travis-ci.org/ivanoblomov/google_maps_geocoder/branches).
17
+
18
+ 3. **Update the inline documentation.** Format it with [YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md). For example, see [`GoogleMapsGeocoder.new`](https://github.com/ivanoblomov/google_maps_geocoder/blob/github-templates/lib/google_maps_geocoder/google_maps_geocoder.rb#L43-L50).
19
+
20
+ 4. [Open a pull request](https://github.com/ivanoblomov/google_maps_geocoder/compare) with the patch or feature. Follow the template's directions.
21
+
22
+ ## Thanks for contributing!
@@ -0,0 +1,17 @@
1
+ # Description
2
+
3
+ Provide as much background as you need to get the implementer up to speed on the problem to be solved. This can also include screenshots and links to other issues or pull requests.
4
+
5
+ # Steps to Reproduce
6
+
7
+ Don't forget to point out the difference between what *should* happen and what *does* happen. Here's an example:
8
+
9
+ 1. Try geocoding "1600 Pennsylvania Ave":
10
+ ```ruby
11
+ white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Ave')
12
+ ```
13
+ 2. The formatted address doesn't match the White House:
14
+ ```ruby
15
+ white_house.formatted_address
16
+ => "1600 Pennsylvania Ave, Charleston, WV 25302, USA"
17
+ ```
@@ -0,0 +1,9 @@
1
+ Closes: #
2
+
3
+ # Goal
4
+ What problem does this pull request solve? This should be close to the goal of the issue this pull request addresses.
5
+
6
+ # Approach
7
+ 1. Describe the approach you chose to solve the above problem.
8
+ 2. This will help code reviewers get oriented quickly.
9
+ 3. It will also document for future maintainers exactly what changed (and why) when this PR was merged.
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.2.5
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  sudo: false
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.2.5
4
4
  script:
5
5
  - bundle exec rake
6
6
  - bundle exec rubocop
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Roderick Monje
1
+ Copyright (c) 2011-2017 Roderick Monje
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/ivanoblomov/google_maps_geocoder.png)](http://travis-ci.org/ivanoblomov/google_maps_geocoder)
4
4
  [![Code Climate](https://codeclimate.com/github/ivanoblomov/google_maps_geocoder.png)](https://codeclimate.com/github/ivanoblomov/google_maps_geocoder)
5
- [![Coverage Status](https://coveralls.io/repos/ivanoblomov/google_maps_geocoder/badge.svg?branch=master&service=github)](https://coveralls.io/github/ivanoblomov/google_maps_geocoder?branch=master)
6
- [![Dependency Status](https://gemnasium.com/ivanoblomov/google_maps_geocoder.png)](https://gemnasium.com/ivanoblomov/google_maps_geocoder)
7
- [![Inch CI](https://inch-ci.org/github/Ivanoblomov/google_maps_geocoder.svg?branch=master&style=flat)](https://inch-ci.org/github/Ivanoblomov/google_maps_geocoder)
5
+ [![Coverage Status](https://coveralls.io/repos/github/ivanoblomov/google_maps_geocoder/badge.svg?branch=master)](https://coveralls.io/github/ivanoblomov/google_maps_geocoder?branch=master)
6
+ [![Inline docs](http://inch-ci.org/github/Ivanoblomov/google_maps_geocoder.svg?branch=master)](http://inch-ci.org/github/Ivanoblomov/google_maps_geocoder)
8
7
  [![Gem Version](https://badge.fury.io/rb/google_maps_geocoder.svg)](http://badge.fury.io/rb/google_maps_geocoder)
8
+ [![security](https://hakiri.io/github/ivanoblomov/google_maps_geocoder/master.svg)](https://hakiri.io/github/ivanoblomov/google_maps_geocoder/master)
9
9
 
10
10
  A simple Plain Old Ruby Object wrapper for geocoding with Google Maps.
11
11
 
@@ -26,7 +26,7 @@ Or try it out in `irb` with:
26
26
  ## Ready to Go in One Step
27
27
 
28
28
  ```ruby
29
- chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania Washington'
29
+ chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania DC'
30
30
  ```
31
31
 
32
32
  ## Usage
@@ -85,16 +85,8 @@ To have GoogleMapsGeocoder use your Google Maps API key, set it as an environmen
85
85
  export GOOGLE_MAPS_API_KEY=[your key]
86
86
  ```
87
87
 
88
- ## Contributing to google_maps_geocoder
89
-
90
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
91
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
92
- * Fork the project
93
- * Start a feature/bugfix branch
94
- * Commit and push until you are happy with your contribution
95
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
96
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
88
+ ## [Contributing to GoogleMapsGeocoder](https://github.com/ivanoblomov/google_maps_geocoder/blob/master/.github/CONTRIBUTING.md)
97
89
 
98
90
  ## Copyright
99
91
 
100
- Copyright (c) 2011 Roderick Monje. See LICENSE.txt for further details.
92
+ Copyright © 2011-2018 Roderick Monje. See [LICENSE.txt](https://github.com/ivanoblomov/google_maps_geocoder/blob/master/LICENSE.txt) for further details.
@@ -1,22 +1,24 @@
1
- require File.expand_path '../lib/google_maps_geocoder/version', __FILE__
1
+ require File.expand_path('lib/google_maps_geocoder/version', __dir__)
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'google_maps_geocoder'
4
4
  s.version = GoogleMapsGeocoder::VERSION.dup
5
+ s.licenses = ['MIT']
5
6
  s.summary = 'A simple PORO wrapper for geocoding with Google Maps.'
6
7
  s.description = 'Geocode a location without worrying about parsing Google '\
7
8
  "Maps' response. GoogleMapsGeocoder wraps it in a plain-old "\
8
9
  'Ruby object.'
9
10
  s.homepage = 'http://github.com/ivanoblomov/google_maps_geocoder'
10
11
  s.authors = ['Roderick Monje']
12
+ s.email = 'rod@foveacentral.com'
11
13
 
12
- s.add_development_dependency 'codeclimate-test-reporter', '>= 0'
13
- s.add_development_dependency 'coveralls', '>= 0'
14
- s.add_development_dependency 'rake', '>= 0'
15
- s.add_development_dependency 'rspec', '>= 0'
16
- s.add_development_dependency 'rubocop', '>= 0'
14
+ s.add_development_dependency 'codeclimate-test-reporter', '~> 0'
15
+ s.add_development_dependency 'coveralls', '~> 0'
16
+ s.add_development_dependency 'rake', '~> 0'
17
+ s.add_development_dependency 'rspec', '~> 3'
18
+ s.add_development_dependency 'rubocop', '~> 0'
17
19
 
18
- s.add_runtime_dependency 'activesupport', '>= 0'
19
- s.add_runtime_dependency 'rack', '>= 0'
20
+ s.add_runtime_dependency 'activesupport', '~> 4.2'
21
+ s.add_runtime_dependency 'rack', '~> 1.6'
20
22
 
21
23
  s.files = `git ls-files`.split "\n"
22
24
  s.test_files = `git ls-files -- {test,spec,features}/*`.split "\n"
@@ -1,5 +1,4 @@
1
1
  require 'active_support'
2
- require 'active_support/core_ext/string/inflections'
3
2
  require 'logger'
4
3
  require 'net/http'
5
4
  require 'rack'
@@ -7,47 +6,19 @@ require 'rack'
7
6
  # A simple PORO wrapper for geocoding with Google Maps.
8
7
  #
9
8
  # @example
10
- # chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania Ave'
9
+ # chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania DC'
11
10
  # chez_barack.formatted_address
12
11
  # => "1600 Pennsylvania Avenue Northwest, President's Park,
13
12
  # Washington, DC 20500, USA"
14
- # rubocop:disable Metrics/ClassLength
15
13
  class GoogleMapsGeocoder
16
- # Error handling for google statuses
17
- class GeocodingError < StandardError
18
- def initialize(response_json = '')
19
- @json = response_json
20
- super
21
- end
22
-
23
- def message
24
- "Google returned:\n#{@json.inspect}"
25
- end
26
- end
27
-
28
- class ZeroResultsError < GeocodingError; end
29
- class QueryLimitError < GeocodingError; end
30
- class RequestDeniedError < GeocodingError; end
31
- class InvalidRequestError < GeocodingError; end
32
- class UnknownError < GeocodingError; end
33
-
34
- ERROR_STATUSES = { zero_results: 'ZERO_RESULTS',
35
- query_limit: 'OVER_QUERY_LIMIT',
36
- request_denied: 'REQUEST_DENIED',
37
- invalid_request: 'INVALID_REQUEST',
38
- unknown: 'UNKNOWN_ERROR'
39
- }.freeze
40
-
41
- GOOGLE_ADDRESS_SEGMENTS = %i(
14
+ GOOGLE_ADDRESS_SEGMENTS = %i[
42
15
  city country_long_name country_short_name county lat lng postal_code
43
16
  state_long_name state_short_name
44
- ).freeze
45
- GOOGLE_API_URI = 'https://maps.googleapis.com/maps/api/geocode/json'.freeze
17
+ ].freeze
18
+ GOOGLE_MAPS_API = 'https://maps.googleapis.com/maps/api/geocode/json'.freeze
46
19
 
47
20
  ALL_ADDRESS_SEGMENTS = (
48
- GOOGLE_ADDRESS_SEGMENTS + %i(
49
- formatted_address formatted_street_address
50
- )
21
+ GOOGLE_ADDRESS_SEGMENTS + %i[formatted_address formatted_street_address]
51
22
  ).freeze
52
23
 
53
24
  # Returns the complete formatted address with standardized abbreviations.
@@ -64,7 +35,7 @@ class GoogleMapsGeocoder
64
35
  # @return [String] the formatted street address
65
36
  # @example
66
37
  # chez_barack.formatted_street_address
67
- # => "1600 Pennsylvania Avenue"
38
+ # => "1600 Pennsylvania Avenue Northwest"
68
39
  attr_reader :formatted_street_address
69
40
  # Self-explanatory
70
41
  attr_reader(*GOOGLE_ADDRESS_SEGMENTS)
@@ -72,17 +43,20 @@ class GoogleMapsGeocoder
72
43
  # Geocodes the specified address and wraps the results in a GoogleMapsGeocoder
73
44
  # object.
74
45
  #
75
- # @param data [String] a geocodable address
46
+ # @param address [String] a geocodable address
76
47
  # @return [GoogleMapsGeocoder] the Google Maps result for the specified
77
48
  # address
78
49
  # @example
79
- # chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania Ave'
80
- def initialize(data)
81
- @json = data.is_a?(String) ? json_from_url(data) : data
82
- handle_error if @json.blank? || @json['status'] != 'OK'
50
+ # chez_barack = GoogleMapsGeocoder.new '1600 Pennsylvania DC'
51
+ def initialize(address)
52
+ @json = address.is_a?(String) ? google_maps_response(address) : address
53
+ status = @json && @json['status']
54
+ raise RuntimeError if status == 'OVER_QUERY_LIMIT'
55
+ raise GeocodingError, @json if @json.blank? || status != 'OK'
56
+
83
57
  set_attributes_from_json
84
- logger.info('GoogleMapsGeocoder') do
85
- "Geocoded \"#{data}\" => \"#{formatted_address}\""
58
+ Logger.new(STDERR).info('GoogleMapsGeocoder') do
59
+ "Geocoded \"#{address}\" => \"#{formatted_address}\""
86
60
  end
87
61
  end
88
62
 
@@ -100,21 +74,48 @@ class GoogleMapsGeocoder
100
74
  #
101
75
  # @return [boolean] whether the Google Maps result is a partial match
102
76
  # @example
103
- # GoogleMapsGeocoder.new('1600 Pennsylvania Washington').partial_match?
77
+ # GoogleMapsGeocoder.new('1600 Pennsylvania DC').partial_match?
104
78
  # => true
105
79
  def partial_match?
106
80
  @json['results'][0]['partial_match'] == true
107
81
  end
108
82
 
109
- def self.error_class_name(key)
110
- "google_maps_geocoder/#{key}_error".classify.constantize
83
+ # A geocoding error returned by Google Maps.
84
+ class GeocodingError < StandardError
85
+ # Returns the complete JSON response from Google Maps as a Hash.
86
+ #
87
+ # @return [Hash] Google Maps' JSON response
88
+ # @example
89
+ # {
90
+ # "results" => [],
91
+ # "status" => "ZERO_RESULTS"
92
+ # }
93
+ attr_reader :json
94
+
95
+ # Initialize a GeocodingError wrapping the JSON returned by Google Maps.
96
+ #
97
+ # @param json [Hash] Google Maps' JSON response
98
+ # @return [GeocodingError] the geocoding error
99
+ def initialize(json = {})
100
+ @json = json
101
+ if (message = @json['error_message'])
102
+ Logger.new(STDERR).error(message)
103
+ end
104
+ super @json['status']
105
+ end
111
106
  end
112
107
 
113
108
  private
114
109
 
115
- def api_key
116
- @api_key ||= "&key=#{ENV['GOOGLE_MAPS_API_KEY']}" if
117
- ENV['GOOGLE_MAPS_API_KEY']
110
+ def google_maps_request(address)
111
+ "#{GOOGLE_MAPS_API}?address=#{Rack::Utils.escape address}"\
112
+ "&key=#{ENV['GOOGLE_MAPS_API_KEY']}"
113
+ end
114
+
115
+ def google_maps_response(address)
116
+ uri = URI.parse google_maps_request(address)
117
+ response = http(uri).request(Net::HTTP::Get.new(uri.request_uri))
118
+ ActiveSupport::JSON.decode response.body
118
119
  end
119
120
 
120
121
  def http(uri)
@@ -124,29 +125,6 @@ class GoogleMapsGeocoder
124
125
  http
125
126
  end
126
127
 
127
- def json_from_url(url)
128
- uri = URI.parse query_url(url)
129
-
130
- logger.debug('GoogleMapsGeocoder') { uri }
131
-
132
- response = http(uri).request(Net::HTTP::Get.new(uri.request_uri))
133
- ActiveSupport::JSON.decode response.body
134
- end
135
-
136
- def handle_error
137
- status = @json['status']
138
- message = GeocodingError.new(@json).message
139
-
140
- # for status codes see https://developers.google.com/maps/documentation/geocoding/intro#StatusCodes
141
- ERROR_STATUSES.each do |key, value|
142
- raise GoogleMapsGeocoder.error_class_name(key), message if status == value
143
- end
144
- end
145
-
146
- def logger
147
- @logger ||= Logger.new STDERR
148
- end
149
-
150
128
  def parse_address_component_type(type, name = 'long_name')
151
129
  address_component = @json['results'][0]['address_components'].detect do |ac|
152
130
  ac['types'] && ac['types'].include?(type)
@@ -200,11 +178,6 @@ class GoogleMapsGeocoder
200
178
  parse_address_component_type('administrative_area_level_1', 'short_name')
201
179
  end
202
180
 
203
- def query_url(query)
204
- "#{GOOGLE_API_URI}?address=#{Rack::Utils.escape query}&sensor=false"\
205
- "#{api_key}"
206
- end
207
-
208
181
  def set_attributes_from_json
209
182
  ALL_ADDRESS_SEGMENTS.each do |segment|
210
183
  instance_variable_set :"@#{segment}", send("parse_#{segment}")
@@ -1,4 +1,4 @@
1
1
  # A simple PORO wrapper for geocoding with Google Maps.
2
2
  class GoogleMapsGeocoder
3
- VERSION = '0.5.0'.freeze unless defined?(GoogleMapsGeocoder::VERSION)
3
+ VERSION = '0.6.0'.freeze unless defined?(GoogleMapsGeocoder::VERSION)
4
4
  end
@@ -1,10 +1,9 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+ # rubocop:disable Metrics/BlockLength
3
3
  describe GoogleMapsGeocoder do
4
4
  before(:all) do
5
5
  begin
6
- @exact_match = GoogleMapsGeocoder.new('837 Union Street Brooklyn NY')
7
- @partial_match = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
6
+ @exact_match = GoogleMapsGeocoder.new('White House')
8
7
  rescue SocketError
9
8
  @no_network = true
10
9
  rescue RuntimeError
@@ -17,82 +16,48 @@ describe GoogleMapsGeocoder do
17
16
  pending 'waiting for query limit to pass' if @query_limit
18
17
  end
19
18
 
20
- context 'with "837 Union Street Brooklyn NY"' do
21
- subject { @exact_match }
22
- it { expect(subject).to be_exact_match }
23
-
24
- context 'address' do
25
- it { expect(subject.formatted_street_address).to eq '837 Union Street' }
26
- it { expect(subject.city).to eq 'Brooklyn' }
27
- it { expect(subject.county).to match(/Kings/) }
28
- it { expect(subject.state_long_name).to eq 'New York' }
29
- it { expect(subject.state_short_name).to eq 'NY' }
30
- it { expect(subject.postal_code).to match(/112[0-9]{2}/) }
31
- it { expect(subject.country_short_name).to eq 'US' }
32
- it { expect(subject.country_long_name).to eq 'United States' }
33
- it do
34
- expect(subject.formatted_address)
35
- .to match(/837 Union St, Brooklyn, NY 112[0-9]{2}, USA/)
36
- end
37
- end
38
-
39
- context 'coordinates' do
40
- it { expect(subject.lat).to be_within(0.005).of(40.6748151) }
41
- it { expect(subject.lng).to be_within(0.005).of(-73.9760302) }
42
- end
43
- end
44
-
45
- context 'with "1600 Pennsylvania Washington"' do
46
- subject { @partial_match }
47
- it { should be_partial_match }
48
-
49
- context 'address' do
50
- it do
51
- expect(subject.formatted_street_address)
52
- .to eq '1600 Pennsylvania Avenue Southeast'
19
+ describe '#new' do
20
+ context 'with "White House"' do
21
+ subject { @exact_match }
22
+
23
+ it { should be_exact_match }
24
+
25
+ context 'address' do
26
+ it do
27
+ expect(subject.formatted_street_address)
28
+ .to eq '1600 Pennsylvania Avenue Northwest'
29
+ end
30
+ it { expect(subject.city).to eq 'Washington' }
31
+ it { expect(subject.state_long_name).to eq 'District of Columbia' }
32
+ it { expect(subject.state_short_name).to eq 'DC' }
33
+ it { expect(subject.postal_code).to eq '20500' }
34
+ it { expect(subject.country_short_name).to eq 'US' }
35
+ it { expect(subject.country_long_name).to eq 'United States' }
36
+ it do
37
+ expect(subject.formatted_address)
38
+ .to match(/1600 Pennsylvania Ave NW, Washington, DC 20500, USA/)
39
+ end
53
40
  end
54
- it { expect(subject.city).to eq 'Washington' }
55
- it { expect(subject.state_long_name).to eq 'District of Columbia' }
56
- it { expect(subject.state_short_name).to eq 'DC' }
57
- it { expect(subject.postal_code).to match(/2000[0-9]/) }
58
- it { expect(subject.country_short_name).to eq 'US' }
59
- it { expect(subject.country_long_name).to eq 'United States' }
60
- it do
61
- expect(subject.formatted_address)
62
- .to match(/1600 Pennsylvania Ave SE, Washington, DC 20003, USA/)
41
+ context 'coordinates' do
42
+ it { expect(subject.lat).to be_within(0.005).of(38.8976633) }
43
+ it { expect(subject.lng).to be_within(0.005).of(-77.0365739) }
63
44
  end
64
45
  end
46
+ context 'with an invalid address' do
47
+ before do
48
+ @key = ENV['GOOGLE_MAPS_API_KEY']
49
+ ENV['GOOGLE_MAPS_API_KEY'] = 'invalid_key'
50
+ end
65
51
 
66
- context 'coordinates' do
67
- it { expect(subject.lat).to be_within(0.005).of(38.8791981) }
68
- it { expect(subject.lng).to be_within(0.005).of(-76.9818437) }
69
- end
70
- end
71
-
72
- context "when ENV['GOOGLE_MAPS_API_KEY'] = 'INVALID_KEY'" do
73
- before { ENV['GOOGLE_MAPS_API_KEY'] = 'INVALID_KEY' }
74
-
75
- subject { @exact_match }
76
-
77
- it do
78
- expect(subject.send(:query_url, nil)).to eq(
79
- 'https://maps.googleapis.com/maps/api/geocode/json?address='\
80
- '&sensor=false&key=INVALID_KEY'
81
- )
82
- end
83
- end
84
-
85
- context 'with google returns empty results' do
86
- let(:results_hash) { { 'results' => [] } }
52
+ after { ENV['GOOGLE_MAPS_API_KEY'] = @key }
87
53
 
88
- GoogleMapsGeocoder::ERROR_STATUSES.each do |key, value|
89
- it "raises #{key} error" do
90
- allow_any_instance_of(GoogleMapsGeocoder).to receive(:json_from_url)\
91
- .and_return results_hash.merge('status' => value)
54
+ subject { GoogleMapsGeocoder.new('nowhere that comes to mind') }
92
55
 
93
- expect { GoogleMapsGeocoder.new('anything') }.to \
94
- raise_error(GoogleMapsGeocoder.error_class_name(key))
56
+ it do
57
+ expect { subject }.to raise_error GoogleMapsGeocoder::GeocodingError,
58
+ 'REQUEST_DENIED'
95
59
  end
96
60
  end
97
61
  end
98
62
  end
63
+ # rubocop:enable Metrics/BlockLength
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,17 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
1
+ require 'simplecov'
2
+ SimpleCov.start
3
3
  require 'coveralls'
4
4
  Coveralls.wear!
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- CodeClimate::TestReporter::Formatter,
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
7
6
  Coveralls::SimpleCov::Formatter
8
- ]
7
+ )
9
8
  require 'rubygems'
10
9
  require 'bundler'
11
10
  begin
12
11
  Bundler.setup(:default, :development)
13
12
  rescue Bundler::BundlerError => e
14
- $stderr.puts e.message
15
- $stderr.puts 'Run `bundle install` to install missing gems'
13
+ warn e.message
14
+ warn 'Run `bundle install` to install missing gems'
16
15
  exit e.status_code
17
16
  end
18
17
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
metadata CHANGED
@@ -1,121 +1,124 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_maps_geocoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roderick Monje
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codeclimate-test-reporter
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '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
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '4.2'
90
90
  type: :runtime
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: '0'
96
+ version: '4.2'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rack
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '1.6'
104
104
  type: :runtime
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: '0'
110
+ version: '1.6'
111
111
  description: Geocode a location without worrying about parsing Google Maps' response.
112
112
  GoogleMapsGeocoder wraps it in a plain-old Ruby object.
113
- email:
113
+ email: rod@foveacentral.com
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".document"
119
+ - ".github/CONTRIBUTING.md"
120
+ - ".github/ISSUE_TEMPLATE.md"
121
+ - ".github/PULL_REQUEST_TEMPLATE.md"
119
122
  - ".gitignore"
120
123
  - ".ruby-version"
121
124
  - ".travis.yml"
@@ -129,7 +132,8 @@ files:
129
132
  - spec/lib/google_maps_geocoder_spec.rb
130
133
  - spec/spec_helper.rb
131
134
  homepage: http://github.com/ivanoblomov/google_maps_geocoder
132
- licenses: []
135
+ licenses:
136
+ - MIT
133
137
  metadata: {}
134
138
  post_install_message:
135
139
  rdoc_options: []
@@ -147,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
151
  version: '0'
148
152
  requirements: []
149
153
  rubyforge_project:
150
- rubygems_version: 2.4.5
154
+ rubygems_version: 2.4.5.1
151
155
  signing_key:
152
156
  specification_version: 4
153
157
  summary: A simple PORO wrapper for geocoding with Google Maps.