greatseth-google-geo 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. data/CHANGELOG +3 -0
  2. data/LICENSE +19 -0
  3. data/Manifest +67 -0
  4. data/README +35 -0
  5. data/Rakefile +10 -0
  6. data/google-geo.gemspec +139 -0
  7. data/lib/google/geo.rb +194 -0
  8. data/test/fixtures/invalid_map_key.xml +10 -0
  9. data/test/fixtures/missing_address.xml +10 -0
  10. data/test/fixtures/server_error.xml +10 -0
  11. data/test/fixtures/success.xml +36 -0
  12. data/test/fixtures/success_with_multiple_addresses.xml +62 -0
  13. data/test/fixtures/too_many_queries.xml +10 -0
  14. data/test/fixtures/unavailable_address.xml +10 -0
  15. data/test/fixtures/unknown_address.xml +10 -0
  16. data/test/geo_test.rb +102 -0
  17. data/vendor/mocha-0.4.0/COPYING +3 -0
  18. data/vendor/mocha-0.4.0/MIT-LICENSE +7 -0
  19. data/vendor/mocha-0.4.0/README +35 -0
  20. data/vendor/mocha-0.4.0/RELEASE +98 -0
  21. data/vendor/mocha-0.4.0/Rakefile +126 -0
  22. data/vendor/mocha-0.4.0/examples/misc.rb +36 -0
  23. data/vendor/mocha-0.4.0/examples/mocha.rb +26 -0
  24. data/vendor/mocha-0.4.0/examples/stubba.rb +65 -0
  25. data/vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb +35 -0
  26. data/vendor/mocha-0.4.0/lib/mocha/auto_verify.rb +113 -0
  27. data/vendor/mocha-0.4.0/lib/mocha/central.rb +35 -0
  28. data/vendor/mocha-0.4.0/lib/mocha/class_method.rb +62 -0
  29. data/vendor/mocha-0.4.0/lib/mocha/expectation.rb +295 -0
  30. data/vendor/mocha-0.4.0/lib/mocha/expectation_error.rb +6 -0
  31. data/vendor/mocha-0.4.0/lib/mocha/infinite_range.rb +27 -0
  32. data/vendor/mocha-0.4.0/lib/mocha/inspect.rb +37 -0
  33. data/vendor/mocha-0.4.0/lib/mocha/instance_method.rb +8 -0
  34. data/vendor/mocha-0.4.0/lib/mocha/metaclass.rb +7 -0
  35. data/vendor/mocha-0.4.0/lib/mocha/mock.rb +20 -0
  36. data/vendor/mocha-0.4.0/lib/mocha/mock_methods.rb +122 -0
  37. data/vendor/mocha-0.4.0/lib/mocha/object.rb +100 -0
  38. data/vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb +28 -0
  39. data/vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb +23 -0
  40. data/vendor/mocha-0.4.0/lib/mocha/standalone.rb +30 -0
  41. data/vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb +49 -0
  42. data/vendor/mocha-0.4.0/lib/mocha.rb +19 -0
  43. data/vendor/mocha-0.4.0/lib/mocha_standalone.rb +2 -0
  44. data/vendor/mocha-0.4.0/lib/stubba.rb +2 -0
  45. data/vendor/mocha-0.4.0/test/active_record_test_case.rb +36 -0
  46. data/vendor/mocha-0.4.0/test/all_tests.rb +75 -0
  47. data/vendor/mocha-0.4.0/test/execution_point.rb +34 -0
  48. data/vendor/mocha-0.4.0/test/method_definer.rb +18 -0
  49. data/vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb +124 -0
  50. data/vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb +163 -0
  51. data/vendor/mocha-0.4.0/test/mocha/central_test.rb +124 -0
  52. data/vendor/mocha-0.4.0/test/mocha/class_method_test.rb +196 -0
  53. data/vendor/mocha-0.4.0/test/mocha/expectation_test.rb +357 -0
  54. data/vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb +50 -0
  55. data/vendor/mocha-0.4.0/test/mocha/inspect_test.rb +90 -0
  56. data/vendor/mocha-0.4.0/test/mocha/metaclass_test.rb +22 -0
  57. data/vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb +235 -0
  58. data/vendor/mocha-0.4.0/test/mocha/mock_test.rb +84 -0
  59. data/vendor/mocha-0.4.0/test/mocha/object_test.rb +165 -0
  60. data/vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb +32 -0
  61. data/vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb +76 -0
  62. data/vendor/mocha-0.4.0/test/mocha_acceptance_test.rb +98 -0
  63. data/vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb +105 -0
  64. data/vendor/mocha-0.4.0/test/standalone_acceptance_test.rb +110 -0
  65. data/vendor/mocha-0.4.0/test/stubba_acceptance_test.rb +102 -0
  66. data/vendor/mocha-0.4.0/test/stubba_integration_test.rb +89 -0
  67. data/vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb +85 -0
  68. data/vendor/mocha-0.4.0/test/test_helper.rb +4 -0
  69. metadata +136 -0
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ v2.0. Multiple Addresses (and tests you can actually run!); Not insignificant API change: *** Google::Geo#locate ALWAYS RETURNS AN ARRAY ***; There are now some nice examples in the README; Updated to include the fixtures and vendor dependencies for tests, yeknow, so you can actually run them; No namby pamby point releases. This is serious, folks.
2
+
3
+ v1.0. Initial Release
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ This program is free software. It comes without any warranty, to
2
+ the extent permitted by applicable law. You can redistribute it
3
+ and/or modify it under the terms of the Do What The Fuck You Want
4
+ To Public License, Version 2, as published by Sam Hocevar. See
5
+ http://sam.zoy.org/wtfpl/COPYING for more details.
6
+
7
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
8
+ Version 2, December 2004
9
+
10
+ Copyright (C) 2004 Sam Hocevar
11
+ 14 rue de Plaisance, 75014 Paris, France
12
+ Everyone is permitted to copy and distribute verbatim or modified
13
+ copies of this license document, and changing it is allowed as long
14
+ as the name is changed.
15
+
16
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
17
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
18
+
19
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/Manifest ADDED
@@ -0,0 +1,67 @@
1
+ CHANGELOG
2
+ lib/google/geo.rb
3
+ LICENSE
4
+ Rakefile
5
+ README
6
+ test/fixtures/invalid_map_key.xml
7
+ test/fixtures/missing_address.xml
8
+ test/fixtures/server_error.xml
9
+ test/fixtures/success.xml
10
+ test/fixtures/success_with_multiple_addresses.xml
11
+ test/fixtures/too_many_queries.xml
12
+ test/fixtures/unavailable_address.xml
13
+ test/fixtures/unknown_address.xml
14
+ test/geo_test.rb
15
+ vendor/mocha-0.4.0/COPYING
16
+ vendor/mocha-0.4.0/examples/misc.rb
17
+ vendor/mocha-0.4.0/examples/mocha.rb
18
+ vendor/mocha-0.4.0/examples/stubba.rb
19
+ vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
20
+ vendor/mocha-0.4.0/lib/mocha/auto_verify.rb
21
+ vendor/mocha-0.4.0/lib/mocha/central.rb
22
+ vendor/mocha-0.4.0/lib/mocha/class_method.rb
23
+ vendor/mocha-0.4.0/lib/mocha/expectation.rb
24
+ vendor/mocha-0.4.0/lib/mocha/expectation_error.rb
25
+ vendor/mocha-0.4.0/lib/mocha/infinite_range.rb
26
+ vendor/mocha-0.4.0/lib/mocha/inspect.rb
27
+ vendor/mocha-0.4.0/lib/mocha/instance_method.rb
28
+ vendor/mocha-0.4.0/lib/mocha/metaclass.rb
29
+ vendor/mocha-0.4.0/lib/mocha/mock.rb
30
+ vendor/mocha-0.4.0/lib/mocha/mock_methods.rb
31
+ vendor/mocha-0.4.0/lib/mocha/object.rb
32
+ vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb
33
+ vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb
34
+ vendor/mocha-0.4.0/lib/mocha/standalone.rb
35
+ vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb
36
+ vendor/mocha-0.4.0/lib/mocha.rb
37
+ vendor/mocha-0.4.0/lib/mocha_standalone.rb
38
+ vendor/mocha-0.4.0/lib/stubba.rb
39
+ vendor/mocha-0.4.0/MIT-LICENSE
40
+ vendor/mocha-0.4.0/Rakefile
41
+ vendor/mocha-0.4.0/README
42
+ vendor/mocha-0.4.0/RELEASE
43
+ vendor/mocha-0.4.0/test/active_record_test_case.rb
44
+ vendor/mocha-0.4.0/test/all_tests.rb
45
+ vendor/mocha-0.4.0/test/execution_point.rb
46
+ vendor/mocha-0.4.0/test/method_definer.rb
47
+ vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb
48
+ vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb
49
+ vendor/mocha-0.4.0/test/mocha/central_test.rb
50
+ vendor/mocha-0.4.0/test/mocha/class_method_test.rb
51
+ vendor/mocha-0.4.0/test/mocha/expectation_test.rb
52
+ vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb
53
+ vendor/mocha-0.4.0/test/mocha/inspect_test.rb
54
+ vendor/mocha-0.4.0/test/mocha/metaclass_test.rb
55
+ vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb
56
+ vendor/mocha-0.4.0/test/mocha/mock_test.rb
57
+ vendor/mocha-0.4.0/test/mocha/object_test.rb
58
+ vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb
59
+ vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb
60
+ vendor/mocha-0.4.0/test/mocha_acceptance_test.rb
61
+ vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb
62
+ vendor/mocha-0.4.0/test/standalone_acceptance_test.rb
63
+ vendor/mocha-0.4.0/test/stubba_acceptance_test.rb
64
+ vendor/mocha-0.4.0/test/stubba_integration_test.rb
65
+ vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb
66
+ vendor/mocha-0.4.0/test/test_helper.rb
67
+ Manifest
data/README ADDED
@@ -0,0 +1,35 @@
1
+ = Google::Geo
2
+
3
+ A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
4
+
5
+ == Examples
6
+
7
+ geo = Google::Geo.new API_KEY
8
+
9
+ addresses = geo.locate '1600 Amphitheatre Parkway, Mountain View, CA'
10
+
11
+ addresses.size # 1, :locate always returns an Array
12
+
13
+ address = addresses.first
14
+
15
+ address.country # 'US'
16
+ address.city # 'Mountain View'
17
+ address.full_address # '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA'
18
+
19
+ address.query # '1600 Amphitheatre Parkway, Mountain View, CA'
20
+ address.accuracy # 8
21
+
22
+ In the case of sufficiently vague queries, Google::Geo will return more than one:
23
+
24
+ addresses = geo.locate 'hell'
25
+
26
+ addresses.size # 2
27
+ addresses.map { |a| a.state } # ['PA', 'NC']
28
+
29
+ == Contributors
30
+
31
+ Seth Thomas Rasmussen - http://greatseth.com - sethrasmussen@gmail.com
32
+
33
+ == License
34
+
35
+ (c) 2007-2008 Seth Thomas Rasmussen and released under the WTFPL. See the LICENSE file for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ README = File.readlines "#{File.dirname __FILE__}/README"
2
+
3
+ require "echoe"
4
+
5
+ Echoe.new "google-geo" do |p|
6
+ p.author = "Seth Thomas Rasmussen"
7
+ p.email = "sethrasmussen@gmail.com"
8
+ p.url = "http://github.com/greatseth/google-geo"
9
+ p.summary = README[2]
10
+ end
@@ -0,0 +1,139 @@
1
+
2
+ # Gem::Specification for Google-geo-2.0
3
+ # Originally generated by Echoe
4
+
5
+ --- !ruby/object:Gem::Specification
6
+ name: google-geo
7
+ version: !ruby/object:Gem::Version
8
+ version: "2.0"
9
+ platform: ruby
10
+ authors:
11
+ - Seth Thomas Rasmussen
12
+ autorequire:
13
+ bindir: bin
14
+
15
+ date: 2008-08-06 00:00:00 -07:00
16
+ default_executable:
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: echoe
20
+ type: :development
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ version:
28
+ description: A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
29
+ email: sethrasmussen@gmail.com
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - CHANGELOG
36
+ - lib/google/geo.rb
37
+ - LICENSE
38
+ - README
39
+ files:
40
+ - CHANGELOG
41
+ - lib/google/geo.rb
42
+ - LICENSE
43
+ - Rakefile
44
+ - README
45
+ - test/fixtures/invalid_map_key.xml
46
+ - test/fixtures/missing_address.xml
47
+ - test/fixtures/server_error.xml
48
+ - test/fixtures/success.xml
49
+ - test/fixtures/success_with_multiple_addresses.xml
50
+ - test/fixtures/too_many_queries.xml
51
+ - test/fixtures/unavailable_address.xml
52
+ - test/fixtures/unknown_address.xml
53
+ - test/geo_test.rb
54
+ - vendor/mocha-0.4.0/COPYING
55
+ - vendor/mocha-0.4.0/examples/misc.rb
56
+ - vendor/mocha-0.4.0/examples/mocha.rb
57
+ - vendor/mocha-0.4.0/examples/stubba.rb
58
+ - vendor/mocha-0.4.0/lib/mocha/any_instance_method.rb
59
+ - vendor/mocha-0.4.0/lib/mocha/auto_verify.rb
60
+ - vendor/mocha-0.4.0/lib/mocha/central.rb
61
+ - vendor/mocha-0.4.0/lib/mocha/class_method.rb
62
+ - vendor/mocha-0.4.0/lib/mocha/expectation.rb
63
+ - vendor/mocha-0.4.0/lib/mocha/expectation_error.rb
64
+ - vendor/mocha-0.4.0/lib/mocha/infinite_range.rb
65
+ - vendor/mocha-0.4.0/lib/mocha/inspect.rb
66
+ - vendor/mocha-0.4.0/lib/mocha/instance_method.rb
67
+ - vendor/mocha-0.4.0/lib/mocha/metaclass.rb
68
+ - vendor/mocha-0.4.0/lib/mocha/mock.rb
69
+ - vendor/mocha-0.4.0/lib/mocha/mock_methods.rb
70
+ - vendor/mocha-0.4.0/lib/mocha/object.rb
71
+ - vendor/mocha-0.4.0/lib/mocha/pretty_parameters.rb
72
+ - vendor/mocha-0.4.0/lib/mocha/setup_and_teardown.rb
73
+ - vendor/mocha-0.4.0/lib/mocha/standalone.rb
74
+ - vendor/mocha-0.4.0/lib/mocha/test_case_adapter.rb
75
+ - vendor/mocha-0.4.0/lib/mocha.rb
76
+ - vendor/mocha-0.4.0/lib/mocha_standalone.rb
77
+ - vendor/mocha-0.4.0/lib/stubba.rb
78
+ - vendor/mocha-0.4.0/MIT-LICENSE
79
+ - vendor/mocha-0.4.0/Rakefile
80
+ - vendor/mocha-0.4.0/README
81
+ - vendor/mocha-0.4.0/RELEASE
82
+ - vendor/mocha-0.4.0/test/active_record_test_case.rb
83
+ - vendor/mocha-0.4.0/test/all_tests.rb
84
+ - vendor/mocha-0.4.0/test/execution_point.rb
85
+ - vendor/mocha-0.4.0/test/method_definer.rb
86
+ - vendor/mocha-0.4.0/test/mocha/any_instance_method_test.rb
87
+ - vendor/mocha-0.4.0/test/mocha/auto_verify_test.rb
88
+ - vendor/mocha-0.4.0/test/mocha/central_test.rb
89
+ - vendor/mocha-0.4.0/test/mocha/class_method_test.rb
90
+ - vendor/mocha-0.4.0/test/mocha/expectation_test.rb
91
+ - vendor/mocha-0.4.0/test/mocha/infinite_range_test.rb
92
+ - vendor/mocha-0.4.0/test/mocha/inspect_test.rb
93
+ - vendor/mocha-0.4.0/test/mocha/metaclass_test.rb
94
+ - vendor/mocha-0.4.0/test/mocha/mock_methods_test.rb
95
+ - vendor/mocha-0.4.0/test/mocha/mock_test.rb
96
+ - vendor/mocha-0.4.0/test/mocha/object_test.rb
97
+ - vendor/mocha-0.4.0/test/mocha/pretty_parameters_test.rb
98
+ - vendor/mocha-0.4.0/test/mocha/setup_and_teardown_test.rb
99
+ - vendor/mocha-0.4.0/test/mocha_acceptance_test.rb
100
+ - vendor/mocha-0.4.0/test/mocha_test_result_integration_test.rb
101
+ - vendor/mocha-0.4.0/test/standalone_acceptance_test.rb
102
+ - vendor/mocha-0.4.0/test/stubba_acceptance_test.rb
103
+ - vendor/mocha-0.4.0/test/stubba_integration_test.rb
104
+ - vendor/mocha-0.4.0/test/stubba_test_result_integration_test.rb
105
+ - vendor/mocha-0.4.0/test/test_helper.rb
106
+ - Manifest
107
+ - google-geo.gemspec
108
+ has_rdoc: true
109
+ homepage: http://github.com/greatseth/google-geo
110
+ post_install_message:
111
+ rdoc_options:
112
+ - --line-numbers
113
+ - --inline-source
114
+ - --title
115
+ - Google-geo
116
+ - --main
117
+ - README
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ version:
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "="
129
+ - !ruby/object:Gem::Version
130
+ version: "1.2"
131
+ version:
132
+ requirements: []
133
+
134
+ rubyforge_project: google-geo
135
+ rubygems_version: 1.2.0
136
+ specification_version: 2
137
+ summary: A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
138
+ test_files:
139
+ - test/geo_test.rb
data/lib/google/geo.rb ADDED
@@ -0,0 +1,194 @@
1
+ require 'open-uri'
2
+
3
+ module Google
4
+
5
+ # = Google::Geo
6
+ #
7
+ # A simple, elegant library for getting geocoding information from Google Maps. Very much inspired by the google-geocode gem, but completely dependency free!
8
+ #
9
+ # == Examples
10
+ #
11
+ # geo = Google::Geo.new API_KEY
12
+ #
13
+ # addresses = geo.locate '1600 Amphitheatre Parkway, Mountain View, CA'
14
+ #
15
+ # addresses.size # 1, :locate always returns an Array
16
+ #
17
+ # address = addresses.first
18
+ #
19
+ # address.country # 'US'
20
+ # address.city # 'Mountain View'
21
+ # address.full_address # '1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA'
22
+ #
23
+ # address.query # '1600 Amphitheatre Parkway, Mountain View, CA'
24
+ # address.accuracy # 8
25
+ #
26
+ # In the case of sufficiently vague queries, Google will return more than one address:
27
+ #
28
+ # addresses = geo.locate 'heaven'
29
+ #
30
+ # addresses.size # 2
31
+ # addresses.map { |a| a.state } # ['PA', 'NC']
32
+ #
33
+ # == Contributors
34
+ #
35
+ # Seth Thomas Rasmussen - http://greatseth.com - sethrasmussen@gmail.com
36
+ class Geo
37
+ # API key provided by Google allowing access to the Geocode API
38
+ attr_accessor :key
39
+
40
+ def initialize(key)
41
+ @key = key
42
+ end
43
+
44
+ # Returns an array of Address objects, each with accessors for all the components of a location.
45
+ # The query argument should be a string.
46
+ def locate(query)
47
+ xml = open(uri(query)).read
48
+ res = Response.new(xml, key)
49
+
50
+ res.placemarks.map { |place| Address.new place, res.query }
51
+ end
52
+
53
+ # Generate a request URI from a given search string.
54
+ def uri(address) #:nodoc:
55
+ "http://maps.google.com/maps/geo?q=#{URI.escape address}&key=#{key}&output=xml"
56
+ end
57
+ private :uri
58
+
59
+ ###
60
+
61
+ module Parser #:nodoc:
62
+ # Fetch contents of an XML element of the response.
63
+ def fetch(element) #:nodoc:
64
+ @xml.slice %r{<#{element}>(.+?)</#{element}>}, 1
65
+ end
66
+
67
+ # Like fetch, but for the only piece of data locked away in an attribute.
68
+ def fetch_accuracy #:nodoc:
69
+ @xml.slice(%r{Accuracy="([^"]+)">}, 1).to_i
70
+ end
71
+ end
72
+
73
+ ###
74
+
75
+ # Represents locations returned in response to geocoding queries.
76
+ class Address
77
+ include Parser
78
+
79
+ attr_reader :street
80
+ alias :thoroughfare :street
81
+
82
+ attr_reader :city
83
+ alias :locality :city
84
+
85
+ attr_reader :zip
86
+ alias :postal_code :zip
87
+
88
+ attr_reader :county
89
+ alias :subadministrative_area :county
90
+
91
+ attr_reader :state
92
+ alias :administrative_area :state
93
+
94
+ attr_reader :country
95
+ alias :country_code :country
96
+
97
+ # An array containing the standard three elements of a coordinate triple: latitude, longitude, elevation.
98
+ attr_reader :coordinates
99
+
100
+ # A float, the standard first element of a coordinate triple.
101
+ attr_reader :longitude
102
+ alias :lng :longitude
103
+
104
+ # A float, the standard second element of a coordinate triple.
105
+ attr_reader :latitude
106
+ alias :lat :latitude
107
+
108
+ # A float, the standard third element of a coordinate triple.
109
+ attr_reader :elevation
110
+
111
+ # An integer, Google's rating of the accuracy of the supplied address.
112
+ attr_reader :accuracy
113
+
114
+ # All address attributes as one string, formatted by the service.
115
+ attr_reader :full_address
116
+ alias :to_s :full_address
117
+
118
+ # The address query sent to the service. i.e. The user input.
119
+ attr_reader :query
120
+
121
+ def initialize(placemark, query) #:nodoc
122
+ @xml = placemark
123
+ @query = query
124
+
125
+ {
126
+ :@street => :ThoroughfareName,
127
+ :@city => :LocalityName,
128
+ :@zip => :PostalCodeNumber,
129
+ :@county => :SubAdministrativeAreaName,
130
+ :@state => :AdministrativeAreaName,
131
+ :@country => :CountryNameCode,
132
+
133
+ :@full_address => :address
134
+ }.each do |attribute, element|
135
+ instance_variable_set(attribute, (fetch(element) rescue nil))
136
+ end
137
+
138
+ @longitude, @latitude, @elevation = @coordinates = fetch(:coordinates).split(',').map { |x| x.to_f }
139
+
140
+ @accuracy = fetch_accuracy
141
+ end
142
+ end
143
+
144
+ ###
145
+
146
+ class Response #:nodoc:
147
+ include Parser
148
+
149
+ attr_reader :query, :status, :placemarks
150
+
151
+ def initialize(xml, geo_key) #:nodoc
152
+ @xml, @geo_key = xml, geo_key
153
+
154
+ @query = fetch(:name)
155
+ @status = fetch(:code).to_i
156
+
157
+ check_for_errors
158
+
159
+ @placemarks = @xml.scan %r{<Placemark(?: id="p\d+")?>.+?</Placemark>}m
160
+ end
161
+
162
+ def check_for_errors #:nodoc:
163
+ case status
164
+ when 200 then # Success
165
+ when 500 then raise ServerError, "Unknown error from Google's server"
166
+ when 601 then raise MissingAddressError, "Missing address"
167
+ when 602 then raise UnknownAddressError, "Unknown address: #{@query}"
168
+ when 603 then raise UnavailableAddressError, "Unavailable address: #{@query}"
169
+ when 610 then raise InvalidMapKeyError, "Invalid map key: #{@geo_key}"
170
+ when 620 then raise TooManyQueriesError, "Too many queries for map key: #{@geo_key}"
171
+ else raise UnknownError, "Unknown error: #{@status}"
172
+ end
173
+ end
174
+ end
175
+
176
+ ###
177
+
178
+ class Error < Exception; end
179
+
180
+ class ServerError < Error; end
181
+
182
+ class AddressError < Error; end
183
+ class MissingAddressError < AddressError; end
184
+ class UnknownAddressError < AddressError; end
185
+ class UnavailableAddressError < AddressError; end
186
+
187
+ class MapKeyError < Error; end
188
+ class InvalidMapKeyError < MapKeyError; end
189
+ class TooManyQueriesError < MapKeyError; end
190
+
191
+ class UnknownError < Error; end
192
+ end
193
+
194
+ end
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>1600 Amphitheater Pkwy, Mountain View, CA</name>
5
+ <Status>
6
+ <code>610</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>1600</name>
5
+ <Status>
6
+ <code>601</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>1600 Amphitheater Pkwy, Mountain View, CA</name>
5
+ <Status>
6
+ <code>500</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.1">
3
+ <Response>
4
+ <name>1600 Amphitheatre Parkway, Mountain View, CA</name>
5
+ <Status>
6
+ <code>200</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ <Placemark>
10
+ <address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA</address>
11
+ <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" Accuracy="8">
12
+ <Country>
13
+ <CountryNameCode>US</CountryNameCode>
14
+ <AdministrativeArea>
15
+ <AdministrativeAreaName>CA</AdministrativeAreaName>
16
+ <SubAdministrativeArea>
17
+ <SubAdministrativeAreaName>Santa Clara</SubAdministrativeAreaName>
18
+ <Locality>
19
+ <LocalityName>Mountain View</LocalityName>
20
+ <Thoroughfare>
21
+ <ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName>
22
+ </Thoroughfare>
23
+ <PostalCode>
24
+ <PostalCodeNumber>94043</PostalCodeNumber>
25
+ </PostalCode>
26
+ </Locality>
27
+ </SubAdministrativeArea>
28
+ </AdministrativeArea>
29
+ </Country>
30
+ </AddressDetails>
31
+ <Point>
32
+ <coordinates>-122.083739,37.423021,0</coordinates>
33
+ </Point>
34
+ </Placemark>
35
+ </Response>
36
+ </kml>
@@ -0,0 +1,62 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>heaven</name>
5
+ <Status>
6
+ <code>200</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ <Placemark id="p1">
10
+ <address>Heaven, Pottsville, PA 17901, USA</address>
11
+ <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" Accuracy="6">
12
+ <Country>
13
+ <CountryNameCode>US</CountryNameCode>
14
+ <AdministrativeArea>
15
+ <AdministrativeAreaName>PA</AdministrativeAreaName>
16
+ <SubAdministrativeArea>
17
+ <SubAdministrativeAreaName>Schuylkill</SubAdministrativeAreaName>
18
+ <Locality>
19
+ <LocalityName>Pottsville</LocalityName>
20
+ <Thoroughfare>
21
+ <ThoroughfareName>Heaven</ThoroughfareName>
22
+ </Thoroughfare>
23
+ <PostalCode>
24
+ <PostalCodeNumber>17901</PostalCodeNumber>
25
+ </PostalCode>
26
+ </Locality>
27
+ </SubAdministrativeArea>
28
+ </AdministrativeArea>
29
+ </Country>
30
+ </AddressDetails>
31
+ <Point>
32
+ <coordinates>-76.169968,40.650970,0</coordinates>
33
+ </Point>
34
+ </Placemark>
35
+ <Placemark id="p2">
36
+ <address>Heaven, Oakboro, NC 28129, USA</address>
37
+ <AddressDetails xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0" Accuracy="6">
38
+ <Country>
39
+ <CountryNameCode>US</CountryNameCode>
40
+ <AdministrativeArea>
41
+ <AdministrativeAreaName>NC</AdministrativeAreaName>
42
+ <SubAdministrativeArea>
43
+ <SubAdministrativeAreaName>Stanly</SubAdministrativeAreaName>
44
+ <Locality>
45
+ <LocalityName>Oakboro</LocalityName>
46
+ <Thoroughfare>
47
+ <ThoroughfareName>Heaven</ThoroughfareName>
48
+ </Thoroughfare>
49
+ <PostalCode>
50
+ <PostalCodeNumber>28129</PostalCodeNumber>
51
+ </PostalCode>
52
+ </Locality>
53
+ </SubAdministrativeArea>
54
+ </AdministrativeArea>
55
+ </Country>
56
+ </AddressDetails>
57
+ <Point>
58
+ <coordinates>-80.330399,35.254227,0</coordinates>
59
+ </Point>
60
+ </Placemark>
61
+ </Response>
62
+ </kml>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>1600 Amphitheater Pkwy, Mountain View, CA</name>
5
+ <Status>
6
+ <code>620</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>42-44 Hanway Street, London</name>
5
+ <Status>
6
+ <code>603</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://earth.google.com/kml/2.0">
3
+ <Response>
4
+ <name>1600</name>
5
+ <Status>
6
+ <code>602</code>
7
+ <request>geocode</request>
8
+ </Status>
9
+ </Response>
10
+ </kml>