gmaps_geocoding 0.1.4 → 1.0.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: a0762f7a1fae54e8aac3aba8e523b2ea8ab61f68
4
- data.tar.gz: 210e1a48f1305392ed7b9ebb040c33cbf0cbc544
3
+ metadata.gz: 5f019fb274f185c52576b9ca9ec1be88841e5284
4
+ data.tar.gz: 9a39437c2ccd8803efef2a4e43a45339866c0be1
5
5
  SHA512:
6
- metadata.gz: 1e6c4304dd3568cf5580aead51449950a21ae17043b04ba5c1449be48f4eb31909cdf4a47e972287034c59051f64f56b51bddefc1b3de4b2d8ef738573aeae4f
7
- data.tar.gz: ef406b7b18d64cd055edd8baab7bb44e53613d386b9a7368c87c00c4c6ccadf1d64948a67a84387a8151552b7b5465a2e0cb31bd008637095a5851299cf1d17a
6
+ metadata.gz: 6eae47d13d97a317fbc51dca0844e9069a210ac67f4e9328118e12330e96f54758804c9839711ba2826ad40b7af26ca7005e2490aaa4ae302b0b3f11ca313a8e
7
+ data.tar.gz: 478e7fd679a880eda910d489596b88d72cd93812dc2fcc3214e2169bdc477ea259c315ccc1925b035b4ff6fc99c2eae17a4c281fca50782928ab6ef52fec56cd
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ # Reference here: https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
2
+
3
+ Metrics/LineLength:
4
+ Description: 'Limit lines to 310 characters.'
5
+ Enabled: true
6
+ Max: 310
7
+
8
+ Metrics/MethodLength:
9
+ Description: 'Try to avoid methods longer than 50 lines of code.'
10
+ Enabled: true
11
+ Max: 50
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
3
+ - 2.1.5
4
+ - 2.2.1
data/.versions.conf CHANGED
@@ -1,4 +1,4 @@
1
- ruby=ruby-2.1.1
1
+ ruby=ruby-2.2.1
2
2
  ruby-gemset=gmaps_geocoding
3
3
  #ruby-gem-install=bundler rake
4
4
  #ruby-bundle-install=true
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ group :test do
4
+ gem 'simplecov', require: false
5
+ gem 'test-unit'
6
+ gem 'rubocop'
7
+ end
8
+
3
9
  # Specify your gem's dependencies in gmaps_geocoding.gemspec
4
10
  gemspec
5
-
6
- gem 'simplecov', :require => false, :group => :test
data/README.md CHANGED
@@ -37,15 +37,15 @@ All options could be overriden with corresponding environment variable:
37
37
 
38
38
  opts = {address: 'Tour Eiffel, Paris, IDF, France'}
39
39
  api = GmapsGeocoding::Api.new(opts)
40
- data = api.get_location
41
- loc = api.get_finest_latlng(data['results']) if data.include?('status') && data['status'].eql?('OK')
40
+ data = api.location
41
+ loc = api.finest_latlng(data['results']) if data.include?('status') && data['status'].eql?('OK')
42
42
 
43
43
  _Return a location array_
44
44
 
45
45
  * `loc[0] is the longitude float value`
46
46
  * `loc[1] is the latitude float value`
47
47
 
48
- `get_finest_latlng` retrieve the best address in this order:
48
+ `finest_latlng` retrieve the best address in this order:
49
49
 
50
50
  * _ROOFTOP_
51
51
  * _RANGE_INTERPOLATED_
@@ -57,7 +57,16 @@ _Return a location array_
57
57
  # json output example
58
58
  opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
59
59
  api = GmapsGeocoding::Api.new(opts)
60
- result = api.get_location
60
+ result = api.location
61
+
62
+ ### XML example
63
+
64
+ # xml output example
65
+ opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
66
+ api = GmapsGeocoding::Api.new(opts)
67
+ result = api.location
68
+
69
+ # JSON and XML output
61
70
 
62
71
  **Ruby Hash object from json output**
63
72
 
@@ -146,13 +155,6 @@ _Return a location array_
146
155
  "types"=>[]}],
147
156
  "status"=>"OK"}
148
157
 
149
- ### XML example
150
-
151
- # xml output example
152
- opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
153
- api = GmapsGeocoding::Api.new(opts)
154
- result = api.get_location
155
-
156
158
  **Ruby Hash object from xml output**
157
159
 
158
160
  {"status"=>"OK",
data/Rakefile CHANGED
@@ -1,11 +1,9 @@
1
- # encoding: utf-8
2
1
  require 'bundler/gem_tasks'
3
2
  require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
4
  require 'yard'
5
5
 
6
- lib = File.expand_path('../lib/', __FILE__)
7
- $:.unshift lib unless $:.include?(lib)
8
- require('gmaps_geocoding/version')
6
+ require_relative 'lib/gmaps_geocoding/version'
9
7
 
10
8
  task gem: :build
11
9
  task :build do
@@ -20,7 +18,7 @@ task release: :build do
20
18
  system "git tag -a v#{GmapsGeocoding::VERSION} -m 'Tagging #{GmapsGeocoding::VERSION}'"
21
19
  system 'git push --tags'
22
20
  system "gem push gmaps_geocoding-#{GmapsGeocoding::VERSION}.gem"
23
- # system "rm gmaps_geocoding-#{GmapsGeocoding::VERSION}.gem"
21
+ system "rm gmaps_geocoding-#{GmapsGeocoding::VERSION}.gem"
24
22
  end
25
23
 
26
24
  Rake::TestTask.new do |t|
@@ -28,11 +26,15 @@ Rake::TestTask.new do |t|
28
26
  t.test_files = FileList['test/**/*_test.rb']
29
27
  t.verbose = true
30
28
  end
29
+ task default: [:test, :rubocop]
30
+
31
+ RuboCop::RakeTask.new do |task|
32
+ task.formatters = ['simple']
33
+ task.fail_on_error = false
34
+ end
31
35
 
32
36
  desc 'Generate documentation'
33
37
  YARD::Rake::YardocTask.new do |t|
34
- t.files = ['lib/**/*.rb', '-', 'LICENSE.txt']
35
- t.options = ['--main', 'README.md', '--no-private']
38
+ t.files = %w(lib/**/*.rb - LICENSE.txt)
39
+ t.options = %w(--main README.md --no-private)
36
40
  end
37
-
38
- task default: :test
@@ -1,31 +1,30 @@
1
- # encoding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'gmaps_geocoding/version'
1
+ require 'English'
2
+
3
+ require_relative 'lib/gmaps_geocoding/version'
5
4
 
6
5
  Gem::Specification.new do |s|
7
6
  s.name = 'gmaps_geocoding'
8
7
  s.version = GmapsGeocoding::VERSION
9
8
  s.authors = ['Christian Kakesa']
10
9
  s.email = ['christian.kakesa@gmail.com']
11
- s.description = %q{
10
+ s.description = <<-END
12
11
  A simple Ruby gem for Google Maps Geocoding API.
13
12
  This gem return a Ruby Hash object of the result.
14
- }
15
- s.summary = %q{Use Google Geocoding API from Ruby.}
13
+ END
14
+ s.summary = 'Use Google Geocoding API from Ruby.'
16
15
  s.homepage = 'https://github.com/fenicks/gmaps_geocoding'
17
16
  s.license = 'MIT'
18
17
 
19
- s.files = `git ls-files`.split($/)
20
- s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+ s.files = `git ls-files`.split($RS)
19
+ s.executables = s.files.grep(%r{^bin\/}) { |f| File.basename(f) }
20
+ s.test_files = s.files.grep(%r{^(test|spec|features)\/})
22
21
  s.require_paths = ['lib']
23
22
 
24
- s.add_runtime_dependency 'rest-client', '~> 1.6.7'
25
- s.add_runtime_dependency 'yajl-ruby', '~> 1.2.0'
26
- s.add_runtime_dependency 'nori', '~> 2.3.0'
27
- s.add_runtime_dependency 'nokogiri', '~> 1.6.0'
28
- s.add_development_dependency 'bundler', '>= 1.5.3'
23
+ s.add_runtime_dependency 'rest-client', '~> 1.8.0'
24
+ s.add_runtime_dependency 'yajl-ruby', '~> 1.2.1'
25
+ s.add_runtime_dependency 'nori', '~> 2.5.0'
26
+ s.add_runtime_dependency 'nokogiri', '~> 1.6.6'
27
+ s.add_development_dependency 'bundler', '>= 1.8.4'
29
28
  s.add_development_dependency 'rake'
30
29
  s.add_development_dependency 'yard'
31
30
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'gmaps_geocoding/api'
4
2
  require 'gmaps_geocoding/config'
5
3
  require 'gmaps_geocoding/version'
@@ -1,6 +1,9 @@
1
- # encoding: utf-8
2
1
  require 'logger'
2
+ require 'rest-client'
3
+ require 'yajl/json_gem'
4
+ require 'nori'
3
5
 
6
+ # Gmaps geocoding module
4
7
  module GmapsGeocoding
5
8
  # Google Maps Geocoding Service abstraction class
6
9
  #
@@ -12,9 +15,12 @@ module GmapsGeocoding
12
15
  attr_reader :config
13
16
 
14
17
  def initialize(opts = {})
15
- @logger = opts.delete(:logger)||Logger.new(STDERR) do |l|
16
- l.progname = 'gmaps_geocoding'
17
- l.level = $DEBUG ? Logger::DEBUG : Logger::INFO
18
+ @logger = opts.delete(:logger)
19
+ unless @logger
20
+ @logger = Logger.new(STDERR) do |l|
21
+ l.progname = 'gmaps_geocoding'.freeze
22
+ l.level = $DEBUG ? Logger::DEBUG : Logger::INFO
23
+ end
18
24
  end
19
25
  @config = GmapsGeocoding::Config.new(opts)
20
26
  end
@@ -27,26 +33,31 @@ module GmapsGeocoding
27
33
  # # json output example
28
34
  # opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
29
35
  # api = GmapsGeocoding::Api.new(opts)
30
- # result = api.get_location
36
+ # result = api.location
31
37
  # # xml output example
32
38
  # opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
33
39
  # api = GmapsGeocoding::Api.new(opts)
34
- # result = api.get_location
40
+ # result = api.location
35
41
  #
36
- def get_location
42
+ def location
37
43
  begin
38
44
  if @config.valid?
39
45
  rest_client = retrieve_geocoding_data
40
- result = case @config.is_json_format?
46
+ result = case @config.json_format?
41
47
  when true
42
- GmapsGeocoding.from_json(rest_client.to_s)
48
+ Yajl::Parser.parse(rest_client)
43
49
  else
44
- GmapsGeocoding.from_xml(rest_client.to_s)
50
+ r = Nori.new.parse(rest_client)
51
+ if r.include?('GeocodeResponse')
52
+ r['GeocodeResponse']
53
+ else
54
+ { status: 'UNKNOWN_ERROR' }
55
+ end
45
56
  end
46
57
  return result
47
58
  end
48
59
  rescue => e
49
- @logger.error e.to_s
60
+ @logger.error e
50
61
  end
51
62
  nil
52
63
  end
@@ -63,71 +74,51 @@ module GmapsGeocoding
63
74
  # # json output example
64
75
  # opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
65
76
  # api = GmapsGeocoding::Api.new(opts)
66
- # data = api.get_location
77
+ # data = api.location
67
78
  # if data.include?('status') && data['status'].eql?('OK') # or more simple : if data.include?('results')
68
- # return get_finest_latlng(data['results']) # output : [2.291018, 48.857269]
79
+ # return finest_latlng(data['results']) # output : [2.291018, 48.857269]
69
80
  # end
70
81
  #
71
- # @param data_result [Array] The json#results or xml#result array from {#get_location} method
82
+ # @param data [Array] The json#results or xml#result array from {#location} method
72
83
  # @return [Array] array contains latitude and longitude of the location
73
- def get_finest_latlng(data_result)
74
- tmp_result = {}
75
- data = data_result
76
- if data.kind_of?(Array)
77
- data.each do |d|
78
- tmp_result["#{d['geometry']['location_type']}"] = { lng: d['geometry']['location']['lng'].to_f,
79
- lat: d['geometry']['location']['lat'].to_f }
80
- end
81
- else
82
- tmp_result["#{data['geometry']['location_type']}"] = { lng: data['geometry']['location']['lng'].to_f,
83
- lat: data['geometry']['location']['lat'].to_f }
84
- end
85
- if tmp_result.include?('ROOFTOP')
86
- [tmp_result['ROOFTOP'][:lng], tmp_result['ROOFTOP'][:lat]]
87
- elsif tmp_result.include?('RANGE_INTERPOLATED')
88
- [tmp_result['RANGE_INTERPOLATED'][:lng], tmp_result['RANGE_INTERPOLATED'][:lat]]
89
- elsif tmp_result.include?('GEOMETRIC_CENTER')
90
- [tmp_result['GEOMETRIC_CENTER'][:lng], tmp_result['GEOMETRIC_CENTER'][:lat]]
91
- else
92
- [tmp_result['APPROXIMATE'][:lng], tmp_result['APPROXIMATE'][:lat]]
93
- end
84
+ # rubocop:disable Metrics/AbcSize
85
+ def finest_latlng(data)
86
+ result = retrieve_finest_location(data)
87
+ return [result['ROOFTOP'][:lng], result['ROOFTOP'][:lat]] if result.include?('ROOFTOP')
88
+ return [result['RANGE_INTERPOLATED'][:lng], result['RANGE_INTERPOLATED'][:lat]] if result.include?('RANGE_INTERPOLATED')
89
+ return [result['GEOMETRIC_CENTER'][:lng], result['GEOMETRIC_CENTER'][:lat]] if result.include?('GEOMETRIC_CENTER')
90
+ [result['APPROXIMATE'][:lng], result['APPROXIMATE'][:lat]]
91
+ rescue
92
+ [0.0, 0.0]
94
93
  end
94
+ # rubocop:enable Metrics/AbcSize
95
95
 
96
96
  private
97
+
98
+ def retrieve_finest_location(data)
99
+ result = {}
100
+ tmp_data = data
101
+ tmp_data = [tmp_data] unless tmp_data.is_a?(Array)
102
+ tmp_data.each do |d|
103
+ result["#{d['geometry']['location_type']}"] = { lng: d['geometry']['location']['lng'].to_f,
104
+ lat: d['geometry']['location']['lat'].to_f }
105
+ end
106
+ result
107
+ end
108
+
97
109
  def build_url_query
98
110
  query = {}
99
- query[:address] = @config.address if @config.address
100
- query[:latlng] = @config.latlng if @config.latlng
101
- query[:components] = @config.components if @config.components
102
- query[:sensor] = @config.sensor if @config.sensor
103
- query[:bounds] = @config.bounds if @config.bounds
104
- query[:language] = @config.language if @config.language
105
- query[:region] = @config.region if @config.region
111
+ [:address, :latlng, :components, :sensor, :bounds, :language, :region].each do |k|
112
+ val = @config.send(k)
113
+ query[k] = val if val
114
+ end
106
115
  url = "#{@config.url}/#{@config.output}"
107
- { url: url, query: query }
116
+ { url: url, query: query }.freeze
108
117
  end
109
118
 
110
119
  def retrieve_geocoding_data
111
- require 'rest-client'
112
120
  data = build_url_query
113
121
  RestClient.get data[:url], params: data[:query]
114
122
  end
115
123
  end
116
-
117
- class << self
118
- def from_json(json)
119
- require 'yajl/json_gem'
120
- Yajl::Parser.parse(json)
121
- end
122
-
123
- def from_xml(xml)
124
- require 'nori'
125
- result = Nori.new.parse(xml)
126
- if result.include?('GeocodeResponse')
127
- result['GeocodeResponse']
128
- else
129
- { status: 'UNKNOWN_ERROR' }
130
- end
131
- end
132
- end
133
124
  end
@@ -1,19 +1,29 @@
1
- # encoding: utf-8
2
-
1
+ # Gmaps geocoding module
3
2
  module GmapsGeocoding
4
3
  # Configuration class for GmapsGeocoding API.
5
4
  class Config
5
+ # Configuration valid keys
6
+ VALID_KEYS = [:url, :output, :address, :latlng, :components, :sensor, :bounds, :language, :region].freeze
7
+
8
+ # Default configuration values
9
+ DEFAULT_CONFIG = {
10
+ url: 'https://maps.googleapis.com/maps/api/geocode',
11
+ output: 'json',
12
+ sensor: 'false'
13
+ }.freeze
14
+
6
15
  def initialize(opts = {})
7
- @options = { url: 'https://maps.googleapis.com/maps/api/geocode' }
8
- @options[:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json'
9
- @options[:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || ''
10
- @options[:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || ''
11
- @options[:components] = ENV['GOOGLE_MAPS_GEOCODING_COMPONENTS'] || opts[:components] || ''
12
- @options[:sensor] = ENV['GOOGLE_MAPS_GEOCODING_SENSOR'] || opts[:sensor] || 'false'
13
- @options[:bounds] = ENV['GOOGLE_MAPS_GEOCODING_BOUNDS'] || opts[:bounds] || ''
14
- @options[:language] = ENV['GOOGLE_MAPS_GEOCODING_LANGUAGE'] || opts[:language] || ''
15
- @options[:region] = ENV['GOOGLE_MAPS_GEOCODING_REGION'] || opts[:region] || ''
16
- @options.merge!(opts).reject! { |_, v| v.to_s.length == 0 }
16
+ @options = {}
17
+ @options.merge!(DEFAULT_CONFIG)
18
+ opts.each do |k, _|
19
+ next unless VALID_KEYS.include?(k)
20
+ val = if k.eql?(:url)
21
+ opts.delete(k)
22
+ else
23
+ ENV["GOOGLE_MAPS_GEOCODING_#{k.to_s.upcase}"] || opts.delete(k)
24
+ end
25
+ @options[k] = val if val
26
+ end
17
27
  end
18
28
 
19
29
  # URL of the Google Maps Geocoding Service
@@ -89,37 +99,38 @@ module GmapsGeocoding
89
99
  #
90
100
  # @return [true, false] Return _true_ or _false_
91
101
  def valid?
92
- is_query_valid? && is_output_param_valid?
102
+ query_valid? && output_param_valid?
93
103
  end
94
104
 
95
105
  # Check if the output format of the query is set to _json_
96
106
  #
97
107
  # @return [true, false] Return _true_ or _false_
98
- def is_json_format?
108
+ def json_format?
99
109
  'json'.eql?(output)
100
110
  end
101
111
 
102
112
  # Check if the output format of the query is set to _xml_
103
113
  #
104
114
  # @return [true, false] Return _true_ or _false_
105
- def is_xml_format?
115
+ def xml_format?
106
116
  'xml'.eql?(output)
107
117
  end
108
118
 
109
119
  private
120
+
110
121
  # Check if the query is valid
111
122
  #
112
123
  # According to the specifications: {https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests}
113
- def is_query_valid?
114
- (@options[:address].to_s.length > 0 && @options[:latlng].to_s.length == 0) ||
115
- (@options[:address].to_s.length == 0 && @options[:latlng].to_s.length > 0) ||
116
- (@options[:components].to_s.length > 0)
124
+ def query_valid?
125
+ (@options.include?(:address) && !@options.include?(:latlng)) ||
126
+ (!@options.include?(:address) && @options.include?(:latlng)) ||
127
+ @options.include?(:components)
117
128
  end
118
129
 
119
130
  # Check if the output format is valid
120
131
  #
121
132
  # According to the specifications: {https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses}
122
- def is_output_param_valid?
133
+ def output_param_valid?
123
134
  %w(json xml).include?(output)
124
135
  end
125
136
  end
@@ -1,3 +1,5 @@
1
+ # rubocop:disable Style/Documentation
1
2
  module GmapsGeocoding
2
- VERSION = '0.1.4'
3
+ # GmapsGeocoding version
4
+ VERSION = '1.0.0'.freeze
3
5
  end
@@ -0,0 +1,36 @@
1
+
2
+ require_relative '../lib/gmaps_geocoding'
3
+ require_relative 'test_helper'
4
+
5
+ # Main test class
6
+ class GmapsGeocodingApiTest < Test::Unit::TestCase
7
+ def test_api_json_set
8
+ opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'json' }
9
+ api = GmapsGeocoding::Api.new(opts)
10
+ assert_not_nil api
11
+
12
+ result_location = api.location
13
+ assert_not_nil result_location
14
+ assert_kind_of Hash, result_location
15
+ assert_include result_location, 'results'
16
+
17
+ result_latlng = api.finest_latlng(result_location['results'])
18
+ assert_not_nil result_latlng
19
+ assert_instance_of Array, result_latlng
20
+ end
21
+
22
+ def test_api_xml_set
23
+ opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'xml' }
24
+ api = GmapsGeocoding::Api.new(opts)
25
+ assert_not_nil api
26
+
27
+ result_location = api.location
28
+ assert_not_nil result_location
29
+ assert_kind_of Hash, result_location
30
+ assert_include result_location, 'result'
31
+
32
+ result_latlng = api.finest_latlng(result_location['result'])
33
+ assert_not_nil result_latlng
34
+ assert_instance_of Array, result_latlng
35
+ end
36
+ end
@@ -0,0 +1,57 @@
1
+ require_relative '../lib/gmaps_geocoding'
2
+ require_relative 'test_helper'
3
+
4
+ # Main test class
5
+ class GmapsGeocodingConfigTest < Test::Unit::TestCase
6
+ def test_config_default
7
+ config = GmapsGeocoding::Config.new
8
+ assert_not_nil config
9
+
10
+ assert_equal false, config.valid?
11
+ assert_equal true, config.json_format?
12
+ assert_equal false, config.xml_format?
13
+ end
14
+
15
+ def test_config_default_address
16
+ config = GmapsGeocoding::Config.new
17
+ assert_not_nil config
18
+
19
+ assert_equal true, config.url.size > 0
20
+ assert_equal 'json', config.output
21
+ assert_nil config.address
22
+ end
23
+
24
+ def test_config_default_optional
25
+ config = GmapsGeocoding::Config.new
26
+ assert_not_nil config
27
+ assert_nil config.latlng
28
+ assert_nil config.components
29
+ assert_equal 'false', config.sensor
30
+ assert_nil config.bounds
31
+ assert_nil config.language
32
+ assert_nil config.region
33
+ end
34
+
35
+ def test_config_address_set
36
+ config = GmapsGeocoding::Config.new(address: 'Tour Eiffel, IDF, Paris, France')
37
+ assert_not_nil config
38
+ assert_equal true, config.valid?
39
+ end
40
+
41
+ def test_config_latlng_set
42
+ config = GmapsGeocoding::Config.new(latlng: '40.714224,-73.961452')
43
+ assert_not_nil config
44
+ assert_equal true, config.valid?
45
+ end
46
+
47
+ def test_config_address_latlng_set
48
+ config = GmapsGeocoding::Config.new(address: 'Tour Eiffel, IDF, Paris, France', latlng: '40.714224,-73.961452')
49
+ assert_not_nil config
50
+ assert_equal false, config.valid?
51
+ end
52
+
53
+ def test_config_url
54
+ config = GmapsGeocoding::Config.new(url: 'http://fakeurl.com')
55
+ assert_equal 'http://fakeurl.com', config.url
56
+ end
57
+ end
data/test/test_helper.rb CHANGED
@@ -1,9 +1,6 @@
1
+ require 'test/unit'
1
2
  require 'simplecov'
2
3
 
3
4
  SimpleCov.start do
4
- add_filter 'coverage'
5
- add_filter 'doc'
6
- add_filter 'pkg'
7
- add_filter 'test'
5
+ add_filter '/test/'
8
6
  end
9
- SimpleCov.command_name 'Unit Tests'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmaps_geocoding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-29 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,70 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.7
19
+ version: 1.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.7
26
+ version: 1.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yajl-ruby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.0
33
+ version: 1.2.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.0
40
+ version: 1.2.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: nori
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.3.0
47
+ version: 2.5.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.3.0
54
+ version: 2.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.6.0
61
+ version: 1.6.6
62
62
  type: :runtime
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: 1.6.0
68
+ version: 1.6.6
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.5.3
75
+ version: 1.8.4
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: 1.5.3
82
+ version: 1.8.4
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,8 +108,9 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: "\n A simple Ruby gem for Google Maps Geocoding API.\n This gem
112
- return a Ruby Hash object of the result.\n "
111
+ description: |2
112
+ A simple Ruby gem for Google Maps Geocoding API.
113
+ This gem return a Ruby Hash object of the result.
113
114
  email:
114
115
  - christian.kakesa@gmail.com
115
116
  executables: []
@@ -117,6 +118,7 @@ extensions: []
117
118
  extra_rdoc_files: []
118
119
  files:
119
120
  - ".gitignore"
121
+ - ".rubocop.yml"
120
122
  - ".travis.yml"
121
123
  - ".versions.conf"
122
124
  - ".yardopts"
@@ -129,7 +131,8 @@ files:
129
131
  - lib/gmaps_geocoding/api.rb
130
132
  - lib/gmaps_geocoding/config.rb
131
133
  - lib/gmaps_geocoding/version.rb
132
- - test/gmaps_geocoding_test.rb
134
+ - test/gmaps_geocoding_api_test.rb
135
+ - test/gmaps_geocoding_config_test.rb
133
136
  - test/test_helper.rb
134
137
  homepage: https://github.com/fenicks/gmaps_geocoding
135
138
  licenses:
@@ -151,11 +154,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
154
  version: '0'
152
155
  requirements: []
153
156
  rubyforge_project:
154
- rubygems_version: 2.2.2
157
+ rubygems_version: 2.4.6
155
158
  signing_key:
156
159
  specification_version: 4
157
160
  summary: Use Google Geocoding API from Ruby.
158
161
  test_files:
159
- - test/gmaps_geocoding_test.rb
162
+ - test/gmaps_geocoding_api_test.rb
163
+ - test/gmaps_geocoding_config_test.rb
160
164
  - test/test_helper.rb
161
165
  has_rdoc:
@@ -1,66 +0,0 @@
1
- # encoding: utf-8
2
- require 'test/unit'
3
- require_relative 'test_helper'
4
- require 'gmaps_geocoding'
5
-
6
- # Main test class
7
- class GmapsGeocodingTest < Test::Unit::TestCase
8
- def test_config_default
9
- config = GmapsGeocoding::Config.new
10
- assert_not_nil config
11
- assert_equal false, config.valid?
12
- end
13
-
14
- def test_config_address_set
15
- config = GmapsGeocoding::Config.new({ address: 'Tour Eiffel, IDF, Paris, France' })
16
- assert_not_nil config
17
- assert_equal true, config.valid?
18
- end
19
-
20
- def test_config_latlng_set
21
- config = GmapsGeocoding::Config.new({ latlng: '40.714224,-73.961452' })
22
- assert_not_nil config
23
- assert_equal true, config.valid?
24
- end
25
-
26
- def test_config_address_latlng_set
27
- config = GmapsGeocoding::Config.new({ address: 'Tour Eiffel, IDF, Paris, France', latlng: '40.714224,-73.961452' })
28
- assert_not_nil config
29
- assert_equal false, config.valid?
30
- end
31
-
32
- def test_config_url
33
- config = GmapsGeocoding::Config.new({ url: 'http://fakeurl.com' })
34
- assert_equal 'http://fakeurl.com', config.url
35
- end
36
-
37
- def test_api_json_set
38
- opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'json' }
39
- api = GmapsGeocoding::Api.new(opts)
40
- assert_not_nil api
41
-
42
- result_location = api.get_location
43
- assert_not_nil result_location
44
- assert_kind_of Hash, result_location
45
- assert_include result_location, 'results'
46
-
47
- result_latlng = api.get_finest_latlng(result_location['results'])
48
- assert_not_nil result_latlng
49
- assert_instance_of Array, result_latlng
50
- end
51
-
52
- def test_api_xml_set
53
- opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'xml' }
54
- api = GmapsGeocoding::Api.new(opts)
55
- assert_not_nil api
56
-
57
- result_location = api.get_location
58
- assert_not_nil result_location
59
- assert_kind_of Hash, result_location
60
- assert_include result_location, 'result'
61
-
62
- result_latlng = api.get_finest_latlng(result_location['result'])
63
- assert_not_nil result_latlng
64
- assert_instance_of Array, result_latlng
65
- end
66
- end