aub-graticule 0.2.11

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 (88) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.txt +61 -0
  3. data/LICENSE.txt +30 -0
  4. data/Manifest.txt +84 -0
  5. data/README.txt +41 -0
  6. data/Rakefile +143 -0
  7. data/VERSION +1 -0
  8. data/bin/geocode +5 -0
  9. data/graticule.gemspec +143 -0
  10. data/init.rb +2 -0
  11. data/lib/graticule/cli.rb +64 -0
  12. data/lib/graticule/core_ext.rb +15 -0
  13. data/lib/graticule/distance/haversine.rb +40 -0
  14. data/lib/graticule/distance/spherical.rb +52 -0
  15. data/lib/graticule/distance/vincenty.rb +76 -0
  16. data/lib/graticule/distance.rb +18 -0
  17. data/lib/graticule/geocoder/base.rb +116 -0
  18. data/lib/graticule/geocoder/bogus.rb +15 -0
  19. data/lib/graticule/geocoder/geocoder_ca.rb +54 -0
  20. data/lib/graticule/geocoder/geocoder_us.rb +51 -0
  21. data/lib/graticule/geocoder/google.rb +100 -0
  22. data/lib/graticule/geocoder/host_ip.rb +41 -0
  23. data/lib/graticule/geocoder/local_search_maps.rb +44 -0
  24. data/lib/graticule/geocoder/mapquest.rb +96 -0
  25. data/lib/graticule/geocoder/meta_carta.rb +32 -0
  26. data/lib/graticule/geocoder/multi.rb +46 -0
  27. data/lib/graticule/geocoder/multimap.rb +73 -0
  28. data/lib/graticule/geocoder/postcode_anywhere.rb +63 -0
  29. data/lib/graticule/geocoder/rest.rb +18 -0
  30. data/lib/graticule/geocoder/yahoo.rb +84 -0
  31. data/lib/graticule/geocoder.rb +21 -0
  32. data/lib/graticule/location.rb +61 -0
  33. data/lib/graticule/version.rb +9 -0
  34. data/lib/graticule.rb +26 -0
  35. data/site/index.html +114 -0
  36. data/site/plugin.html +82 -0
  37. data/site/stylesheets/style.css +69 -0
  38. data/test/config.yml.default +36 -0
  39. data/test/fixtures/responses/geocoder_us/success.xml +18 -0
  40. data/test/fixtures/responses/geocoder_us/unknown.xml +1 -0
  41. data/test/fixtures/responses/google/badkey.xml +1 -0
  42. data/test/fixtures/responses/google/limit.xml +10 -0
  43. data/test/fixtures/responses/google/missing_address.xml +1 -0
  44. data/test/fixtures/responses/google/only_coordinates.xml +1 -0
  45. data/test/fixtures/responses/google/partial.xml +1 -0
  46. data/test/fixtures/responses/google/server_error.xml +10 -0
  47. data/test/fixtures/responses/google/success.xml +1 -0
  48. data/test/fixtures/responses/google/success_multiple_results.xml +88 -0
  49. data/test/fixtures/responses/google/unavailable.xml +1 -0
  50. data/test/fixtures/responses/google/unknown_address.xml +1 -0
  51. data/test/fixtures/responses/host_ip/private.txt +4 -0
  52. data/test/fixtures/responses/host_ip/success.txt +4 -0
  53. data/test/fixtures/responses/host_ip/unknown.txt +4 -0
  54. data/test/fixtures/responses/local_search_maps/empty.txt +1 -0
  55. data/test/fixtures/responses/local_search_maps/not_found.txt +1 -0
  56. data/test/fixtures/responses/local_search_maps/success.txt +1 -0
  57. data/test/fixtures/responses/mapquest/multi_result.xml +1 -0
  58. data/test/fixtures/responses/mapquest/success.xml +1 -0
  59. data/test/fixtures/responses/meta_carta/bad_address.xml +17 -0
  60. data/test/fixtures/responses/meta_carta/multiple.xml +33 -0
  61. data/test/fixtures/responses/meta_carta/success.xml +31 -0
  62. data/test/fixtures/responses/multimap/missing_params.xml +4 -0
  63. data/test/fixtures/responses/multimap/no_matches.xml +4 -0
  64. data/test/fixtures/responses/multimap/success.xml +19 -0
  65. data/test/fixtures/responses/postcode_anywhere/badkey.xml +9 -0
  66. data/test/fixtures/responses/postcode_anywhere/canada.xml +16 -0
  67. data/test/fixtures/responses/postcode_anywhere/empty.xml +16 -0
  68. data/test/fixtures/responses/postcode_anywhere/success.xml +16 -0
  69. data/test/fixtures/responses/postcode_anywhere/uk.xml +18 -0
  70. data/test/fixtures/responses/yahoo/success.xml +3 -0
  71. data/test/fixtures/responses/yahoo/unknown_address.xml +6 -0
  72. data/test/mocks/uri.rb +52 -0
  73. data/test/test_helper.rb +31 -0
  74. data/test/unit/graticule/distance_test.rb +58 -0
  75. data/test/unit/graticule/geocoder/geocoder_us_test.rb +43 -0
  76. data/test/unit/graticule/geocoder/geocoders.rb +56 -0
  77. data/test/unit/graticule/geocoder/google_test.rb +112 -0
  78. data/test/unit/graticule/geocoder/host_ip_test.rb +40 -0
  79. data/test/unit/graticule/geocoder/local_search_maps_test.rb +30 -0
  80. data/test/unit/graticule/geocoder/mapquest_test.rb +61 -0
  81. data/test/unit/graticule/geocoder/meta_carta_test.rb +44 -0
  82. data/test/unit/graticule/geocoder/multi_test.rb +43 -0
  83. data/test/unit/graticule/geocoder/multimap_test.rb +52 -0
  84. data/test/unit/graticule/geocoder/postcode_anywhere_test.rb +50 -0
  85. data/test/unit/graticule/geocoder/yahoo_test.rb +48 -0
  86. data/test/unit/graticule/geocoder_test.rb +27 -0
  87. data/test/unit/graticule/location_test.rb +73 -0
  88. metadata +166 -0
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ test/config.yml
2
+ *.gem
3
+ pkg
4
+ coverage
data/CHANGELOG.txt ADDED
@@ -0,0 +1,61 @@
1
+ 0.2.11 (2009-07-15)
2
+ * Add new MapQuest geocoder [Aubrey Holland]
3
+
4
+ 0.2.10 (2009-04-17)
5
+ * Added #blank? to Location
6
+
7
+ 0.2.9 (2009-04-14)
8
+ * Remove retired MapQuest geocoder
9
+ * Slightly more aggressive error handling for Geocoder.us
10
+ * Extend Numeric with #to_radians and #to_degrees
11
+
12
+ 0.2.8 (2008-10-03)
13
+ * fixed missing files from gem
14
+
15
+ 0.2.7 (2008-10-03)
16
+ * Adding Multimap geocoder [Tom Taylor]
17
+ * Added MapQuest geocoder [Andrew Selder]
18
+ * Fix google geocoder for responses that only return coordinates [Andrew Selder]
19
+
20
+ 0.2.5
21
+ * fixed address mapping for local search maps (again)
22
+
23
+ 0.2.4 (2007-05-15)
24
+ * fixed address mapping for local search maps (Tom Taylor)
25
+
26
+ 0.2.3 (2007-04-27)
27
+ * fixed Google for less precise queries
28
+ * added User-Agent to coerce Google into returning UTF-8 (Jonathan Tron)
29
+
30
+ 0.2.2 (2007-03-27)
31
+ * fixed LocalSearchMaps
32
+
33
+ 0.2.1 (2007-03-19)
34
+ * fixed error in command line interface
35
+
36
+ 0.2.0 (2007-03-17)
37
+ * changed city to locality, state to region, and zip to postal_code
38
+ * added support for PostcodeAnywhere
39
+ * added support for Local Search Maps (James Stewart)
40
+ * added IP-based geocoder
41
+ * moved geocoders to Graticule::Geocoder namespace
42
+ * fixed Google geocoder (again)
43
+ * made Yahoo geocoder consistent with others by returning 1 result
44
+ * geocoders can how take a Hash (:street, :locality, :region, :postal_code, :country)
45
+ or a Graticule::Location for the #locate call
46
+
47
+ 0.1.3 (2007-02-14)
48
+ * fixed Google geocoder
49
+ * fixed CLI
50
+
51
+ 0.1.2 (2007-02-12)
52
+ * added "geocode" executable. See "geocode --help" for more information
53
+ * declared dependency on ActiveSupport
54
+
55
+ 0.1.1 (2006-12-16)
56
+ * fixed bug in Yahoo that raised error when street address not returned
57
+ * migrated to Hoe (http://seattlerb.rubyforge.org/hoe/)
58
+ * added Haversine, Spherical and Vincenty distance calculations
59
+
60
+ 0.1 (2006-10-31)
61
+ * Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,30 @@
1
+ Copyright 2006 Brandon Keepers, Collective Idea. All rights reserved.
2
+
3
+ Original geocoding code:
4
+ Copyright 2006 Eric Hodel, The Robot Co-op. All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions
8
+ are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
+ 2. Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+ 3. Neither the names of the authors nor the names of their contributors
16
+ may be used to endorse or promote products derived from this software
17
+ without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
20
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
23
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
25
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
26
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
data/Manifest.txt ADDED
@@ -0,0 +1,84 @@
1
+ CHANGELOG.txt
2
+ LICENSE.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/geocode
7
+ init.rb
8
+ lib/graticule.rb
9
+ lib/graticule/cli.rb
10
+ lib/graticule/core_ext.rb
11
+ lib/graticule/distance.rb
12
+ lib/graticule/distance/haversine.rb
13
+ lib/graticule/distance/spherical.rb
14
+ lib/graticule/distance/vincenty.rb
15
+ lib/graticule/geocoder.rb
16
+ lib/graticule/geocoder/base.rb
17
+ lib/graticule/geocoder/bogus.rb
18
+ lib/graticule/geocoder/geocoder_ca.rb
19
+ lib/graticule/geocoder/geocoder_us.rb
20
+ lib/graticule/geocoder/google.rb
21
+ lib/graticule/geocoder/host_ip.rb
22
+ lib/graticule/geocoder/local_search_maps.rb
23
+ lib/graticule/geocoder/mapquest.rb
24
+ lib/graticule/geocoder/meta_carta.rb
25
+ lib/graticule/geocoder/multi.rb
26
+ lib/graticule/geocoder/multimap.rb
27
+ lib/graticule/geocoder/postcode_anywhere.rb
28
+ lib/graticule/geocoder/rest.rb
29
+ lib/graticule/geocoder/yahoo.rb
30
+ lib/graticule/location.rb
31
+ lib/graticule/version.rb
32
+ site/index.html
33
+ site/plugin.html
34
+ site/stylesheets/style.css
35
+ test/config.yml.default
36
+ test/fixtures/responses/geocoder_us/success.xml
37
+ test/fixtures/responses/geocoder_us/unknown.xml
38
+ test/fixtures/responses/google/badkey.xml
39
+ test/fixtures/responses/google/limit.xml
40
+ test/fixtures/responses/google/missing_address.xml
41
+ test/fixtures/responses/google/only_coordinates.xml
42
+ test/fixtures/responses/google/partial.xml
43
+ test/fixtures/responses/google/server_error.xml
44
+ test/fixtures/responses/google/success.xml
45
+ test/fixtures/responses/google/success_multiple_results.xml
46
+ test/fixtures/responses/google/unavailable.xml
47
+ test/fixtures/responses/google/unknown_address.xml
48
+ test/fixtures/responses/host_ip/private.txt
49
+ test/fixtures/responses/host_ip/success.txt
50
+ test/fixtures/responses/host_ip/unknown.txt
51
+ test/fixtures/responses/local_search_maps/empty.txt
52
+ test/fixtures/responses/local_search_maps/not_found.txt
53
+ test/fixtures/responses/local_search_maps/success.txt
54
+ test/fixtures/responses/mapquest/multi_result.xml
55
+ test/fixtures/responses/mapquest/success.xml
56
+ test/fixtures/responses/meta_carta/bad_address.xml
57
+ test/fixtures/responses/meta_carta/multiple.xml
58
+ test/fixtures/responses/meta_carta/success.xml
59
+ test/fixtures/responses/multimap/missing_params.xml
60
+ test/fixtures/responses/multimap/no_matches.xml
61
+ test/fixtures/responses/multimap/success.xml
62
+ test/fixtures/responses/postcode_anywhere/badkey.xml
63
+ test/fixtures/responses/postcode_anywhere/canada.xml
64
+ test/fixtures/responses/postcode_anywhere/empty.xml
65
+ test/fixtures/responses/postcode_anywhere/success.xml
66
+ test/fixtures/responses/postcode_anywhere/uk.xml
67
+ test/fixtures/responses/yahoo/success.xml
68
+ test/fixtures/responses/yahoo/unknown_address.xml
69
+ test/mocks/uri.rb
70
+ test/test_helper.rb
71
+ test/unit/graticule/distance_test.rb
72
+ test/unit/graticule/geocoder/geocoder_us_test.rb
73
+ test/unit/graticule/geocoder/geocoders.rb
74
+ test/unit/graticule/geocoder/google_test.rb
75
+ test/unit/graticule/geocoder/host_ip_test.rb
76
+ test/unit/graticule/geocoder/local_search_maps_test.rb
77
+ test/unit/graticule/geocoder/mapquest_test.rb
78
+ test/unit/graticule/geocoder/meta_carta_test.rb
79
+ test/unit/graticule/geocoder/multi_test.rb
80
+ test/unit/graticule/geocoder/multimap_test.rb
81
+ test/unit/graticule/geocoder/postcode_anywhere_test.rb
82
+ test/unit/graticule/geocoder/yahoo_test.rb
83
+ test/unit/graticule/geocoder_test.rb
84
+ test/unit/graticule/location_test.rb
data/README.txt ADDED
@@ -0,0 +1,41 @@
1
+ = Graticule
2
+
3
+ Graticule is a geocoding API for looking up address coordinates. It supports many popular APIs, including Yahoo, Google, Geocoder.ca, Geocoder.us, PostcodeAnywhere and MetaCarta.
4
+
5
+ = Usage
6
+
7
+ require 'rubygems'
8
+ require 'graticule'
9
+ geocoder = Graticule.service(:google).new "api_key"
10
+ location = geocoder.locate "61 East 9th Street, Holland, MI"
11
+
12
+ = Distance Calculation
13
+
14
+ Graticule includes 3 different distance formulas, Spherical (simplest but least accurate), Vincenty (most accurate and most complicated), and Haversine (somewhere inbetween).
15
+
16
+ geocoder.locate("Holland, MI").distance_to(geocoder.locate("Chicago, IL"))
17
+ #=> 101.997458788177
18
+
19
+ = Command Line
20
+
21
+ Graticule includes a command line interface (CLI).
22
+
23
+ $ geocode -s yahoo -a yahookey Washington, DC
24
+ Washington, DC US
25
+ latitude: 38.895222, longitude: -77.036758
26
+
27
+ = How to contribute
28
+
29
+ If you find what you might think is a bug:
30
+
31
+ 1. Check the GitHub issue tracker to see if anyone else has had the same issue.
32
+ http://github.com/collectiveidea/graticule/issues/
33
+ 2. If you don't see anything, create an issue with information on how to reproduce it.
34
+
35
+ If you want to contribute an enhancement or a fix:
36
+
37
+ 1. Fork the project on github.
38
+ http://github.com/collectiveidea/graticule/
39
+ 2. Make your changes with tests.
40
+ 3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren't related to your enhancement or fix
41
+ 4. Send a pull request.
data/Rakefile ADDED
@@ -0,0 +1,143 @@
1
+ begin
2
+ require 'jeweler'
3
+ rescue LoadError
4
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
5
+ exit 1
6
+ end
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+ require 'rcov/rcovtask'
10
+
11
+ Jeweler::Tasks.new do |s|
12
+ s.name = "graticule"
13
+ s.rubyforge_project = "graticule"
14
+ s.author = 'Brandon Keepers'
15
+ s.email = 'brandon@opensoul.org'
16
+ s.summary = "API for using all the popular geocoding services."
17
+ s.description = 'Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.'
18
+ s.homepage = "http://github.com/collectiveidea/graticule"
19
+ s.add_dependency "activesupport"
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ["README.txt"]
22
+ s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
23
+ s.test_files = Dir['test/**/*.{yml,rb}']
24
+ end
25
+
26
+ desc 'Default: run unit tests.'
27
+ task :default => :test
28
+
29
+ desc 'Run the unit tests'
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = true
34
+ end
35
+
36
+ desc 'Generate documentatio'
37
+ Rake::RDocTask.new(:rdoc) do |rdoc|
38
+ rdoc.rdoc_dir = 'rdoc'
39
+ rdoc.title = 'Graticule'
40
+ rdoc.options << '--line-numbers' << '--inline-source'
41
+ rdoc.rdoc_files.include('README.txt')
42
+ rdoc.rdoc_files.include('lib/**/*.rb')
43
+ end
44
+
45
+ namespace :test do
46
+ desc "just rcov minus html output"
47
+ Rcov::RcovTask.new(:coverage) do |t|
48
+ # t.libs << 'test'
49
+ t.test_files = FileList['test/**/*_test.rb']
50
+ t.output_dir = 'coverage'
51
+ t.verbose = true
52
+ t.rcov_opts = %w(--exclude test,/usr/lib/ruby,/Library/Ruby,$HOME/.gem --sort coverage)
53
+ end
54
+ end
55
+
56
+ require 'rake/contrib/sshpublisher'
57
+ namespace :rubyforge do
58
+
59
+ desc "Release gem and RDoc documentation to RubyForge"
60
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
61
+
62
+ namespace :release do
63
+ desc "Publish RDoc to RubyForge."
64
+ task :docs => [:rdoc] do
65
+ config = YAML.load(
66
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
67
+ )
68
+
69
+ host = "#{config['username']}@rubyforge.org"
70
+ remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
71
+ local_dir = 'rdoc'
72
+
73
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
74
+ end
75
+ end
76
+ end
77
+
78
+ namespace :test do
79
+ namespace :cache do
80
+ desc 'Cache test responses from all the free geocoders'
81
+ task :free => [:google, :geocoder_us, :host_ip, :local_search_maps, :meta_carta, :yahoo]
82
+
83
+ desc 'Cache test responses from Google'
84
+ task :google do
85
+ cache_responses('google')
86
+ end
87
+
88
+ desc 'Cache test responses from Geocoder.us'
89
+ task :geocoder_us do
90
+ cache_responses('geocoder_us')
91
+ end
92
+
93
+ desc 'Cache test responses from HostIP'
94
+ task :host_ip do
95
+ cache_responses('host_ip')
96
+ end
97
+
98
+ desc 'Cache test responses from Local Search Maps'
99
+ task :local_search_maps do
100
+ cache_responses('local_search_maps')
101
+ end
102
+
103
+ desc 'Cache test responses from Meta Carta'
104
+ task :meta_carta do
105
+ cache_responses('meta_carta')
106
+ end
107
+
108
+ desc 'Cache test responses from Yahoo'
109
+ task :yahoo do
110
+ cache_responses('yahoo')
111
+ end
112
+
113
+ end
114
+ end
115
+
116
+ require 'active_support'
117
+ require 'net/http'
118
+ require 'uri'
119
+ RESPONSES_PATH = File.dirname(__FILE__) + '/test/fixtures/responses'
120
+
121
+ def cache_responses(service)
122
+ test_config[service.to_s]['responses'].each do |file,url|
123
+ File.open("#{RESPONSES_PATH}/#{service}/#{file}", 'w') do |f|
124
+ f.puts Net::HTTP.get(URI.parse(url))
125
+ end
126
+ end
127
+ end
128
+
129
+ def test_config
130
+ file = File.dirname(__FILE__) + '/test/config.yml'
131
+ raise "Copy config.yml.default to config.yml and set the API keys" unless File.exists?(file)
132
+ @test_config ||= returning(YAML.load(File.read(file))) do |config|
133
+ config.each do |service,values|
134
+ values['responses'].each {|file,url| update_placeholders!(values, url) }
135
+ end
136
+ end
137
+ end
138
+
139
+ def update_placeholders!(config, thing)
140
+ config.each do |option, value|
141
+ thing.gsub!(":#{option}", value) if value.is_a?(String)
142
+ end
143
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.11
data/bin/geocode ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'graticule/cli'
4
+
5
+ Graticule::Cli.start ARGV
data/graticule.gemspec ADDED
@@ -0,0 +1,143 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{graticule}
5
+ s.version = "0.2.11"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brandon Keepers"]
9
+ s.date = %q{2009-07-20}
10
+ s.default_executable = %q{geocode}
11
+ s.description = %q{Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.}
12
+ s.email = %q{brandon@opensoul.org}
13
+ s.executables = ["geocode"]
14
+ s.extra_rdoc_files = [
15
+ "README.txt"
16
+ ]
17
+ s.files = [
18
+ ".gitignore",
19
+ "CHANGELOG.txt",
20
+ "LICENSE.txt",
21
+ "Manifest.txt",
22
+ "README.txt",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "bin/geocode",
26
+ "graticule.gemspec",
27
+ "init.rb",
28
+ "lib/graticule.rb",
29
+ "lib/graticule/cli.rb",
30
+ "lib/graticule/core_ext.rb",
31
+ "lib/graticule/distance.rb",
32
+ "lib/graticule/distance/haversine.rb",
33
+ "lib/graticule/distance/spherical.rb",
34
+ "lib/graticule/distance/vincenty.rb",
35
+ "lib/graticule/geocoder.rb",
36
+ "lib/graticule/geocoder/base.rb",
37
+ "lib/graticule/geocoder/bogus.rb",
38
+ "lib/graticule/geocoder/geocoder_ca.rb",
39
+ "lib/graticule/geocoder/geocoder_us.rb",
40
+ "lib/graticule/geocoder/google.rb",
41
+ "lib/graticule/geocoder/host_ip.rb",
42
+ "lib/graticule/geocoder/local_search_maps.rb",
43
+ "lib/graticule/geocoder/mapquest.rb",
44
+ "lib/graticule/geocoder/meta_carta.rb",
45
+ "lib/graticule/geocoder/multi.rb",
46
+ "lib/graticule/geocoder/multimap.rb",
47
+ "lib/graticule/geocoder/postcode_anywhere.rb",
48
+ "lib/graticule/geocoder/rest.rb",
49
+ "lib/graticule/geocoder/yahoo.rb",
50
+ "lib/graticule/location.rb",
51
+ "lib/graticule/version.rb",
52
+ "site/index.html",
53
+ "site/plugin.html",
54
+ "site/stylesheets/style.css",
55
+ "test/config.yml.default",
56
+ "test/fixtures/responses/geocoder_us/success.xml",
57
+ "test/fixtures/responses/geocoder_us/unknown.xml",
58
+ "test/fixtures/responses/google/badkey.xml",
59
+ "test/fixtures/responses/google/limit.xml",
60
+ "test/fixtures/responses/google/missing_address.xml",
61
+ "test/fixtures/responses/google/only_coordinates.xml",
62
+ "test/fixtures/responses/google/partial.xml",
63
+ "test/fixtures/responses/google/server_error.xml",
64
+ "test/fixtures/responses/google/success.xml",
65
+ "test/fixtures/responses/google/success_multiple_results.xml",
66
+ "test/fixtures/responses/google/unavailable.xml",
67
+ "test/fixtures/responses/google/unknown_address.xml",
68
+ "test/fixtures/responses/host_ip/private.txt",
69
+ "test/fixtures/responses/host_ip/success.txt",
70
+ "test/fixtures/responses/host_ip/unknown.txt",
71
+ "test/fixtures/responses/local_search_maps/empty.txt",
72
+ "test/fixtures/responses/local_search_maps/not_found.txt",
73
+ "test/fixtures/responses/local_search_maps/success.txt",
74
+ "test/fixtures/responses/mapquest/multi_result.xml",
75
+ "test/fixtures/responses/mapquest/success.xml",
76
+ "test/fixtures/responses/meta_carta/bad_address.xml",
77
+ "test/fixtures/responses/meta_carta/multiple.xml",
78
+ "test/fixtures/responses/meta_carta/success.xml",
79
+ "test/fixtures/responses/multimap/missing_params.xml",
80
+ "test/fixtures/responses/multimap/no_matches.xml",
81
+ "test/fixtures/responses/multimap/success.xml",
82
+ "test/fixtures/responses/postcode_anywhere/badkey.xml",
83
+ "test/fixtures/responses/postcode_anywhere/canada.xml",
84
+ "test/fixtures/responses/postcode_anywhere/empty.xml",
85
+ "test/fixtures/responses/postcode_anywhere/success.xml",
86
+ "test/fixtures/responses/postcode_anywhere/uk.xml",
87
+ "test/fixtures/responses/yahoo/success.xml",
88
+ "test/fixtures/responses/yahoo/unknown_address.xml",
89
+ "test/mocks/uri.rb",
90
+ "test/test_helper.rb",
91
+ "test/unit/graticule/distance_test.rb",
92
+ "test/unit/graticule/geocoder/geocoder_us_test.rb",
93
+ "test/unit/graticule/geocoder/geocoders.rb",
94
+ "test/unit/graticule/geocoder/google_test.rb",
95
+ "test/unit/graticule/geocoder/host_ip_test.rb",
96
+ "test/unit/graticule/geocoder/local_search_maps_test.rb",
97
+ "test/unit/graticule/geocoder/mapquest_test.rb",
98
+ "test/unit/graticule/geocoder/meta_carta_test.rb",
99
+ "test/unit/graticule/geocoder/multi_test.rb",
100
+ "test/unit/graticule/geocoder/multimap_test.rb",
101
+ "test/unit/graticule/geocoder/postcode_anywhere_test.rb",
102
+ "test/unit/graticule/geocoder/yahoo_test.rb",
103
+ "test/unit/graticule/geocoder_test.rb",
104
+ "test/unit/graticule/location_test.rb"
105
+ ]
106
+ s.homepage = %q{http://github.com/collectiveidea/graticule}
107
+ s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
108
+ s.require_paths = ["lib"]
109
+ s.rubyforge_project = %q{graticule}
110
+ s.rubygems_version = %q{1.3.3}
111
+ s.summary = %q{API for using all the popular geocoding services.}
112
+ s.test_files = [
113
+ "test/mocks/uri.rb",
114
+ "test/test_helper.rb",
115
+ "test/unit/graticule/distance_test.rb",
116
+ "test/unit/graticule/geocoder/geocoder_us_test.rb",
117
+ "test/unit/graticule/geocoder/geocoders.rb",
118
+ "test/unit/graticule/geocoder/google_test.rb",
119
+ "test/unit/graticule/geocoder/host_ip_test.rb",
120
+ "test/unit/graticule/geocoder/local_search_maps_test.rb",
121
+ "test/unit/graticule/geocoder/mapquest_test.rb",
122
+ "test/unit/graticule/geocoder/meta_carta_test.rb",
123
+ "test/unit/graticule/geocoder/multi_test.rb",
124
+ "test/unit/graticule/geocoder/multimap_test.rb",
125
+ "test/unit/graticule/geocoder/postcode_anywhere_test.rb",
126
+ "test/unit/graticule/geocoder/yahoo_test.rb",
127
+ "test/unit/graticule/geocoder_test.rb",
128
+ "test/unit/graticule/location_test.rb"
129
+ ]
130
+
131
+ if s.respond_to? :specification_version then
132
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
133
+ s.specification_version = 3
134
+
135
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
136
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
137
+ else
138
+ s.add_dependency(%q<activesupport>, [">= 0"])
139
+ end
140
+ else
141
+ s.add_dependency(%q<activesupport>, [">= 0"])
142
+ end
143
+ end
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require 'graticule'
@@ -0,0 +1,64 @@
1
+ require 'graticule'
2
+ require 'optparse'
3
+
4
+ module Graticule
5
+
6
+ # A command line interface for geocoding. From the command line, run:
7
+ #
8
+ # geocode 49423
9
+ #
10
+ # Outputs:
11
+ #
12
+ # # Holland, MI 49423 US
13
+ # # latitude: 42.7654, longitude: -86.1085
14
+ #
15
+ # == Usage: geocode [options] location
16
+ #
17
+ # Options:
18
+ # -s, --service service Geocoding service
19
+ # -a, --apikey apikey API key for the selected service
20
+ # -h, --help Help
21
+ class Cli
22
+
23
+ def self.start(args, out = STDOUT)
24
+ options = { :service => :yahoo, :api_key => 'YahooDemo' }
25
+
26
+ OptionParser.new do |opts|
27
+ opts.banner = "Usage: geocode [options] location"
28
+ opts.separator ""
29
+ opts.separator "Options: "
30
+
31
+ opts.on("-s service", %w(yahoo google geocoder_us metacarta), "--service service", "Geocoding service") do |service|
32
+ options[:service] = service
33
+ end
34
+
35
+ opts.on("-a apikey", "--apikey apikey", "API key for the selected service")
36
+
37
+ opts.on_tail("-h", "--help", "Help") do
38
+ puts opts
39
+ exit
40
+ end
41
+ end.parse! args
42
+
43
+ options[:location] = args.join(" ")
44
+
45
+ result = Graticule.service(options[:service]).new(*options[:api_key].split(',')).locate(options[:location])
46
+ location = (result.is_a?(Array) ? result.first : result)
47
+ if location
48
+ out << location.to_s(:coordinates => true)
49
+ exit 0
50
+ else
51
+ out << "Location not found"
52
+ exit 1
53
+ end
54
+ rescue Graticule::CredentialsError
55
+ $stderr.puts "Invalid API key. Pass your #{options[:service]} API key using the -a option. "
56
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption,
57
+ Graticule::Error => error
58
+ $stderr.puts error.message
59
+ end
60
+
61
+
62
+ end
63
+ end
64
+
@@ -0,0 +1,15 @@
1
+ module Graticule
2
+ module RadiansAndDegrees
3
+ # Convert from degrees to radians
4
+ def to_radians
5
+ ( self / 360.0 ) * Math::PI * 2
6
+ end
7
+
8
+ # Convert from radians to degrees
9
+ def to_degrees
10
+ ( self * 360.0 ) / Math::PI / 2
11
+ end
12
+ end
13
+ end
14
+
15
+ Numeric.send :include, Graticule::RadiansAndDegrees
@@ -0,0 +1,40 @@
1
+ module Graticule
2
+ module Distance
3
+ #
4
+ # The Haversine Formula works better at small distances than the Spherical Law of Cosines
5
+ #
6
+ # Thanks to Chris Veness (http://www.movable-type.co.uk/scripts/LatLong.html)
7
+ # for distance formulas.
8
+ #
9
+ class Haversine < DistanceFormula
10
+
11
+ # Calculate the distance between two Locations using the Haversine formula
12
+ #
13
+ # Graticule::Distance::Haversine.distance(
14
+ # Graticule::Location.new(:latitude => 42.7654, :longitude => -86.1085),
15
+ # Graticule::Location.new(:latitude => 41.849838, :longitude => -87.648193)
16
+ # )
17
+ # #=> 101.061720831836
18
+ #
19
+ def self.distance(from, to, units = :miles)
20
+ from_longitude = from.longitude.to_radians
21
+ from_latitude = from.latitude.to_radians
22
+ to_longitude = to.longitude.to_radians
23
+ to_latitude = to.latitude.to_radians
24
+
25
+ latitude_delta = to_latitude - from_latitude
26
+ longitude_delta = to_longitude - from_longitude
27
+
28
+ a = sin(latitude_delta/2)**2 +
29
+ cos(from_latitude) *
30
+ cos(to_latitude) *
31
+ sin(longitude_delta/2)**2
32
+
33
+ c = 2 * atan2(sqrt(a), sqrt(1-a))
34
+
35
+ d = EARTH_RADIUS[units.to_sym] * c
36
+ end
37
+
38
+ end
39
+ end
40
+ end