graticule 1.0.0.pre2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/bin/geocode +0 -0
  2. data/lib/graticule.rb +2 -0
  3. data/lib/graticule/geocoder/bogus.rb +1 -1
  4. data/lib/graticule/geocoder/geonames.rb +1 -1
  5. data/lib/graticule/geocoder/google.rb +4 -1
  6. data/lib/graticule/geocoder/host_ip.rb +1 -1
  7. data/lib/graticule/version.rb +3 -0
  8. metadata +73 -131
  9. data/.autotest +0 -13
  10. data/.gitignore +0 -6
  11. data/Rakefile +0 -123
  12. data/VERSION +0 -1
  13. data/graticule.gemspec +0 -199
  14. data/init.rb +0 -2
  15. data/site/index.html +0 -114
  16. data/site/plugin.html +0 -82
  17. data/site/stylesheets/style.css +0 -69
  18. data/test/config.yml.default +0 -33
  19. data/test/fixtures/responses/freethepostcode/not_found.txt +0 -3
  20. data/test/fixtures/responses/freethepostcode/success.txt +0 -2
  21. data/test/fixtures/responses/geocoder_ca/success.xml +0 -12
  22. data/test/fixtures/responses/geocoder_us/success.xml +0 -8
  23. data/test/fixtures/responses/geocoder_us/unknown.xml +0 -1
  24. data/test/fixtures/responses/geonames/missing.xml +0 -4
  25. data/test/fixtures/responses/geonames/success.xml +0 -14
  26. data/test/fixtures/responses/geonames/unknown.xml +0 -4
  27. data/test/fixtures/responses/google/badkey.xml +0 -1
  28. data/test/fixtures/responses/google/limit.xml +0 -10
  29. data/test/fixtures/responses/google/missing_address.xml +0 -1
  30. data/test/fixtures/responses/google/only_coordinates.xml +0 -1
  31. data/test/fixtures/responses/google/partial.xml +0 -16
  32. data/test/fixtures/responses/google/server_error.xml +0 -10
  33. data/test/fixtures/responses/google/success.xml +0 -16
  34. data/test/fixtures/responses/google/success_multiple_results.xml +0 -88
  35. data/test/fixtures/responses/google/unavailable.xml +0 -1
  36. data/test/fixtures/responses/google/unknown_address.xml +0 -8
  37. data/test/fixtures/responses/host_ip/private.txt +0 -4
  38. data/test/fixtures/responses/host_ip/success.txt +0 -4
  39. data/test/fixtures/responses/host_ip/unknown.txt +0 -4
  40. data/test/fixtures/responses/local_search_maps/empty.txt +0 -1
  41. data/test/fixtures/responses/local_search_maps/not_found.txt +0 -1
  42. data/test/fixtures/responses/local_search_maps/success.txt +0 -1
  43. data/test/fixtures/responses/mapquest/multi_result.xml +0 -1
  44. data/test/fixtures/responses/mapquest/success.xml +0 -1
  45. data/test/fixtures/responses/multimap/missing_params.xml +0 -4
  46. data/test/fixtures/responses/multimap/no_matches.xml +0 -4
  47. data/test/fixtures/responses/multimap/success.xml +0 -19
  48. data/test/fixtures/responses/yahoo/success.xml +0 -3
  49. data/test/fixtures/responses/yahoo/unknown_address.xml +0 -6
  50. data/test/graticule/distance_test.rb +0 -58
  51. data/test/graticule/geocoder/freethepostcode_test.rb +0 -36
  52. data/test/graticule/geocoder/geocoder_ca_test.rb +0 -41
  53. data/test/graticule/geocoder/geocoder_us_test.rb +0 -43
  54. data/test/graticule/geocoder/geocoders.rb +0 -55
  55. data/test/graticule/geocoder/geonames_test.rb +0 -48
  56. data/test/graticule/geocoder/google_test.rb +0 -107
  57. data/test/graticule/geocoder/host_ip_test.rb +0 -40
  58. data/test/graticule/geocoder/local_search_maps_test.rb +0 -30
  59. data/test/graticule/geocoder/mapquest_test.rb +0 -49
  60. data/test/graticule/geocoder/multi_test.rb +0 -51
  61. data/test/graticule/geocoder/multimap_test.rb +0 -52
  62. data/test/graticule/geocoder/yahoo_test.rb +0 -49
  63. data/test/graticule/geocoder_test.rb +0 -23
  64. data/test/graticule/location_test.rb +0 -86
  65. data/test/graticule/precision_test.rb +0 -37
  66. data/test/mocks/uri.rb +0 -52
  67. data/test/test_helper.rb +0 -30
@@ -1,49 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Graticule
4
- module Geocoder
5
- class YahooTest < Test::Unit::TestCase
6
-
7
- def setup
8
- URI::HTTP.responses = []
9
- URI::HTTP.uris = []
10
- @geocoder = Yahoo.new 'APP_ID'
11
- @location = Location.new(
12
- :street => "701 1st Ave",
13
- :locality => "Sunnyvale",
14
- :region => "CA",
15
- :postal_code => "94089-1019",
16
- :country => "US",
17
- :longitude => -122.025055,
18
- :latitude => 37.416397,
19
- :precision => :address,
20
- :warning => "The exact location could not be found, here is the closest match: 701 First Ave, Sunnyvale, CA 94089"
21
- )
22
- end
23
-
24
- def test_locate
25
- prepare_response(:success)
26
- assert_equal @location, @geocoder.locate('701 First Street, Sunnyvale, CA')
27
- end
28
-
29
- def test_url
30
- prepare_response(:success)
31
- @geocoder.locate('701 First Street, Sunnyvale, CA')
32
- assert_equal 'http://api.local.yahoo.com/MapsService/V1/geocode?appid=APP_ID&location=701%20First%20Street,%20Sunnyvale,%20CA&output=xml',
33
- URI::HTTP.uris.first
34
- end
35
-
36
-
37
- def test_locate_bad_address
38
- prepare_response(:unknown_address)
39
- assert_raise(Error) { @geocoder.locate('yucksthoeusthaoeusnhtaosu') }
40
- end
41
-
42
- protected
43
- def prepare_response(id)
44
- URI::HTTP.responses << response('yahoo', id)
45
- end
46
-
47
- end
48
- end
49
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Graticule
4
- class GeocoderTest < Test::Unit::TestCase
5
-
6
- def test_bogus_service
7
- assert_equal Geocoder::Bogus, Graticule.service(:bogus)
8
- end
9
-
10
- def test_yahoo_service
11
- assert_equal Geocoder::Yahoo, Graticule.service(:yahoo)
12
- end
13
-
14
- def test_google_service
15
- assert_equal Geocoder::Google, Graticule.service(:google)
16
- end
17
-
18
- def test_geocoder_us_service
19
- assert_equal Geocoder::GeocoderUs, Graticule.service(:geocoder_us)
20
- end
21
-
22
- end
23
- end
@@ -1,86 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Graticule
4
- class LocationTest < Test::Unit::TestCase
5
-
6
- def setup
7
- @washington_dc = Location.new :latitude => 38.898748, :longitude => -77.037684,
8
- :street => '1600 Pennsylvania Avenue, NW', :locality => 'Washington',
9
- :region => 'DC', :postal_code => 20500, :country => 'US'
10
- end
11
-
12
- def test_distance_to
13
- chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
14
- assert_in_delta 594.820, @washington_dc.distance_to(chicago), 1.0
15
- end
16
-
17
- def test_responds_to
18
- [:latitude, :longitude, :street, :locality, :region, :postal_code, :country, :coordinates, :precision].each do |m|
19
- assert Location.new.respond_to?(m), "should respond to #{m}"
20
- end
21
- end
22
-
23
- def test_coordinates
24
- l = Location.new(:latitude => 100, :longitude => 50)
25
- assert_equal [100, 50], l.coordinates
26
- end
27
-
28
- def test_equal
29
- assert_equal Location.new, Location.new
30
-
31
- attrs = {:latitude => 100.5389, :longitude => -147.5893, :street => '123 A Street',
32
- :locality => 'Somewhere', :region => 'NO', :postal_code => '12345', :country => 'USA'}
33
-
34
- assert_equal Location.new(attrs), Location.new(attrs)
35
- attrs.each do |k,v|
36
- assert_equal Location.new(k => v), Location.new(k => v)
37
- assert_not_equal Location.new, Location.new(k => v)
38
- assert_not_equal Location.new(attrs), Location.new(attrs.update(k => nil))
39
- end
40
- end
41
-
42
- def test_antipode
43
- chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
44
-
45
- assert_equal [-38.898748, 102.962316], @washington_dc.antipode.coordinates
46
- assert_equal [-41.85, 92.35], chicago.antipode.coordinates
47
- assert_equal [-41, -180], Graticule::Location.new(:latitude => 41, :longitude => 0).antipode.coordinates
48
- assert_equal [-41, 179], Graticule::Location.new(:latitude => 41, :longitude => -1).antipode.coordinates
49
- assert_equal [-41, -179], Graticule::Location.new(:latitude => 41, :longitude => 1).antipode.coordinates
50
-
51
- assert_equal @washington_dc.coordinates, @washington_dc.antipode.antipode.coordinates
52
- assert_equal chicago.coordinates, chicago.antipode.antipode.coordinates
53
- end
54
-
55
- def test_to_s
56
- assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500 US",
57
- @washington_dc.to_s
58
- assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500",
59
- @washington_dc.to_s(:country => false)
60
- assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500",
61
- @washington_dc.to_s(:country => false)
62
- assert_equal "1600 Pennsylvania Avenue, NW\nWashington, DC 20500\nlatitude: 38.898748, longitude: -77.037684",
63
- @washington_dc.to_s(:country => false, :coordinates => true)
64
- end
65
-
66
- def test_blank?
67
- assert Location.new.blank?
68
- [:latitude, :longitude, :street, :locality, :region, :postal_code, :country].each do |attr|
69
- assert !Location.new(attr => 'Foo').blank?
70
- end
71
- end
72
-
73
- def test_time_zone
74
- URI::HTTP.uris = []
75
- URI::HTTP.responses = []
76
- URI::HTTP.responses << response('geonames', :success)
77
- chicago = Location.new(:latitude => 41.85, :longitude => -87.65)
78
- assert_equal 'America/Chicago', chicago.time_zone
79
- end
80
-
81
- def test_casts_precision
82
- assert_equal Precision::Region, Location.new(:precision => :region).precision
83
- assert_equal Precision::Street, Location.new(:precision => Precision::Street).precision
84
- end
85
- end
86
- end
@@ -1,37 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Graticule
4
- class PrecisionTest < Test::Unit::TestCase
5
- def test_constants_exist
6
- %w(
7
- Unknown
8
- Country
9
- Region
10
- Locality
11
- PostalCode
12
- Street
13
- Address
14
- Premise
15
- ).each do |const|
16
- assert Precision.const_defined?(const), "Can't find #{const}"
17
- end
18
- end
19
-
20
- def test_can_compare_precisions
21
- assert Precision::Country < Precision::Region
22
- assert Precision::Country > Precision::Unknown
23
- assert Precision::Country == Precision::Country
24
- assert Precision::Country == Precision.new(:country)
25
- assert Precision::Country != Precision::Premise
26
- end
27
-
28
- def test_can_compare_against_symbols
29
- assert Precision::Country < :region
30
- end
31
-
32
- def test_can_compare_against_symbols
33
- assert_raise(ArgumentError) { Precision::Unknown > :foo }
34
- assert_raise(ArgumentError) { Precision::Unknown == :bar }
35
- end
36
- end
37
- end
@@ -1,52 +0,0 @@
1
- require 'uri/http'
2
- require 'open-uri'
3
-
4
- ##
5
- # This stub overrides OpenURI's open method to allow programs that use OpenURI
6
- # to be easily tested.
7
- #
8
- # == Usage
9
- #
10
- # require 'rc_rest/uri_stub'
11
- #
12
- # class TestMyClass < Test::Unit::TestCase
13
- #
14
- # def setup
15
- # URI::HTTP.responses = []
16
- # URI::HTTP.uris = []
17
- #
18
- # @obj = MyClass.new
19
- # end
20
- #
21
- # def test_my_method
22
- # URI::HTTP.responses << 'some text open would ordinarily return'
23
- #
24
- # result = @obj.my_method
25
- #
26
- # assert_equal :something_meaninfgul, result
27
- #
28
- # assert_equal true, URI::HTTP.responses.empty?
29
- # assert_equal 1, URI::HTTP.uris.length
30
- # assert_equal 'http://example.com/path', URI::HTTP.uris.first
31
- # end
32
- #
33
- # end
34
-
35
- class URI::HTTP # :nodoc:
36
-
37
- class << self
38
- attr_accessor :responses, :uris
39
- end
40
-
41
- alias original_open open
42
-
43
- def open(*args)
44
- self.class.uris << self.to_s
45
- io = StringIO.new(self.class.responses.shift)
46
- OpenURI::Meta.init(io)
47
- yield io if block_given?
48
- io
49
- end
50
-
51
- end
52
-
@@ -1,30 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'rubygems'
4
- require 'test/unit'
5
- require 'graticule'
6
- require 'mocha'
7
- require 'mocks/uri'
8
-
9
- TEST_RESPONSE_PATH = File.dirname(__FILE__) + '/fixtures/responses'
10
-
11
- module Test
12
- module Unit
13
- module Assertions
14
-
15
- private
16
- def response(geocoder, response, extension = 'xml')
17
- clean_backtrace do
18
- File.read(File.dirname(__FILE__) + "/fixtures/responses/#{geocoder}/#{response}.#{extension}")
19
- end
20
- end
21
-
22
- def clean_backtrace(&block)
23
- yield
24
- rescue AssertionFailedError => e
25
- path = File.expand_path(__FILE__)
26
- raise AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
27
- end
28
- end
29
- end
30
- end