gmaps_geocoding 0.1.2 → 0.1.3

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: e4f401cb0948ca4d9487429c2797d7c99f26cf15
4
- data.tar.gz: 4634b06d21d151f3090a3322f695f380954950d3
3
+ metadata.gz: fc76d950d8449fc15e4dbee37ec08aca9df79d8a
4
+ data.tar.gz: 1fc6d1a2d2d6d87f768e39d230b0706491e02c96
5
5
  SHA512:
6
- metadata.gz: 576577ecb16e216c6fb744c510b1cc10c933ef3b1132ed396984e0b3d5ac825158e959f55305edab091d880162345f22dfb540cb2fdfff97056bfb403d9b1dcf
7
- data.tar.gz: a0965ae57458ed9671336d737f626ebd53225e8465426b1ceec713a56e3809dc8d930c12c4b6b01b42260d9d378d491854d57c8a5b8f07bb28fa878ba8cee9a0
6
+ metadata.gz: a13cb26c3f40aace1d82aadd52e0ea2452be7f67033c5abd6ed347cd9b40b44e532c3a31c7f70154a04a74712a05e67130639c4574fba1b4cd897ced58cf0477
7
+ data.tar.gz: 1edb3ae0bae8162bf38b3197e9dacb3eba49c160006f40e79e61852ccda6a8cd1adfb2fe8398d0c1d19cf1cd1cd88af3e05428690ec8c1b2b8164d0225cb70e4
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'yajl-ruby', '~> 1.2.0'
26
26
  s.add_runtime_dependency 'nori', '~> 2.3.0'
27
27
  s.add_runtime_dependency 'nokogiri', '~> 1.6.0'
28
- s.add_development_dependency 'bundler', '~> 1.5.3'
28
+ s.add_development_dependency 'bundler', '>= 1.5.3'
29
29
  s.add_development_dependency 'rake'
30
30
  s.add_development_dependency 'yard'
31
31
  end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'logger'
2
3
 
3
4
  module GmapsGeocoding
4
5
  # Google Maps Geocoding Service abstraction class
@@ -11,6 +12,10 @@ module GmapsGeocoding
11
12
  attr_reader :config
12
13
 
13
14
  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
+ end
14
19
  @config = GmapsGeocoding::Config.new(opts)
15
20
  end
16
21
 
@@ -33,15 +38,15 @@ module GmapsGeocoding
33
38
  if @config.valid?
34
39
  rest_client = retrieve_geocoding_data
35
40
  result = case @config.is_json_format?
36
- when true
37
- GmapsGeocoding.from_json(rest_client.to_s)
38
- else
39
- GmapsGeocoding.from_xml(rest_client.to_s)
41
+ when true
42
+ GmapsGeocoding.from_json(rest_client.to_s)
43
+ else
44
+ GmapsGeocoding.from_xml(rest_client.to_s)
40
45
  end
41
46
  return result
42
47
  end
43
48
  rescue => e
44
- puts "[error: gmaps_geocoding]: #{e}"
49
+ @logger.debug "[error: gmaps_geocoding]: #{e}"
45
50
  end
46
51
  nil
47
52
  end
@@ -70,12 +75,12 @@ module GmapsGeocoding
70
75
  data = data_result
71
76
  if data.kind_of?(Array)
72
77
  data.each do |d|
73
- tmp_result["#{d['geometry']['location_type']}"] = {lng: d['geometry']['location']['lng'].to_f,
74
- lat: d['geometry']['location']['lat'].to_f}
78
+ tmp_result["#{d['geometry']['location_type']}"] = { lng: d['geometry']['location']['lng'].to_f,
79
+ lat: d['geometry']['location']['lat'].to_f }
75
80
  end
76
81
  else
77
- tmp_result["#{data['geometry']['location_type']}"] = {lng: data['geometry']['location']['lng'].to_f,
78
- lat: data['geometry']['location']['lat'].to_f}
82
+ tmp_result["#{data['geometry']['location_type']}"] = { lng: data['geometry']['location']['lng'].to_f,
83
+ lat: data['geometry']['location']['lat'].to_f }
79
84
  end
80
85
  if tmp_result.include?('ROOFTOP')
81
86
  [tmp_result['ROOFTOP'][:lng], tmp_result['ROOFTOP'][:lat]]
@@ -99,7 +104,7 @@ module GmapsGeocoding
99
104
  query[:language] = @config.language if @config.language
100
105
  query[:region] = @config.region if @config.region
101
106
  url = "#{@config.url}/#{@config.output}"
102
- {url: url, query: query}
107
+ { url: url, query: query }
103
108
  end
104
109
 
105
110
  def retrieve_geocoding_data
@@ -121,7 +126,7 @@ module GmapsGeocoding
121
126
  if result.include?('GeocodeResponse')
122
127
  result['GeocodeResponse']
123
128
  else
124
- {status: 'UNKNOWN_ERROR'}
129
+ { status: 'UNKNOWN_ERROR' }
125
130
  end
126
131
  end
127
132
  end
@@ -4,7 +4,7 @@ module GmapsGeocoding
4
4
  # Configuration class for GmapsGeocoding API.
5
5
  class Config
6
6
  def initialize(opts = {})
7
- @options = {url: 'https://maps.googleapis.com/maps/api/geocode'}
7
+ @options = { url: 'https://maps.googleapis.com/maps/api/geocode' }
8
8
  @options[:output] = ENV['GOOGLE_MAPS_GEOCODING_OUTPUT'] || opts[:output] || 'json'
9
9
  @options[:address] = ENV['GOOGLE_MAPS_GEOCODING_ADDRESS'] || opts[:address] || ''
10
10
  @options[:latlng] = ENV['GOOGLE_MAPS_GEOCODING_LATLNG'] || opts[:latlng] || ''
@@ -1,3 +1,3 @@
1
1
  module GmapsGeocoding
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -3,6 +3,7 @@ require 'test/unit'
3
3
  require_relative 'test_helper'
4
4
  require 'gmaps_geocoding'
5
5
 
6
+ # Main test class
6
7
  class GmapsGeocodingTest < Test::Unit::TestCase
7
8
  def test_config_default
8
9
  config = GmapsGeocoding::Config.new
@@ -11,30 +12,30 @@ class GmapsGeocodingTest < Test::Unit::TestCase
11
12
  end
12
13
 
13
14
  def test_config_address_set
14
- config = GmapsGeocoding::Config.new({address: 'Tour Eiffel, IDF, Paris, France'})
15
+ config = GmapsGeocoding::Config.new({ address: 'Tour Eiffel, IDF, Paris, France' })
15
16
  assert_not_nil config
16
17
  assert_equal true, config.valid?
17
18
  end
18
19
 
19
20
  def test_config_latlng_set
20
- config = GmapsGeocoding::Config.new({latlng: '40.714224,-73.961452'})
21
+ config = GmapsGeocoding::Config.new({ latlng: '40.714224,-73.961452' })
21
22
  assert_not_nil config
22
23
  assert_equal true, config.valid?
23
24
  end
24
25
 
25
26
  def test_config_address_latlng_set
26
- config = GmapsGeocoding::Config.new({address: 'Tour Eiffel, IDF, Paris, France', latlng: '40.714224,-73.961452'})
27
+ config = GmapsGeocoding::Config.new({ address: 'Tour Eiffel, IDF, Paris, France', latlng: '40.714224,-73.961452' })
27
28
  assert_not_nil config
28
29
  assert_equal false, config.valid?
29
30
  end
30
31
 
31
32
  def test_config_url
32
- config = GmapsGeocoding::Config.new({url: 'http://fakeurl.com'})
33
+ config = GmapsGeocoding::Config.new({ url: 'http://fakeurl.com' })
33
34
  assert_equal 'http://fakeurl.com', config.url
34
35
  end
35
36
 
36
37
  def test_api_json_set
37
- opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'json'}
38
+ opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'json' }
38
39
  api = GmapsGeocoding::Api.new(opts)
39
40
  assert_not_nil api
40
41
 
@@ -49,7 +50,7 @@ class GmapsGeocodingTest < Test::Unit::TestCase
49
50
  end
50
51
 
51
52
  def test_api_xml_set
52
- opts = {address: 'Tour Eiffel, Paris, IDF, France', output: 'xml'}
53
+ opts = { address: 'Tour Eiffel, Paris, IDF, France', output: 'xml' }
53
54
  api = GmapsGeocoding::Api.new(opts)
54
55
  assert_not_nil api
55
56
 
data/test/test_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'simplecov'
2
2
 
3
3
  SimpleCov.start do
4
+ add_filter 'coverage'
5
+ add_filter 'doc'
6
+ add_filter 'pkg'
4
7
  add_filter 'test'
5
8
  end
6
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.2
4
+ version: 0.1.3
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-03-10 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.5.3
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: 1.5.3
83
83
  - !ruby/object:Gem::Dependency