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,18 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".find_nearest_intersection" do
6
+ subject { WebService.find_nearest_intersection(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearest_intersection', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/findNearestIntersection\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "park_ave_and_e_51st_st.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ it { should be_a_kind_of(Intersection) }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".hierarchy" do
6
+ subject { WebService.hierarchy(geonameId) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'hierarchy', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/hierarchy\?geonameId=#{geonameId}/, :response => response }
10
+ let(:fixture) { "zurich.xml.http" }
11
+
12
+ let(:geonameId) { 2657896 }
13
+
14
+ it { should be_a_kind_of(Array) }
15
+
16
+ it "returns Toponym instances" do
17
+ subject.each do |element|
18
+ element.should be_a_kind_of Toponym
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".postal_code_search" do
6
+ subject { WebService.postal_code_search(criteria) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'postal_code_search', fixture) }
8
+
9
+ context "lookup by place name" do
10
+ before { FakeWeb.register_uri :get, /\/postalCodeSearch\?.*&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
+
28
+ context "lookup by latitude and longitude" do
29
+ before { FakeWeb.register_uri :get, /\/postalCodeSearch\?.*&lat=47.*&lng=9/, :response => response }
30
+ let(:fixture) { "lat_lng.xml.http" }
31
+
32
+ let :criteria do
33
+ Geonames::PostalCodeSearchCriteria.new.tap do |criteria|
34
+ criteria.latitude = 47
35
+ criteria.longitude = 9
36
+ end
37
+ end
38
+
39
+ it { should be_a_kind_of(Array) }
40
+
41
+ it "returns PostalCode instances" do
42
+ subject.each do |element|
43
+ element.should be_a_kind_of PostalCode
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+
6
+ describe ".search Marchtrenk with full-style" do
7
+ let(:query) { "Marchtrenk" }
8
+
9
+ before { FakeWeb.register_uri :get, /\/search\?.*q=#{query}/, :response => response }
10
+ let(:fixture) { "marchtrenk.xml.http" }
11
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'search', fixture) }
12
+
13
+ subject { WebService.search(ToponymSearchCriteria.new(q: query, style: 'FULL')) }
14
+
15
+ it "return full Toponym instance" do
16
+ subject.toponyms.each do |element|
17
+ element.should be_a_kind_of Toponym
18
+ end
19
+ end
20
+ end
21
+
22
+ describe ".search Upper Austria with full-style" do
23
+ let(:query) { "Upper Austria" }
24
+
25
+ before { FakeWeb.register_uri :get, /\/search\?.*q=#{query.gsub(' ','.')}.*/, :response => response }
26
+ let(:fixture) { "upper_austria.xml.http" }
27
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'search', fixture) }
28
+
29
+ subject { WebService.search(ToponymSearchCriteria.new(q: query, style: 'FULL', max_rows: "1")).toponyms.first }
30
+
31
+ it "return full Toponym instance" do
32
+ subject.should be_a_kind_of Toponym
33
+ subject.alternate_names.count.should == 7
34
+ end
35
+ end
36
+
37
+ describe ".search Austria with full-style" do
38
+ let(:query) { "Austria" }
39
+ let(:country_code) { "AT" }
40
+
41
+ before { FakeWeb.register_uri :get, /\/search\?.*q=#{query}.*/, :response => response }
42
+ let(:fixture) { "austria.xml.http" }
43
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'search', fixture) }
44
+
45
+ subject { WebService.search(ToponymSearchCriteria.new(q: query, country_code: country_code, style: 'FULL', max_rows: "1")).toponyms.first }
46
+
47
+ it "return full Toponym instance" do
48
+ subject.should be_a_kind_of Toponym
49
+ subject.alternate_names.count.should == 105
50
+ subject.timezone.should == "Europe/Vienna"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".timezone" do
6
+ subject { WebService.timezone(latitude, longitude) }
7
+ let(:response) { File.read File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'timezone', fixture) }
8
+
9
+ before { FakeWeb.register_uri :get, /\/timezone\?.*lat=#{latitude}&lng=#{longitude}/, :response => response }
10
+ let(:fixture) { "america_toronto.xml.http" }
11
+
12
+ let(:latitude) { +43.900120387 }
13
+ let(:longitude) { -78.882869834 }
14
+
15
+ it { should be_a_kind_of(Timezone) }
16
+
17
+ it "should have the raw offset set" do
18
+ subject.raw_offset.should == -5.0
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ module Geonames
4
+ describe WebService do
5
+ describe ".make_request" do
6
+ it "uses a custom User-Agent header" do
7
+ Net::HTTP::Get.should_receive(:new).with(anything, hash_including('User-Agent' => USER_AGENT))
8
+ Net::HTTP.stub! :start
9
+ WebService.make_request '/foo?a=a'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/autorun'
4
+
5
+ RSpec.configure do |config|
6
+ config.mock_with :rspec
7
+ end
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }
12
+
13
+ require 'geonames'
@@ -0,0 +1,9 @@
1
+ require 'fakeweb'
2
+
3
+ FakeWeb.allow_net_connect = false
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:each) do
7
+ FakeWeb.clean_registry
8
+ end
9
+ end
metadata CHANGED
@@ -1,78 +1,169 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: geonames
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Adam Wisniewski
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2008-01-09 00:00:00 -05:00
13
- default_executable:
14
- dependencies: []
15
-
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakeweb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
16
78
  description:
17
- email: adamw@tbcn.ca
79
+ email:
80
+ - adamw@tbcn.ca
18
81
  executables: []
19
-
20
82
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - README
24
- files:
25
- - geonames-0.2.2.gem
26
- - geonames.gemspec
27
- - lib
28
- - lib/address.rb
29
- - lib/country_subdivision.rb
83
+ extra_rdoc_files:
84
+ - README.markdown
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - Gemfile
89
+ - README.markdown
90
+ - Rakefile
91
+ - init.rb
30
92
  - lib/geonames.rb
31
- - lib/intersection.rb
32
- - lib/main.rb
33
- - lib/postal_code.rb
34
- - lib/postal_code_search_criteria.rb
35
- - lib/Rakefile.rb
36
- - lib/timezone.rb
37
- - lib/toponym.rb
38
- - lib/toponym_search_criteria.rb
39
- - lib/toponym_search_result.rb
40
- - lib/web_service.rb
41
- - lib/wikipedia_article.rb
42
- - nbproject
43
- - nbproject/private
44
- - nbproject/private/private.properties
45
- - nbproject/private/private.xml
46
- - nbproject/private/profiler
47
- - nbproject/project.properties
48
- - nbproject/project.xml
49
- - README
50
- - test
51
- has_rdoc: true
52
- homepage: http://www.tbcn.ca/ruby_geonames
93
+ - lib/geonames/bounding_box.rb
94
+ - lib/geonames/config.rb
95
+ - lib/geonames/country_info.rb
96
+ - lib/geonames/country_subdivision.rb
97
+ - lib/geonames/intersection.rb
98
+ - lib/geonames/postal_code.rb
99
+ - lib/geonames/postal_code_search_criteria.rb
100
+ - lib/geonames/timezone.rb
101
+ - lib/geonames/toponym.rb
102
+ - lib/geonames/toponym_search_criteria.rb
103
+ - lib/geonames/toponym_search_result.rb
104
+ - lib/geonames/version.rb
105
+ - lib/geonames/web_service.rb
106
+ - lib/geonames/wikipedia_article.rb
107
+ - ruby-geonames.gemspec
108
+ - spec/fixtures/country_info/thailand.xml.http
109
+ - spec/fixtures/country_subdivision/ontario.xml.http
110
+ - spec/fixtures/countrycode/canada.xml.http
111
+ - spec/fixtures/find_nearby/marchtrenk.xml.http
112
+ - spec/fixtures/find_nearby/wilkinson.xml.http
113
+ - spec/fixtures/find_nearby_place_name/oshawa.xml.http
114
+ - spec/fixtures/find_nearby_postal_codes/oshawa.xml.http
115
+ - spec/fixtures/find_nearby_wikipedia/general_motors_centre.xml.http
116
+ - spec/fixtures/find_nearest_intersection/park_ave_and_e_51st_st.xml.http
117
+ - spec/fixtures/hierarchy/zurich.xml.http
118
+ - spec/fixtures/postal_code_search/lat_lng.xml.http
119
+ - spec/fixtures/postal_code_search/oshawa.xml.http
120
+ - spec/fixtures/search/austria.xml.http
121
+ - spec/fixtures/search/marchtrenk.xml.http
122
+ - spec/fixtures/search/upper_austria.xml.http
123
+ - spec/fixtures/timezone/america_toronto.xml.http
124
+ - spec/fixtures/wikipedia_bounding_box/wyoming.xml.http
125
+ - spec/geonames/postal_code_search_criteria_spec.rb
126
+ - spec/geonames/web_service/country_code_spec.rb
127
+ - spec/geonames/web_service/country_info_spec.rb
128
+ - spec/geonames/web_service/country_subdivision_spec.rb
129
+ - spec/geonames/web_service/find_bounding_box_wikipedia_spec.rb
130
+ - spec/geonames/web_service/find_nearby_place_name_spec.rb
131
+ - spec/geonames/web_service/find_nearby_postal_codes_spec.rb
132
+ - spec/geonames/web_service/find_nearby_spec.rb
133
+ - spec/geonames/web_service/find_nearby_wikipedia_spec.rb
134
+ - spec/geonames/web_service/find_nearest_intersection_spec.rb
135
+ - spec/geonames/web_service/hierarchy_spec.rb
136
+ - spec/geonames/web_service/postal_code_search_spec.rb
137
+ - spec/geonames/web_service/search_spec.rb
138
+ - spec/geonames/web_service/timezone_spec.rb
139
+ - spec/geonames/web_service_spec.rb
140
+ - spec/spec_helper.rb
141
+ - spec/support/fakeweb.rb
142
+ homepage: http://github.com/elecnix/ruby-geonames
143
+ licenses:
144
+ - Apache 2.0
53
145
  post_install_message:
54
146
  rdoc_options: []
55
-
56
- require_paths:
147
+ require_paths:
57
148
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- version:
64
- required_rubygems_version: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
69
- version:
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
70
161
  requirements: []
71
-
72
162
  rubyforge_project:
73
- rubygems_version: 0.9.5
163
+ rubygems_version: 1.8.23
74
164
  signing_key:
75
- specification_version: 2
165
+ specification_version: 3
76
166
  summary: Ruby library for Geonames Web Services (http://www.geonames.org/export/)
77
- test_files: []
78
-
167
+ test_files:
168
+ - spec/geonames/postal_code_search_criteria_spec.rb
169
+ - spec/geonames/web_service_spec.rb
data/README DELETED
File without changes
File without changes
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'date'
3
-
4
- SPEC = Gem::Specification.new do |s|
5
- s.name = "geonames"
6
- s.version = "0.2.2"
7
- s.author = "Adam Wisniewski"
8
- s.email = "adamw@tbcn.ca"
9
- s.date = s.date = Date.today.to_s
10
- s.homepage = "http://www.tbcn.ca/ruby_geonames"
11
- s.platform = Gem::Platform::RUBY
12
- s.summary = "Ruby library for Geonames Web Services (http://www.geonames.org/export/)"
13
- candidates = Dir.glob("{bin,docs,lib,test}/**/*")
14
- s.files = Dir.glob('**/*')
15
- s.require_path = "lib"
16
- s.has_rdoc = true
17
- s.extra_rdoc_files = ["README"]
18
- end