geonames 0.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +7 -0
  4. data/README.markdown +82 -0
  5. data/Rakefile +13 -0
  6. data/init.rb +1 -0
  7. data/lib/geonames.rb +38 -22
  8. data/lib/geonames/bounding_box.rb +12 -0
  9. data/lib/{country_subdivision.rb → geonames/config.rb} +26 -13
  10. data/lib/geonames/country_info.rb +18 -0
  11. data/lib/{Rakefile.rb → geonames/country_subdivision.rb} +11 -6
  12. data/lib/geonames/intersection.rb +28 -0
  13. data/lib/{toponym_search_result.rb → geonames/postal_code.rb} +10 -16
  14. data/lib/geonames/postal_code_search_criteria.rb +50 -0
  15. data/lib/{timezone.rb → geonames/timezone.rb} +10 -11
  16. data/lib/geonames/toponym.rb +29 -0
  17. data/lib/geonames/toponym_search_criteria.rb +34 -0
  18. data/lib/{address.rb → geonames/toponym_search_result.rb} +10 -7
  19. data/lib/geonames/version.rb +3 -0
  20. data/lib/geonames/web_service.rb +467 -0
  21. data/lib/{wikipedia_article.rb → geonames/wikipedia_article.rb} +5 -20
  22. data/ruby-geonames.gemspec +24 -0
  23. data/spec/fixtures/country_info/thailand.xml.http +29 -0
  24. data/spec/fixtures/country_subdivision/ontario.xml.http +20 -0
  25. data/spec/fixtures/countrycode/canada.xml.http +16 -0
  26. data/spec/fixtures/find_nearby/marchtrenk.xml.http +37 -0
  27. data/spec/fixtures/find_nearby/wilkinson.xml.http +23 -0
  28. data/spec/fixtures/find_nearby_place_name/oshawa.xml.http +23 -0
  29. data/spec/fixtures/find_nearby_postal_codes/oshawa.xml.http +81 -0
  30. data/spec/fixtures/find_nearby_wikipedia/general_motors_centre.xml.http +81 -0
  31. data/spec/fixtures/find_nearest_intersection/park_ave_and_e_51st_st.xml.http +24 -0
  32. data/spec/fixtures/hierarchy/zurich.xml.http +87 -0
  33. data/spec/fixtures/postal_code_search/lat_lng.xml.http +81 -0
  34. data/spec/fixtures/postal_code_search/oshawa.xml.http +77 -0
  35. data/spec/fixtures/search/austria.xml.http +146 -0
  36. data/spec/fixtures/search/marchtrenk.xml.http +93 -0
  37. data/spec/fixtures/search/upper_austria.xml.http +48 -0
  38. data/spec/fixtures/timezone/america_toronto.xml.http +24 -0
  39. data/spec/fixtures/wikipedia_bounding_box/wyoming.xml.http +154 -0
  40. data/spec/geonames/postal_code_search_criteria_spec.rb +31 -0
  41. data/spec/geonames/web_service/country_code_spec.rb +24 -0
  42. data/spec/geonames/web_service/country_info_spec.rb +42 -0
  43. data/spec/geonames/web_service/country_subdivision_spec.rb +24 -0
  44. data/spec/geonames/web_service/find_bounding_box_wikipedia_spec.rb +28 -0
  45. data/spec/geonames/web_service/find_nearby_place_name_spec.rb +24 -0
  46. data/spec/geonames/web_service/find_nearby_postal_codes_spec.rb +29 -0
  47. data/spec/geonames/web_service/find_nearby_spec.rb +41 -0
  48. data/spec/geonames/web_service/find_nearby_wikipedia_spec.rb +26 -0
  49. data/spec/geonames/web_service/find_nearest_intersection_spec.rb +18 -0
  50. data/spec/geonames/web_service/hierarchy_spec.rb +23 -0
  51. data/spec/geonames/web_service/postal_code_search_spec.rb +49 -0
  52. data/spec/geonames/web_service/search_spec.rb +54 -0
  53. data/spec/geonames/web_service/timezone_spec.rb +22 -0
  54. data/spec/geonames/web_service_spec.rb +13 -0
  55. data/spec/spec_helper.rb +13 -0
  56. data/spec/support/fakeweb.rb +9 -0
  57. metadata +152 -61
  58. data/README +0 -0
  59. data/geonames-0.2.2.gem +0 -0
  60. data/geonames.gemspec +0 -18
  61. data/lib/intersection.rb +0 -42
  62. data/lib/main.rb +0 -63
  63. data/lib/postal_code.rb +0 -40
  64. data/lib/postal_code_search_criteria.rb +0 -84
  65. data/lib/toponym.rb +0 -45
  66. data/lib/toponym_search_criteria.rb +0 -44
  67. data/lib/web_service.rb +0 -493
  68. data/nbproject/private/private.properties +0 -0
  69. data/nbproject/private/private.xml +0 -4
  70. data/nbproject/project.properties +0 -3
  71. data/nbproject/project.xml +0 -15
@@ -0,0 +1,24 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 13 Nov 2010 18:03:56 GMT
3
+ Server: Apache/2.2.13 (Linux/SUSE)
4
+ Cache-Control: no-cache
5
+ Access-Control-Allow-Origin: *
6
+ Transfer-Encoding: chunked
7
+ Content-Type: text/xml;charset=UTF-8
8
+
9
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
10
+ <geonames>
11
+ <timezone>
12
+ <countryCode>CA</countryCode>
13
+ <countryName>Canada</countryName>
14
+ <lat>43.900120387</lat>
15
+ <lng>-78.882869834</lng>
16
+ <timezoneId>America/Toronto</timezoneId>
17
+ <dstOffset>-4.0</dstOffset>
18
+ <gmtOffset>-5.0</gmtOffset>
19
+ <rawOffset>-5.0</rawOffset>
20
+ <time>2010-11-13 13:03</time>
21
+ <sunrise>2010-11-13 07:07</sunrise>
22
+ <sunset>2010-11-13 16:51</sunset>
23
+ </timezone>
24
+ </geonames>
@@ -0,0 +1,154 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sun, 14 Nov 2010 04:46:36 GMT
3
+ Server: Apache/2.2.13 (Linux/SUSE)
4
+ Cache-Control: no-cache
5
+ Access-Control-Allow-Origin: *
6
+ Transfer-Encoding: chunked
7
+ Content-Type: text/xml;charset=UTF-8
8
+
9
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
10
+ <geonames>
11
+ <entry>
12
+ <lang>en</lang>
13
+ <title>Wyoming</title>
14
+ <summary>The State of Wyoming is a state in the western region of the United States of America. The majority of the state is dominated by the mountain ranges and rangelands of the Rocky Mountain West, while the easternmost section of the state is a high altitude prairie region known as the High Plains. The tenth largest U.S. state by size, Wyoming is the least populous, with a U.S (...)</summary>
15
+ <feature>state</feature>
16
+ <countryCode>US</countryCode>
17
+ <population>0</population>
18
+ <elevation>0</elevation>
19
+ <lat>43</lat>
20
+ <lng>-107.5</lng>
21
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Wyoming</wikipediaUrl>
22
+ <thumbnailImg/>
23
+ </entry>
24
+ <entry>
25
+ <lang>en</lang>
26
+ <title>USS Orlando (PF-99)</title>
27
+ <summary>USS ''Orlando'' (PF-99), a ''Tacoma''-class frigate, was the only ship of the United States Navy to be named for Orlando, Florida. She was authorized with the hull classification symbol PG-207 but reclassified PF-99 in April 1943. Her keel was laid down 2 August 1943 under a Maritime Commission Contract by American Ship Building Company, in Cleveland, Ohio (...)</summary>
28
+ <feature/>
29
+ <countryCode> </countryCode>
30
+ <population>0</population>
31
+ <elevation>0</elevation>
32
+ <lat>43</lat>
33
+ <lng>165</lng>
34
+ <wikipediaUrl>http://en.wikipedia.org/wiki/USS_Orlando_%28PF-99%29</wikipediaUrl>
35
+ <thumbnailImg/>
36
+ </entry>
37
+ <entry>
38
+ <lang>en</lang>
39
+ <title>Point Edward, Ontario</title>
40
+ <summary>Point Edward is a village (adjacent to Sarnia, Ontario) in the Canadian province of Ontario. Point Edward sits opposite Port Huron, Michigan at the mouth of the St. Clair River. As of 2006, the population was 2,019. The population in 2001 was 2,101. (A population change of -3.9%). The area is 3.27 square kilometres. In the summer of 2003, Point Edward celebrated its 125th anniversary (...)</summary>
41
+ <feature>city</feature>
42
+ <countryCode>CA</countryCode>
43
+ <population>0</population>
44
+ <elevation>0</elevation>
45
+ <lat>43</lat>
46
+ <lng>-82.4</lng>
47
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Point_Edward%2C_Ontario</wikipediaUrl>
48
+ <thumbnailImg/>
49
+ </entry>
50
+ <entry>
51
+ <lang>en</lang>
52
+ <title>Greys River</title>
53
+ <summary>with its confluence near Alpine in northern Lincoln County, Wyoming, USA. The river is about 65 miles (105 km.) in length, starting high up in the Wyoming Range, 40 miles south of the town of Alpine. The river eventually flows into the Snake River forming the Snake River Canyon."Greys River." ''Merriam-Webster's Geographical Dictionary'', 3rd ed. 2001 (...)</summary>
54
+ <feature>adm2nd</feature>
55
+ <countryCode> </countryCode>
56
+ <population>0</population>
57
+ <elevation>0</elevation>
58
+ <lat>43</lat>
59
+ <lng>-110.8</lng>
60
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Greys_River</wikipediaUrl>
61
+ <thumbnailImg/>
62
+ </entry>
63
+ <entry>
64
+ <lang>en</lang>
65
+ <title>Ömnögovi Province</title>
66
+ <summary>(provinces) of Mongolia, located in the south of the country, in the Gobi Desert. Its capital is Dalanzadgad. The province is rich in mineral deposits, including gold and copper. Ömnögovi includes several well known tourist areas, including the Flaming Cliffs, Gobi Gurvansaikhan National Park and Khongoryn Els - The Singing Sand Dunes. (...)</summary>
67
+ <feature/>
68
+ <countryCode> </countryCode>
69
+ <population>0</population>
70
+ <elevation>0</elevation>
71
+ <lat>43</lat>
72
+ <lng>104.25</lng>
73
+ <wikipediaUrl>http://en.wikipedia.org/wiki/%C3%96mn%C3%B6govi_Province</wikipediaUrl>
74
+ <thumbnailImg/>
75
+ </entry>
76
+ <entry>
77
+ <lang>en</lang>
78
+ <title>Genesee County, New York</title>
79
+ <summary>Genesee County is a county located in Western New York, United States. As of the 2000 census, the population was 60,370.[http://quickfacts.census.gov/qfd/states/36/36037.html U.S. Census Bureau, State &amp; County QuickFacts, Genesee County, New York] Its name is from the Seneca Indian word Gen-nis'-hee-yo meaning "The Beautiful Valley (...)</summary>
80
+ <feature>adm2nd</feature>
81
+ <countryCode> </countryCode>
82
+ <population>0</population>
83
+ <elevation>0</elevation>
84
+ <lat>43</lat>
85
+ <lng>-78.19</lng>
86
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Genesee_County%2C_New_York</wikipediaUrl>
87
+ <thumbnailImg/>
88
+ </entry>
89
+ <entry>
90
+ <lang>en</lang>
91
+ <title>Welland County, Ontario</title>
92
+ <summary>Welland County (area, excluding cities was 226,970 acres) is a historic county in the Canadian province of Ontario. The county was formed in 1851 from Lincoln County. The county was named from the Welland River. The river got its name from John Grave Simcoe who named it after a stream in Lincolnshire, England (...)</summary>
93
+ <feature>adm2nd</feature>
94
+ <countryCode>CA</countryCode>
95
+ <population>0</population>
96
+ <elevation>0</elevation>
97
+ <lat>43</lat>
98
+ <lng>-79.0833</lng>
99
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Welland_County%2C_Ontario</wikipediaUrl>
100
+ <thumbnailImg/>
101
+ </entry>
102
+ <entry>
103
+ <lang>en</lang>
104
+ <title>Middlesex County, Ontario</title>
105
+ <summary>Middlesex County is a census division located in Western Ontario. The administrative centre of the county is the city of London, though the city is now separated from the jurisdiction of the county. The population of the county in 2006 was 422,333, of which 70,000 live outside of the city of London but the entire county is within the London census metropolitan area (...)</summary>
106
+ <feature>adm2nd</feature>
107
+ <countryCode>CA</countryCode>
108
+ <population>0</population>
109
+ <elevation>0</elevation>
110
+ <lat>43</lat>
111
+ <lng>-81.5</lng>
112
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Middlesex_County%2C_Ontario</wikipediaUrl>
113
+ <thumbnailImg/>
114
+ </entry>
115
+ <entry>
116
+ <lang>en</lang>
117
+ <title>Otofuke, Hokkaidō</title>
118
+ <summary>located in Katō District, Tokachi, Hokkaidō, Japan. As of 2004, the town has an estimated population of 41,935 and a density of 89.97 persons per km². The total area is 466.09 km². (...)</summary>
119
+ <feature>city</feature>
120
+ <countryCode>JP</countryCode>
121
+ <population>0</population>
122
+ <elevation>0</elevation>
123
+ <lat>43</lat>
124
+ <lng>143.2</lng>
125
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Otofuke%2C_Hokkaid%C5%8D</wikipediaUrl>
126
+ <thumbnailImg/>
127
+ </entry>
128
+ <entry>
129
+ <lang>en</lang>
130
+ <title>Yuni, Hokkaidō</title>
131
+ <summary>is a town located in Yūbari District, Sorachi, Hokkaidō, Japan. As of 2004, the town has an estimated population of 6,677 and a density of 49.88 persons per km². The total area is 133.86 km². (...)</summary>
132
+ <feature>city</feature>
133
+ <countryCode>JP</countryCode>
134
+ <population>0</population>
135
+ <elevation>0</elevation>
136
+ <lat>43</lat>
137
+ <lng>141.7833</lng>
138
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Yuni%2C_Hokkaid%C5%8D</wikipediaUrl>
139
+ <thumbnailImg/>
140
+ </entry>
141
+ <entry>
142
+ <lang>en</lang>
143
+ <title>Kushiro, Hokkaidō (town)</title>
144
+ <summary>located in Kushiro District, Kushiro Subprefecture, Hokkaidō, Japan. As of September 30, 2004 it has an estimated population of 22,602 and an area of 252.57 km². (...)</summary>
145
+ <feature>city</feature>
146
+ <countryCode>JP</countryCode>
147
+ <population>0</population>
148
+ <elevation>0</elevation>
149
+ <lat>43</lat>
150
+ <lng>144.4667</lng>
151
+ <wikipediaUrl>http://en.wikipedia.org/wiki/Kushiro%2C_Hokkaid%C5%8D_%28town%29</wikipediaUrl>
152
+ <thumbnailImg/>
153
+ </entry>
154
+ </geonames>
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe PostalCodeSearchCriteria do
5
+ describe "#to_query_params_string" do
6
+ context "with a numeric latitude" do
7
+ let(:latitude) { 25.123 }
8
+ before(:each) { subject.latitude = latitude }
9
+ it("contains the lat parameter") { subject.to_query_params_string.should =~ /lat=#{latitude}/ }
10
+ end
11
+
12
+ context "with a numeric longitude" do
13
+ let(:longitude) { -52.123 }
14
+ before(:each) { subject.longitude = longitude }
15
+ it("contains the lng parameter") { subject.to_query_params_string.should =~ /lng=#{longitude}/ }
16
+ end
17
+
18
+ context "with a numeric max_rows" do
19
+ let(:max_rows) { 1 }
20
+ before(:each) { subject.max_rows = max_rows }
21
+ it("contains the maxRows parameter") { subject.to_query_params_string.should =~ /maxRows=#{max_rows}/ }
22
+ end
23
+
24
+ context "with a style" do
25
+ let(:style) { "SHORT" }
26
+ before(:each) { subject.style = style }
27
+ it("contains the style parameter") { subject.to_query_params_string.should =~ /style=#{style}/ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".country_code" do
6
+ subject { WebService.country_code(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'countrycode', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/countrycode\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "canada.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ it { should be_a_kind_of(Array) }
16
+
17
+ it "returns Toponym instances" do
18
+ subject.each do |element|
19
+ element.should be_a_kind_of Toponym
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".country_info" do
6
+ subject { country_info }
7
+ let(:country_info) { WebService.country_info(country_code) }
8
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'country_info', fixture) }
9
+
10
+ context "with a country code of 'TH'" do
11
+ before { FakeWeb.register_uri :get, /\/countryInfo\?.*&country=#{country_code}/, :response => response }
12
+ let(:fixture) { "thailand.xml.http" }
13
+ let(:country_code) { "TH" }
14
+
15
+ it { should be_a_kind_of(CountryInfo) }
16
+
17
+ its(:country_code) { should == 'TH' }
18
+ its(:country_name) { should == 'Thailand' }
19
+ its(:iso_numeric) { should == 764 }
20
+ its(:iso_alpha_3) { should == 'THA' }
21
+ its(:fips_code) { should == 'TH' }
22
+ its(:continent) { should == 'AS' }
23
+ its(:capital) { should == 'Bangkok' }
24
+ its(:area_sq_km) { should == 514000.0 }
25
+ its(:population) { should == 67089500 }
26
+ its(:currency_code) { should == 'THB' }
27
+ its(:geoname_id) { should == 1605651 }
28
+ its(:languages) { should == ['th', 'en'] }
29
+
30
+ describe "#bounding_box" do
31
+ subject { country_info.bounding_box }
32
+
33
+ it { should be_a_kind_of(BoundingBox) }
34
+ its(:north_point) { should == 20.463194 }
35
+ its(:south_point) { should == 5.61 }
36
+ its(:east_point) { should == 105.639389 }
37
+ its(:west_point) { should == 97.345642 }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".country_subdivision" do
6
+ subject { WebService.country_subdivision(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'country_subdivision', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/countrySubdivision\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "ontario.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ it { should be_a_kind_of(Array) }
16
+
17
+ it "returns CountrySubdivision instances" do
18
+ subject.each do |element|
19
+ element.should be_a_kind_of CountrySubdivision
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_bounding_box_wikipedia" do
6
+ subject { WebService.find_bounding_box_wikipedia({ :north => north, :east => east, :south => south, :west => west }) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'wikipedia_bounding_box', fixture) }
8
+
9
+ # TODO Why doesn't mocking the following regex work?
10
+ # /\/wikipediaBoundingBox\?.*north=#{north}&east=#{east}&south=#{south}&west=#{west}/
11
+ before { FakeWeb.register_uri :get, /\/wikipediaBoundingBox\?/, :response => response }
12
+ let(:fixture) { "wyoming.xml.http" }
13
+
14
+ let(:north) { +43.900120387 }
15
+ let(:east) { -78.882869834 }
16
+ let(:south) { +43.82 }
17
+ let(:west) { +79.0 }
18
+
19
+ it { should be_a_kind_of(Array) }
20
+
21
+ it "returns WikipediaArticle instances" do
22
+ subject.each do |element|
23
+ element.should be_a_kind_of WikipediaArticle
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_nearby_place_name" do
6
+ subject { WebService.find_nearby_place_name(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby_place_name', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/findNearbyPlaceName\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "oshawa.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ it { should be_a_kind_of(Array) }
16
+
17
+ it "returns Toponym instances" do
18
+ subject.each do |element|
19
+ element.should be_a_kind_of Toponym
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_nearby_postal_codes" do
6
+ subject { WebService.find_nearby_postal_codes(criteria) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby_postal_codes', fixture) }
8
+
9
+ context "lookup by place name" do
10
+ before { FakeWeb.register_uri :get, /\/findNearbyPostalCodes\?.*&placename=Oshawa/, :response => response }
11
+ let(:fixture) { "oshawa.xml.http" }
12
+
13
+ let :criteria do
14
+ Geonames::PostalCodeSearchCriteria.new.tap do |criteria|
15
+ criteria.place_name = "Oshawa"
16
+ end
17
+ end
18
+
19
+ it { should be_a_kind_of(Array) }
20
+
21
+ it "returns PostalCode instances" do
22
+ subject.each do |element|
23
+ element.should be_a_kind_of PostalCode
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_nearby" do
6
+ subject { WebService.find_nearby(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/findNearby\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "wilkinson.xml.http" }
11
+
12
+ let(:latitude) { +37.501707 }
13
+ let(:longitude) { -122.468838 }
14
+
15
+ it { should be_a_kind_of(Array) }
16
+
17
+ it "returns Toponym instances" do
18
+ subject.each do |element|
19
+ element.should be_a_kind_of Toponym
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".find_nearby with full-style" do
25
+ let(:latitude) { 48.18 }
26
+ let(:longitude) { 14.11 }
27
+
28
+ before { FakeWeb.register_uri :get, /\/findNearby\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
29
+ let(:fixture) { "marchtrenk.xml.http" }
30
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby', fixture) }
31
+
32
+ subject { WebService.find_nearby(latitude, longitude, style: 'FULL') }
33
+
34
+ it "return full Toponym instance" do
35
+ subject.each do |element|
36
+ element.should be_a_kind_of Toponym
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_nearby_wikipedia" do
6
+ subject { WebService.find_nearby_wikipedia({ :lat => latitude, :long => longitude }) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby_wikipedia', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/findNearbyWikipedia\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "general_motors_centre.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ context "lookup by latitude and longitude" do
16
+ it { should be_a_kind_of(Array) }
17
+
18
+ it "returns WikipediaArticle instances" do
19
+ subject.each do |element|
20
+ element.should be_a_kind_of WikipediaArticle
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end