geonames_api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -1
- data/geonames_api.gemspec +3 -0
- data/lib/geonames_api.rb +2 -0
- data/lib/geonames_api/country.rb +24 -1
- data/lib/geonames_api/version.rb +1 -1
- metadata +17 -1
data/README.md
CHANGED
@@ -73,7 +73,12 @@ The geonames api uses the ISO code of the country as its natural key.
|
|
73
73
|
|
74
74
|
=> ... array of GeoNamesAPI::Country instances
|
75
75
|
|
76
|
-
|
76
|
+
The [postal code exports](http://download.geonames.org/export/zip/) are also available for each country either in string of ruby CSV form.
|
77
|
+
|
78
|
+
# String
|
79
|
+
> GeoNamesAPI::Country.find("US").postal_code_export
|
80
|
+
# CSV::Table
|
81
|
+
> GeoNamesAPI::Country.find("US").postal_code_csv
|
77
82
|
|
78
83
|
### Weather
|
79
84
|
|
data/geonames_api.gemspec
CHANGED
@@ -11,7 +11,10 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{Simple ruby client for the GeoNames API to get free and easy geographic info.}
|
12
12
|
gem.summary = %q{This is a lightweight client for the GeoNames API. Huge thanks to them for such a great service! There are many GeoNames API clients. BUT, most are rewritten versions of a Java API whose interface is a little funny =| This is a simplified ruby implementation that does not implement the entire API. But, its lightweight and has a nice interface and will be easy to extend :)}
|
13
13
|
gem.homepage = "https://github.com/buytruckload/geonames_api"
|
14
|
+
|
14
15
|
gem.add_runtime_dependency "activesupport"
|
16
|
+
gem.add_runtime_dependency "zipruby"
|
17
|
+
|
15
18
|
gem.files = `git ls-files`.split($/)
|
16
19
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
20
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
data/lib/geonames_api.rb
CHANGED
data/lib/geonames_api/country.rb
CHANGED
@@ -2,7 +2,30 @@ module GeoNamesAPI
|
|
2
2
|
class Country < GeoNamesAPI::Object
|
3
3
|
|
4
4
|
METHOD = "countryInfoJSON"
|
5
|
-
ID = "country"
|
5
|
+
ID = "country"
|
6
6
|
|
7
|
+
EXPORT_BASE_URL = "http://download.geonames.org/export/zip/"
|
8
|
+
EXPORT_HEADERS = %W(country_code postal_code place_name admin_name1 admin_code1 admin_name2 admin_code2 admin_name3 admin_code3 latitude longitude accuracy)
|
9
|
+
|
10
|
+
def postal_code_export
|
11
|
+
zip_data = open(postal_code_export_url) { |f| f.binmode; f.read }
|
12
|
+
stream = lambda { return zip_data.slice!(0, 256) }
|
13
|
+
csv = EXPORT_HEADERS.join("\t") + "\n"
|
14
|
+
Zip::Archive.open_buffer(stream) do |archive|
|
15
|
+
archive.each do |f|
|
16
|
+
csv << f.read if f.name =~ /\A#{country_code}/
|
17
|
+
end
|
18
|
+
end
|
19
|
+
csv
|
20
|
+
end
|
21
|
+
|
22
|
+
def postal_code_csv
|
23
|
+
CSV.parse(postal_code_export, headers: true, col_sep: "\t", header_converters: :symbol)
|
24
|
+
end
|
25
|
+
|
26
|
+
def postal_code_export_url
|
27
|
+
EXPORT_BASE_URL + country_code + ".zip"
|
28
|
+
end
|
29
|
+
|
7
30
|
end
|
8
31
|
end
|
data/lib/geonames_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geonames_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: zipruby
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: Simple ruby client for the GeoNames API to get free and easy geographic
|
31
47
|
info.
|
32
48
|
email:
|