geonames_patched 0.2.2

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.
data/README ADDED
File without changes
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'date'
3
+
4
+ SPEC = Gem::Specification.new do |s|
5
+ s.name = "geonames_patched"
6
+ s.version = "0.2.2"
7
+ s.author = "Calvin Cheung"
8
+ s.email = "calvin@presdo.com"
9
+ s.date = s.date = Date.today.to_s
10
+ s.homepage = "http://github.com/calvin681/geonames_patched"
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "A version of Adam Wisniewksi's geonames gem that includes username/password login."
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
@@ -0,0 +1,18 @@
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 = "Calvin Cheung"
8
+ s.email = "calvin@presdo.com"
9
+ s.date = s.date = Date.today.to_s
10
+ s.homepage = "http://github.com/calvin681/geonames_patched"
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "A version of Adam Wisniewksi's geonames gem that includes username/password login."
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
data/lib/Rakefile.rb ADDED
@@ -0,0 +1,21 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ require 'rake'
20
+ require 'rake/testtask'
21
+ require 'rake/rdoctask'
data/lib/address.rb ADDED
@@ -0,0 +1,25 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class Address
21
+
22
+ end
23
+ end
24
+
25
+
@@ -0,0 +1,32 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class CountrySubdivision
21
+ attr :country_code
22
+ attr :country_name
23
+ attr :admin_code_1
24
+ attr :admin_name_1
25
+
26
+ attr_writer :country_code, :country_name
27
+ attr_writer :admin_name_1, :admin_code_1
28
+
29
+ end
30
+ end
31
+
32
+
data/lib/geonames.rb ADDED
@@ -0,0 +1,62 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ require 'cgi'
20
+ require 'net/http'
21
+ require 'rexml/document'
22
+
23
+ require File.dirname(__FILE__) + '/web_service'
24
+ require File.dirname(__FILE__) + '/toponym'
25
+ require File.dirname(__FILE__) + '/toponym_search_result'
26
+ require File.dirname(__FILE__) + '/toponym_search_criteria'
27
+ require File.dirname(__FILE__) + '/postal_code'
28
+ require File.dirname(__FILE__) + '/postal_code_search_criteria'
29
+ require File.dirname(__FILE__) + '/timezone'
30
+ require File.dirname(__FILE__) + '/country_subdivision'
31
+ require File.dirname(__FILE__) + '/wikipedia_article'
32
+ require File.dirname(__FILE__) + '/intersection'
33
+
34
+ module Geonames
35
+
36
+ GEONAMES_SERVER = "http://ws.geonames.org"
37
+ GEONAMES_COMMERCIAL_SERVER = "http://ws.geonames.net"
38
+ USER_AGENT = "geonames ruby webservice client 0.1"
39
+
40
+ @@commercial_username = nil
41
+
42
+ def self.username
43
+ @@commercial_username
44
+ end
45
+
46
+ def self.username=(user_name)
47
+ puts "Using Geonames commercial web service with username='#{user_name}'"
48
+ @@commercial_username = user_name
49
+ end
50
+
51
+ def self.build_url(ws_name)
52
+ unless @@commercial_username.blank?
53
+ url = GEONAMES_COMMERCIAL_SERVER
54
+ user_param = "&username=#{@@commercial_username}"
55
+ else
56
+ url = GEONAMES_SERVER
57
+ user_param = ''
58
+ end
59
+ url + ws_name + user_param
60
+ end
61
+ end
62
+
@@ -0,0 +1 @@
1
+ require 'geonames'
@@ -0,0 +1,42 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class Intersection
21
+ attr :street_1
22
+ attr :street_2
23
+ attr :latitude
24
+ attr :longitude
25
+ attr :distance
26
+ attr :postal_code
27
+ attr :place_name
28
+ attr :country_code
29
+ attr :admin_code_1
30
+ attr :admin_name_2
31
+ attr :admin_code_2
32
+ attr :admin_name_1
33
+
34
+ attr_writer :street_1, :street_2
35
+ attr_writer :postal_code, :place_name, :country_code
36
+ attr_writer :latitude, :longitude, :admin_name_1
37
+ attr_writer :admin_code_1, :admin_name_2, :admin_code_2
38
+ attr_writer :distance
39
+ end
40
+ end
41
+
42
+
data/lib/main.rb ADDED
@@ -0,0 +1,63 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ # Contributions by Andrew Turner, High Earth Orbit
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ # use this file except in compliance with the License. You may obtain a copy of
8
+ # the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+ #
18
+ #=============================================================================
19
+
20
+ require 'geonames'
21
+ require 'pp'
22
+
23
+ # get the nearest intersection
24
+ intersection = Geonames::WebService.find_nearest_intersection 40.7574053333333, -73.9734773333333
25
+ puts intersection.street_1 #=> Park Ave
26
+ puts intersection.street_2 #=> E 51st St
27
+
28
+ # get wikipedia articles by lat / long
29
+ articles_nearby = Geonames::WebService.find_nearby_wikipedia :lat => 43.900120387, :long => -78.882869834
30
+ p articles_nearby
31
+
32
+ # get wikipedia articles by bounding box
33
+ articles_nearby = Geonames::WebService.find_bounding_box_wikipedia :north => 43.900120387, :east => -78.882869834, :south => 43.82, :west => 79.0
34
+ p articles_nearby
35
+
36
+ # get list of places near by longitude/longitude location
37
+ places_nearby = Geonames::WebService.find_nearby_place_name 43.900120387, -78.882869834
38
+ p places_nearby
39
+
40
+ # get timezone for longitude/longitude location
41
+ timezone = Geonames::WebService.timezone 43.900120387, -78.882869834
42
+ p timezone
43
+
44
+ # get country code for longitude/longitude location
45
+ country_code = Geonames::WebService.country_code 43.900120387, -78.882869834
46
+ p country_code
47
+
48
+ # get country sub-division info for longitude/longitude location
49
+ country_subdivision = Geonames::WebService.country_subdivision 43.900120387, -78.882869834
50
+ p country_subdivision
51
+
52
+ # get postal codes for a given location
53
+ postal_code_sc = Geonames::PostalCodeSearchCriteria.new
54
+ postal_code_sc.place_name = "Oshawa"
55
+ postal_codes = Geonames::WebService.postal_code_search postal_code_sc
56
+ p postal_codes
57
+
58
+ # get nearby postal codes for a place name
59
+ postal_code_sc = Geonames::PostalCodeSearchCriteria.new
60
+ postal_code_sc.place_name = "Oshawa"
61
+ postal_codes_nearby = Geonames::WebService.find_nearby_postal_codes postal_code_sc
62
+ p postal_codes_nearby
63
+
@@ -0,0 +1,40 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class PostalCode
21
+ attr :postal_code
22
+ attr :place_name
23
+ attr :country_code
24
+ attr :latitude
25
+ attr :longitude
26
+ attr :admin_name_1
27
+ attr :admin_code_1
28
+ attr :admin_name_2
29
+ attr :admin_code_2
30
+ attr :distance
31
+
32
+ attr_writer :postal_code, :place_name, :country_code
33
+ attr_writer :latitude, :longitude, :admin_name_1
34
+ attr_writer :admin_code_1, :admin_name_2, :admin_code_2
35
+ attr_writer :distance
36
+
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,84 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class PostalCodeSearchCriteria
21
+
22
+ attr :postal_code
23
+ attr :place_name
24
+ attr :country_code
25
+ attr :latitude
26
+ attr :longitude
27
+ attr :style
28
+ attr :max_rows
29
+ attr :is_or_operator
30
+ attr :radius
31
+
32
+ attr_writer :postal_code, :place_name, :country_code
33
+ attr_writer :latitude, :longitude, :style
34
+ attr_writer :max_rows, :is_or_operator, :radius
35
+
36
+ def initialize
37
+ @is_or_operator = false
38
+ end
39
+
40
+ def to_query_params_string
41
+ url = ''
42
+
43
+ if !@postal_code.nil?
44
+ url = url + "&postalcode=" + CGI::escape( @postal_code )
45
+ end
46
+
47
+ if !@place_name.nil?
48
+ url = url + "&placename=" + CGI::escape( @place_name )
49
+ end
50
+
51
+ if !@latitude.nil?
52
+ url = url + "&lat=" + CGI::escape( @latitude )
53
+ end
54
+
55
+ if !@longitude.nil?
56
+ url = url + "&lng=" + CGI::escape( @longitude )
57
+ end
58
+
59
+ if !@style.nil?
60
+ url = url + "&style=" + CGI::escape( @style )
61
+ end
62
+
63
+ if !@country_code.nil?
64
+ url = url + "&country=" + CGI::escape( @country_code )
65
+ end
66
+
67
+ if !@max_rows.nil?
68
+ url = url + "&maxRows=" + CGI::escape( @max_rows )
69
+ end
70
+
71
+ if !@radius.nil?
72
+ url = url + "&radius=" + CGI::escape( @radius.to_s )
73
+ end
74
+
75
+ if @is_or_operator
76
+ url = url + "&operator=OR"
77
+ end
78
+
79
+ url
80
+ end
81
+ end
82
+ end
83
+
84
+
data/lib/timezone.rb ADDED
@@ -0,0 +1,29 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class Timezone
21
+ attr :timezone_id
22
+ attr :gmt_offset
23
+ attr :dst_offset
24
+
25
+ attr_writer :timezone_id, :gmt_offset, :dst_offset
26
+ end
27
+ end
28
+
29
+
data/lib/toponym.rb ADDED
@@ -0,0 +1,45 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class Toponym
21
+
22
+ attr :geoname_id
23
+ attr :name
24
+ attr :alternate_names
25
+ attr :country_code
26
+ attr :country_name
27
+ attr :population
28
+ attr :elevation
29
+ attr :feature_class
30
+ attr :feature_class_name
31
+ attr :feature_code
32
+ attr :feature_code_name
33
+ attr :latitude
34
+ attr :longitude
35
+ attr :distance
36
+
37
+ attr_writer :geoname_id, :name, :alternate_names, :country_code
38
+ attr_writer :country_name, :population, :elevation, :feature_class
39
+ attr_writer :feature_class_name, :feature_code,:feature_code_name
40
+ attr_writer :latitude, :longitude, :distance
41
+
42
+ end
43
+ end
44
+
45
+
@@ -0,0 +1,44 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class ToponymSearchCriteria
21
+
22
+ attr :q
23
+ attr :country_code
24
+ attr :name
25
+ attr :name_equals
26
+ attr :name_starts_with
27
+ attr :tag
28
+ attr :language
29
+ attr :style
30
+ attr :feature_class
31
+ attr :feature_codes
32
+ attr :admin_code_1
33
+ attr :max_rows
34
+ attr :start_row
35
+
36
+ attr_writer :q, :country_code, :name, :name_equals
37
+ attr_writer :name_starts_with, :tag, :language, :style
38
+ attr_writer :feature_class, :feature_codes, :admin_code_1
39
+ attr_writer :max_rows, :start_row
40
+
41
+ end
42
+ end
43
+
44
+
@@ -0,0 +1,33 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class ToponymSearchResult
21
+
22
+ attr :total_results_count
23
+ attr :toponyms
24
+
25
+ attr_writer :total_results_count, :toponyms
26
+
27
+ def initialize
28
+ @toponyms = Array.new
29
+ end
30
+ end
31
+ end
32
+
33
+
@@ -0,0 +1,503 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ # Contributions by Andrew Turner, High Earth Orbit
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ # use this file except in compliance with the License. You may obtain a copy of
8
+ # the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+ #
18
+ #=============================================================================
19
+
20
+ module Geonames
21
+ class WebService
22
+ def WebService.get_element_child_text( element, child )
23
+ if !element.elements[child].nil?
24
+ element.elements[child][0].to_s
25
+ end
26
+ end
27
+
28
+ def WebService.get_element_child_float( element, child )
29
+ if !element.elements[child].nil?
30
+ element.elements[child][0].to_s.to_f
31
+ end
32
+ end
33
+
34
+ def WebService.get_element_child_int( element, child )
35
+ if !element.elements[child].nil?
36
+ element.elements[child][0].to_s.to_i
37
+ end
38
+ end
39
+
40
+ def WebService.element_to_postal_code ( element )
41
+ postal_code = PostalCode.new
42
+
43
+ postal_code.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
44
+ postal_code.admin_code_2 = WebService::get_element_child_text( element, 'adminCode2' )
45
+ postal_code.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
46
+ postal_code.admin_name_2 = WebService::get_element_child_text( element, 'adminName2' )
47
+ postal_code.country_code = WebService::get_element_child_text( element, 'countryCode' )
48
+ postal_code.distance = WebService::get_element_child_float( element, 'distance' )
49
+ postal_code.latitude = WebService::get_element_child_float( element, 'lat' )
50
+ postal_code.longitude = WebService::get_element_child_float( element, 'lng' )
51
+ postal_code.place_name = WebService::get_element_child_text( element, 'name' )
52
+ postal_code.postal_code = WebService::get_element_child_text( element, 'postalcode' )
53
+
54
+ return postal_code
55
+
56
+ end
57
+
58
+ def WebService.element_to_wikipedia_article ( element )
59
+ article = WikipediaArticle.new
60
+
61
+ article.language = WebService::get_element_child_text( element, 'lang' )
62
+ article.title = WebService::get_element_child_text( element, 'title' )
63
+ article.summary = WebService::get_element_child_text( element, 'summary' )
64
+ article.wikipedia_url = WebService::get_element_child_text( element, 'wikipediaUrl' )
65
+ article.feature = WebService::get_element_child_text( element, 'feature' )
66
+ article.population = WebService::get_element_child_text( element, 'population' )
67
+ article.elevation = WebService::get_element_child_text( element, 'elevation' )
68
+ article.latitude = WebService::get_element_child_float( element, 'lat' )
69
+ article.longitude = WebService::get_element_child_float( element, 'lng' )
70
+ article.thumbnail_img = WebService::get_element_child_text( element, 'thumbnailImg' )
71
+ article.distance = WebService::get_element_child_float( element, 'distance' )
72
+
73
+ return article
74
+
75
+ end
76
+
77
+ def WebService.element_to_toponym ( element )
78
+ toponym = Toponym.new
79
+
80
+ toponym.name = WebService::get_element_child_text( element, 'name' )
81
+ toponym.alternate_names = WebService::get_element_child_text( element, 'alternateNames' )
82
+ toponym.latitude = WebService::get_element_child_float( element, 'lat' )
83
+ toponym.longitude = WebService::get_element_child_float( element, 'lng' )
84
+ toponym.geoname_id = WebService::get_element_child_text( element, 'geonameId' )
85
+ toponym.country_code = WebService::get_element_child_text( element, 'countryCode' )
86
+ toponym.country_name = WebService::get_element_child_text( element, 'countryName' )
87
+ toponym.feature_class = WebService::get_element_child_text( element, 'fcl' )
88
+ toponym.feature_code = WebService::get_element_child_text( element, 'fcode' )
89
+ toponym.feature_class_name = WebService::get_element_child_text( element, 'fclName' )
90
+ toponym.feature_code_name = WebService::get_element_child_text( element, 'fCodeName' )
91
+ toponym.population = WebService::get_element_child_int( element, 'population' )
92
+ toponym.elevation = WebService::get_element_child_text( element, 'elevation' )
93
+ toponym.distance = WebService::get_element_child_float( element, 'distance' )
94
+
95
+ return toponym
96
+
97
+ end
98
+
99
+ def WebService.element_to_intersection ( element )
100
+ intersection = Intersection.new
101
+
102
+ intersection.street_1 = WebService::get_element_child_text( element, 'street1' )
103
+ intersection.street_2 = WebService::get_element_child_text( element, 'street2' )
104
+ intersection.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
105
+ intersection.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
106
+ intersection.admin_code_2 = WebService::get_element_child_text( element, 'adminCode2' )
107
+ intersection.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
108
+ intersection.admin_name_2 = WebService::get_element_child_text( element, 'adminName2' )
109
+ intersection.country_code = WebService::get_element_child_text( element, 'countryCode' )
110
+ intersection.distance = WebService::get_element_child_float( element, 'distance' )
111
+ intersection.longitude = WebService::get_element_child_float( element, 'lat' )
112
+ intersection.latitude = WebService::get_element_child_float( element, 'lng' )
113
+ intersection.place_name = WebService::get_element_child_text( element, 'name' )
114
+ intersection.postal_code = WebService::get_element_child_text( element, 'postalcode' )
115
+
116
+ return intersection
117
+
118
+ end
119
+
120
+ def WebService.postal_code_search( postal_code, place_name, country_code )
121
+ postal_code_sc = PostalCodeSearchCriteria.new
122
+ postal_code_sc.postal_code = postal_code
123
+ postal_code_sc.place_name = place_name
124
+ postal_code_sc.coutry_code = country_code
125
+
126
+ WebService.postal_code_search postal_code_sc
127
+ end
128
+
129
+ def WebService.postal_code_search( search_criteria )
130
+ # postal codes to reutrn
131
+ postal_codes = Array.new
132
+
133
+ url = Geonames.build_url("/postalCodeSearch?a=a")
134
+ # url = Geonames::GEONAMES_SERVER + "/postalCodeSearch?a=a"
135
+ url = url + search_criteria.to_query_params_string
136
+
137
+ uri = URI.parse(url)
138
+
139
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
140
+
141
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
142
+ http.request( req )
143
+ }
144
+
145
+ doc = REXML::Document.new res.body
146
+
147
+ doc.elements.each("geonames/code") do |element|
148
+ postal_codes << WebService::element_to_postal_code( element )
149
+ end
150
+
151
+ postal_codes
152
+
153
+ end
154
+
155
+ def WebService.find_nearby_postal_codes( search_criteria )
156
+ # postal codes to reutrn
157
+ postal_codes = Array.new
158
+
159
+ url = Geonames.build_url("/findNearbyPostalCodes?a=a")
160
+ # url = Geonames::GEONAMES_SERVER + "/findNearbyPostalCodes?a=a"
161
+ url = url + search_criteria.to_query_params_string
162
+
163
+ uri = URI.parse(url)
164
+
165
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
166
+
167
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
168
+ http.request( req )
169
+ }
170
+
171
+ doc = REXML::Document.new res.body
172
+
173
+ doc.elements.each("geonames/code") do |element|
174
+ postal_codes << WebService::element_to_postal_code( element )
175
+ end
176
+
177
+ postal_codes
178
+
179
+ end
180
+
181
+ def WebService.find_nearby_place_name( lat, long )
182
+ places = Array.new
183
+
184
+ url = Geonames.build_url("/findNearbyPlaceName?a=a")
185
+ # url = Geonames::GEONAMES_SERVER + "/findNearbyPlaceName?a=a"
186
+
187
+ url = url + "&lat=" + lat.to_s
188
+ url = url + "&lng=" + long.to_s
189
+
190
+ uri = URI.parse(url)
191
+
192
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
193
+
194
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
195
+ http.request( req )
196
+ }
197
+
198
+ doc = REXML::Document.new res.body
199
+
200
+ doc.elements.each("geonames/geoname") do |element|
201
+
202
+ places << WebService::element_to_toponym( element )
203
+
204
+ end
205
+
206
+ return places
207
+
208
+ end
209
+
210
+ def WebService.find_nearest_intersection( lat, long )
211
+
212
+ url = Geonames.build_url("/findNearestIntersection?a=a")
213
+ # url = Geonames::GEONAMES_SERVER + "/findNearestIntersection?a=a"
214
+
215
+ url = url + "&lat=" + lat.to_s
216
+ url = url + "&lng=" + long.to_s
217
+
218
+ uri = URI.parse(url)
219
+
220
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
221
+
222
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
223
+ http.request( req )
224
+ }
225
+
226
+ doc = REXML::Document.new res.body
227
+
228
+ intersection = []
229
+ doc.elements.each("geonames/intersection") do |element|
230
+
231
+ intersection = WebService::element_to_intersection( element )
232
+
233
+ end
234
+
235
+ return intersection
236
+
237
+ end
238
+
239
+ def WebService.timezone( lat, long )
240
+ timezone = Timezone.new
241
+
242
+ url = Geonames.build_url("/timezone?a=a")
243
+ # url = Geonames::GEONAMES_SERVER + "/timezone?a=a"
244
+
245
+ url = url + "&lat=" + lat.to_s
246
+ url = url + "&lng=" + long.to_s
247
+
248
+ uri = URI.parse(url)
249
+
250
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
251
+
252
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
253
+ http.request( req )
254
+ }
255
+
256
+ doc = REXML::Document.new res.body
257
+
258
+ doc.elements.each("geonames/timezone") do |element|
259
+ timezone.timezone_id = WebService::get_element_child_text( element, 'timezoneId' )
260
+ timezone.gmt_offset = WebService::get_element_child_float( element, 'gmtOffset' )
261
+ timezone.dst_offset = WebService::get_element_child_float( element, 'dstOffset' )
262
+ end
263
+
264
+ return timezone
265
+
266
+ end
267
+
268
+ def WebService.findNearbyWikipedia( hashes )
269
+ # here for backwards compatibility
270
+ WebService.find_nearby_wikipedia( hashes )
271
+ end
272
+
273
+ def WebService.find_nearby_wikipedia( hashes )
274
+ articles = Array.new
275
+
276
+ lat = hashes[:lat]
277
+ long = hashes[:long]
278
+ lang = hashes[:lang]
279
+ radius = hashes[:radius]
280
+ max_rows = hashes[:max_rows]
281
+ country = hashes[:country]
282
+ postalcode = hashes[:postalcode]
283
+ q = hashes[:q]
284
+
285
+ url = Geonames.build_url("/findNearbyWikipedia?a=a")
286
+ # url = Geonames::GEONAMES_SERVER + "/findNearbyWikipedia?a=a"
287
+
288
+ if !lat.nil? && !long.nil?
289
+ url = url + "&lat=" + lat.to_s
290
+ url = url + "&lng=" + long.to_s
291
+ url = url + "&radius=" + radius.to_s unless radius.nil?
292
+ url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
293
+
294
+ elsif !q.nil?
295
+ url = url + "&q=" + q
296
+ url = url + "&radius=" + radius.to_s unless radius.nil?
297
+ url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
298
+ end
299
+
300
+ uri = URI.parse(url)
301
+
302
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
303
+
304
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
305
+ http.request( req )
306
+ }
307
+
308
+ doc = REXML::Document.new res.body
309
+
310
+ doc.elements.each("geonames/entry") do |element|
311
+ articles << WebService::element_to_wikipedia_article( element )
312
+ end
313
+
314
+ return articles
315
+
316
+ end
317
+
318
+ def WebService.findBoundingBoxWikipedia( hashes )
319
+ # here for backwards compatibility
320
+ WebService.find_bounding_box_wikipedia( hashes )
321
+ end
322
+
323
+ def WebService.find_bounding_box_wikipedia( hashes )
324
+ articles = Array.new
325
+
326
+ north = hashes[:north]
327
+ east = hashes[:east]
328
+ south = hashes[:south]
329
+ west = hashes[:west]
330
+ lang = hashes[:lang]
331
+ radius = hashes[:radius]
332
+ max_rows = hashes[:max_rows]
333
+ country = hashes[:country]
334
+ postalcode = hashes[:postalcode]
335
+ q = hashes[:q]
336
+
337
+ url = Geonames.build_url("/wikipediaBoundingBox?a=a")
338
+ # url = Geonames::GEONAMES_SERVER + "/wikipediaBoundingBox?a=a"
339
+
340
+ url = url + "&north=" + north.to_s
341
+ url = url + "&east=" + east.to_s
342
+ url = url + "&south=" + south.to_s
343
+ url = url + "&west=" + west.to_s
344
+ url = url + "&radius=" + radius.to_s unless radius.nil?
345
+ url = url + "&max_rows=" + max_rows.to_s unless max_rows.nil?
346
+
347
+ uri = URI.parse(url)
348
+
349
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
350
+
351
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
352
+ http.request( req )
353
+ }
354
+
355
+ doc = REXML::Document.new res.body
356
+
357
+ doc.elements.each("geonames/entry") do |element|
358
+ articles << WebService::element_to_wikipedia_article( element )
359
+ end
360
+
361
+ return articles
362
+
363
+ end
364
+
365
+ def WebService.country_subdivision ( lat, long )
366
+ country_subdivision = CountrySubdivision.new
367
+
368
+ url = Geonames.build_url("/countrySubdivision?a=a")
369
+ # url = Geonames::GEONAMES_SERVER + "/countrySubdivision?a=a"
370
+
371
+ url = url + "&lat=" + lat.to_s
372
+ url = url + "&lng=" + long.to_s
373
+
374
+ uri = URI.parse(url)
375
+
376
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
377
+
378
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
379
+ http.request( req )
380
+ }
381
+
382
+ doc = REXML::Document.new res.body
383
+
384
+ doc.elements.each("geonames/countrySubdivision") do |element|
385
+ country_subdivision.country_code = WebService::get_element_child_text( element, 'countryCode' )
386
+ country_subdivision.country_name = WebService::get_element_child_text( element, 'countryName' )
387
+ country_subdivision.admin_code_1 = WebService::get_element_child_text( element, 'adminCode1' )
388
+ country_subdivision.admin_name_1 = WebService::get_element_child_text( element, 'adminName1' )
389
+ end
390
+
391
+ return country_subdivision
392
+
393
+ end
394
+
395
+ def WebService.country_code ( lat, long )
396
+
397
+ url = Geonames.build_url("/countrycode?a=a")
398
+ # url = Geonames::GEONAMES_SERVER + "/countrycode?a=a"
399
+
400
+ url = url + "&lat=" + lat.to_s
401
+ url = url + "&lng=" + long.to_s
402
+
403
+ uri = URI.parse(url)
404
+
405
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
406
+
407
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
408
+ http.request( req )
409
+ }
410
+
411
+ doc = REXML::Document.new res.body
412
+
413
+ return res.body.strip
414
+
415
+ end
416
+
417
+ def WebService.search( search_criteria )
418
+ #toponym search results to return
419
+ toponym_sr = ToponymSearchResult.new
420
+
421
+ url = Geonames.build_url("/search?a=a")
422
+ # url = Geonames::GEONAMES_SERVER + "/search?a=a"
423
+
424
+ if !search_criteria.q.nil?
425
+ url = url + "&q=" + CGI::escape( search_criteria.q )
426
+ end
427
+
428
+ if !search_criteria.name_equals.nil?
429
+ url = url + "&name_equals=" + CGI::escape( search_criteria.name_equals )
430
+ end
431
+
432
+ if !search_criteria.name_starts_with.nil?
433
+ url = url + "&name_startsWith=" + CGI::escape( search_criteria.name_starts_with )
434
+ end
435
+
436
+ if !search_criteria.name.nil?
437
+ url = url + "&name=" + CGI::escape( search_criteria.name )
438
+ end
439
+
440
+ if !search_criteria.tag.nil?
441
+ url = url + "&tag=" + CGI::escape( search_criteria.tag )
442
+ end
443
+
444
+ if !search_criteria.country_code.nil?
445
+ url = url + "&country=" + CGI::escape( search_criteria.country_code )
446
+ end
447
+
448
+ if !search_criteria.admin_code_1.nil?
449
+ url = url + "&adminCode1=" + CGI::escape( search_criteria.admin_code_1 )
450
+ end
451
+
452
+ if !search_criteria.language.nil?
453
+ url = url + "&lang=" + CGI::escape( search_criteria.language )
454
+ end
455
+
456
+ if !search_criteria.feature_class.nil?
457
+ url = url + "&featureClass=" + CGI::escape( search_criteria.feature_class )
458
+ end
459
+
460
+ if !search_criteria.feature_codes.nil?
461
+ for feature_code in search_criteria.feature_codes
462
+ url = url + "&fcode=" + CGI::escape( feature_code )
463
+ end
464
+ end
465
+
466
+ if !search_criteria.max_rows.nil?
467
+ url = url + "&maxRows=" + CGI::escape( search_criteria.max_rows )
468
+ end
469
+
470
+ if !search_criteria.start_row.nil?
471
+ url = url + "&startRow=" + CGI::escape( search_criteria.start_row )
472
+ end
473
+
474
+ if !search_criteria.style.nil?
475
+ url = url + "&style=" + CGI::escape( search_criteria.style )
476
+ end
477
+
478
+ uri = URI.parse(url)
479
+
480
+ req = Net::HTTP::Get.new(uri.path + '?' + uri.query)
481
+
482
+ res = Net::HTTP.start( uri.host, uri.port ) { |http|
483
+ http.request( req )
484
+ }
485
+
486
+ doc = REXML::Document.new res.body
487
+
488
+ toponym_sr.total_results_count = doc.elements["geonames/totalResultsCount"].text
489
+
490
+ doc.elements.each("geonames/geoname") do |element|
491
+
492
+ toponym_sr.toponyms << WebService::element_to_toponym( element )
493
+
494
+ end
495
+
496
+ return toponym_sr
497
+ end
498
+
499
+ end
500
+ end
501
+
502
+ #alias WebService.find_nearby_wikipedia findNearbyWikipedia
503
+ #alias find_bounding_box_wikipedia findBoundingBoxWikipedia
@@ -0,0 +1,42 @@
1
+ #=============================================================================
2
+ #
3
+ # Copyright 2007 Adam Wisniewski <adamw@tbcn.ca>
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6
+ # use this file except in compliance with the License. You may obtain a copy of
7
+ # the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations under
15
+ # the License.
16
+ #
17
+ #=============================================================================
18
+
19
+ module Geonames
20
+ class WikipediaArticle
21
+
22
+ attr :language
23
+ attr :title
24
+ attr :summary
25
+ attr :wikipedia_url
26
+ attr :feature
27
+ attr :population
28
+ attr :elevation
29
+ attr :latitude
30
+ attr :longitude
31
+ attr :thumbnail_img
32
+ attr :distance
33
+
34
+ attr_writer :language, :title, :summary
35
+ attr_writer :wikipedia_url, :feature, :population
36
+ attr_writer :elevation, :latitude, :longitude
37
+ attr_writer :thumbnail_img, :distance
38
+
39
+ end
40
+ end
41
+
42
+
File without changes
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project-private xmlns="http://www.netbeans.org/ns/project-private/1">
3
+ <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
4
+ </project-private>
@@ -0,0 +1,3 @@
1
+ main.file=main.rb
2
+ src.dir=lib
3
+ test.src.dir=test
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project xmlns="http://www.netbeans.org/ns/project/1">
3
+ <type>org.netbeans.modules.ruby.rubyproject</type>
4
+ <configuration>
5
+ <data xmlns="http://www.netbeans.org/ns/ruby-project/1">
6
+ <name>geonames</name>
7
+ <source-roots>
8
+ <root id="src.dir"/>
9
+ </source-roots>
10
+ <test-roots>
11
+ <root id="test.src.dir"/>
12
+ </test-roots>
13
+ </data>
14
+ </configuration>
15
+ </project>
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geonames_patched
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Calvin Cheung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-11 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: calvin@presdo.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - geonames_patched.gemspec
26
+ - geonames_patched.gemspec~
27
+ - lib/address.rb
28
+ - lib/country_subdivision.rb
29
+ - lib/geonames.rb
30
+ - lib/geonames_patched.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/private/private.properties
43
+ - nbproject/private/private.xml
44
+ - nbproject/project.properties
45
+ - nbproject/project.xml
46
+ - README
47
+ has_rdoc: true
48
+ homepage: http://github.com/calvin681/geonames_patched
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A version of Adam Wisniewksi's geonames gem that includes username/password login.
75
+ test_files: []
76
+