geoplanet 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTORS +1 -0
- data/README.rdoc +30 -18
- data/geoplanet.gemspec +7 -6
- data/lib/geoplanet/base.rb +21 -17
- data/lib/geoplanet/place.rb +14 -14
- metadata +46 -68
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 48f9a1e864994edc2566bf32bb9fa7c847437fa6
|
4
|
+
data.tar.gz: 40ad06343c7b5a48b2dc16a683592e3c58ba975e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b9cb13658ac365bc6229e075f78454dccf658033be8630cfd04bf1525f3c96ef6144b599bf5341393da8aae02c48b67520f84a4ce6f5859fcbdacd9d6c5d9a1
|
7
|
+
data.tar.gz: 114fcc912096be99bf91f8681d99c559bb8d3e57e468552bdff1d585e2a6229345d66e44ec28f1b9b8093818b3c431dfa8c5c8e3a7aa8aaa395780fc3f7fced3
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
David Ramalho (https://github.com/dramalho)
|
data/README.rdoc
CHANGED
@@ -15,28 +15,31 @@ but this version supports better usage of matrix and query parameters, uses JSON
|
|
15
15
|
|
16
16
|
require 'geoplanet'
|
17
17
|
GeoPlanet.appid = [Your App ID Here]
|
18
|
-
|
18
|
+
|
19
19
|
# Search for places that matches "Springfield" (the API returns 1 by default)
|
20
20
|
GeoPlanet::Place.search("Springfield")
|
21
|
-
|
21
|
+
|
22
22
|
# Search for *all* places that matches "Springfield"
|
23
23
|
GeoPlanet::Place.search("Springfield", :count => 0)
|
24
|
-
|
24
|
+
|
25
|
+
# Search for "Toronto" with focus on "Canada"
|
26
|
+
GeoPlanet::Place.search("Toronto", :focus => "ca")
|
27
|
+
|
25
28
|
# You can pass in any Matrix or Query parameters this way too
|
26
29
|
# For more details see the following URLs:
|
27
30
|
# http://developer.yahoo.com/geo/guide/resources_and_collections.html#matrix_parameters
|
28
31
|
# http://developer.yahoo.com/geo/guide/resources_and_collections.html#query_parameters
|
29
|
-
|
32
|
+
|
30
33
|
=== Initializing by Where On Earth ID && Associations
|
31
|
-
|
34
|
+
|
32
35
|
require 'geoplanet'
|
33
36
|
GeoPlanet.appid = [Your App ID Here]
|
34
|
-
|
37
|
+
|
35
38
|
a = GeoPlanet::Place.new(752067) # WoE ID for Algeciras
|
36
|
-
|
39
|
+
|
37
40
|
# Everything you get back from the API you have direct access to
|
38
41
|
# through the Place object. For example:
|
39
|
-
|
42
|
+
|
40
43
|
a.version # "long"
|
41
44
|
a.placetype # "Town"
|
42
45
|
a.placetype_code # 7
|
@@ -55,33 +58,36 @@ but this version supports better usage of matrix and query parameters, uses JSON
|
|
55
58
|
a.area_rank # 4
|
56
59
|
# Code representing the size of the place
|
57
60
|
# See codes at http://developer.yahoo.com/geo/geoplanet/guide/api_docs.html
|
58
|
-
|
61
|
+
|
59
62
|
# We unlock the true power of GeoPlanet with association collections
|
60
63
|
# Check out this truly amazing stuff:
|
61
|
-
|
64
|
+
|
62
65
|
# A list of other towns in the area
|
63
66
|
a.siblings
|
64
|
-
|
67
|
+
|
65
68
|
# A complete hierarchy, from country down to municipality
|
66
69
|
a.ancestors
|
67
70
|
|
71
|
+
# All descendants for a location
|
72
|
+
a.descendants(count: 0)
|
73
|
+
|
68
74
|
# Postal Codes at Algeciras
|
69
75
|
a.children(:select => "long", :type => 11)
|
70
|
-
|
76
|
+
|
71
77
|
# You can use multiple types on the same query.
|
72
78
|
# e.g. Country and Province for Algeciras
|
73
79
|
a.belongtos(:type => [12, 9])
|
74
|
-
|
80
|
+
|
75
81
|
# You can specify the language you want for the results.
|
76
82
|
a.belongtos(:type => 12, :lang => 'es_ES').first.name # España
|
77
|
-
|
83
|
+
|
78
84
|
a = GeoPlanet::Place.new(752067, :lang => :es)
|
79
85
|
a.country # España
|
80
|
-
|
86
|
+
|
81
87
|
# It is also possible to query for any association directly using a WOE ID, without
|
82
88
|
# create a Place object. Append a '_of' suffix to the association name to build the
|
83
89
|
# method name to execute. The first argument is the WOE ID.
|
84
|
-
|
90
|
+
|
85
91
|
GeoPlanet::Place.belongtos_of(752067, :type => [12, 9])
|
86
92
|
|
87
93
|
=== Debug Mode
|
@@ -96,7 +102,7 @@ If you want to look at the requests that are being executed against the Yahoo Ge
|
|
96
102
|
|
97
103
|
== REQUIREMENTS:
|
98
104
|
|
99
|
-
To use this library, you must have a valid Yahoo! App ID.
|
105
|
+
To use this library, you must have a valid Yahoo! App ID.
|
100
106
|
You can get one at http://developer.yahoo.com/wsregapp/
|
101
107
|
|
102
108
|
Additionally, geoplanet has the following gem dependencies:
|
@@ -128,4 +134,10 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
128
134
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
129
135
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
130
136
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
131
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
137
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
138
|
+
|
139
|
+
== Credits
|
140
|
+
|
141
|
+
Carlos Paramio
|
142
|
+
|
143
|
+
http://h1labs.com
|
data/geoplanet.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "geoplanet"
|
3
|
-
s.version = "0.2.
|
4
|
-
s.date = "
|
3
|
+
s.version = "0.2.7"
|
4
|
+
s.date = "2014-05-09"
|
5
5
|
s.summary = "A Ruby wrapper for the Yahoo! GeoPlanet API."
|
6
6
|
s.email = "carlosparamio@gmail.com"
|
7
7
|
s.homepage = "http://github.com/carlosparamio/geoplanet/"
|
8
8
|
s.description = "A Ruby wrapper for the Yahoo! GeoPlanet API. It uses JSON format by default to minimize bandwidth usage. See http://developer.yahoo.com/geo/ for more information about the API."
|
9
9
|
s.authors = ["Carlos Paramio"]
|
10
|
-
|
10
|
+
|
11
11
|
s.files = [
|
12
12
|
"README.rdoc",
|
13
|
-
|
13
|
+
"CONTRIBUTORS",
|
14
|
+
"geoplanet.gemspec",
|
14
15
|
"lib/geoplanet.rb",
|
15
16
|
"lib/geoplanet/base.rb",
|
16
17
|
"lib/geoplanet/place.rb",
|
17
18
|
"lib/geoplanet/version.rb"
|
18
19
|
]
|
19
|
-
|
20
|
+
|
20
21
|
s.add_dependency("rest-client", [">= 0.9"])
|
21
22
|
s.add_dependency("json", [">= 1.1.3"])
|
22
|
-
|
23
|
+
|
23
24
|
s.has_rdoc = false
|
24
25
|
s.rdoc_options = ["--main", "README.rdoc"]
|
25
26
|
end
|
data/lib/geoplanet/base.rb
CHANGED
@@ -3,7 +3,7 @@ module GeoPlanet
|
|
3
3
|
class << self
|
4
4
|
def build_url(resource_path, options = {})
|
5
5
|
check_options_for(resource_path, options)
|
6
|
-
|
6
|
+
|
7
7
|
filters = extract_filters(options)
|
8
8
|
matrix_params = extract_matrix_params(options)
|
9
9
|
query_params = extract_query_params(options)
|
@@ -12,19 +12,23 @@ module GeoPlanet
|
|
12
12
|
|
13
13
|
raise ArgumentError, "appid or q filter missing" if query_params[:appid].nil? || resource_path == 'places' && filters[:q].nil? # required
|
14
14
|
|
15
|
-
|
15
|
+
if filters[:q]
|
16
|
+
query = [filters[:q], filters[:focus]].compact.map { |t| "'#{t}'" }.join(',')
|
17
|
+
q = ".q(#{query})"
|
18
|
+
end
|
19
|
+
|
16
20
|
type = ".type('#{filters[:type]}')" if filters[:type]
|
17
|
-
|
21
|
+
|
18
22
|
query_string = q && type ? "$and(#{q},#{type})" : "#{q}#{type}"
|
19
|
-
|
23
|
+
|
20
24
|
matrix_params = matrix_params.any? ? ";#{matrix_params.map{|k,v| "#{k}=#{v}"}.join(';')}" : nil
|
21
25
|
query_params = query_params.any? ? "?#{query_params.map{|k,v| "#{k}=#{v}"}.join('&')}" : nil
|
22
|
-
|
26
|
+
|
23
27
|
query_string += "#{matrix_params}#{query_params}"
|
24
|
-
|
28
|
+
|
25
29
|
"#{GeoPlanet::API_URL}#{resource_path}#{query_string}"
|
26
30
|
end
|
27
|
-
|
31
|
+
|
28
32
|
def get(url)
|
29
33
|
RestClient.get(url)
|
30
34
|
rescue RestClient::RequestFailed
|
@@ -37,40 +41,40 @@ module GeoPlanet
|
|
37
41
|
def supported_options_for(resource_path)
|
38
42
|
case resource_path
|
39
43
|
when 'places'
|
40
|
-
%w(q type start count lang format callback select appid)
|
44
|
+
%w(q type start count lang format callback select appid focus)
|
41
45
|
when /^place\/\d+\/parent$/, /^place\/\d+\/ancestors$/, /^place\/\d+$/, 'placetype'
|
42
46
|
%w(lang format callback select appid)
|
43
|
-
when /^place\/\d+\/belongtos$/, /^place\/\d+\/children$/, 'placetypes'
|
44
|
-
%w(type start count lang format callback select appid)
|
47
|
+
when /^place\/\d+\/belongtos$/, /^place\/\d+\/children$/, /^place\/\d+\/descendants$/, 'placetypes'
|
48
|
+
%w(type start count lang format callback select appid degree view)
|
45
49
|
when /^place\/\d+\/neighbors$/, /^place\/\d+\/siblings$/
|
46
50
|
%w(start count lang format callback select appid)
|
47
51
|
else
|
48
52
|
raise NotFound, "URI invalid"
|
49
53
|
end
|
50
54
|
end
|
51
|
-
|
55
|
+
|
52
56
|
def check_options_for(resource_path, options)
|
53
57
|
supported = supported_options_for(resource_path)
|
54
58
|
unless options.keys.all?{|o| supported.include?(o.to_s)}
|
55
59
|
raise ArgumentError, "invalid option(s) for #{resource_path}. Supported are: #{supported.join(', ')}. You used: #{options.keys.join(', ')}"
|
56
60
|
end
|
57
61
|
end
|
58
|
-
|
62
|
+
|
59
63
|
def extract_filters(options)
|
60
|
-
filters = %w(q type)
|
64
|
+
filters = %w(q focus type degree)
|
61
65
|
options[:type] = options[:type].join(",") if options[:type].is_a?(Array)
|
62
66
|
Hash[*(options.select{|k,v| filters.include?(k.to_s)}).flatten]
|
63
67
|
end
|
64
|
-
|
68
|
+
|
65
69
|
def extract_matrix_params(options)
|
66
70
|
matrix_params = %w(start count)
|
67
71
|
Hash[*(options.select{|k,v| matrix_params.include?(k.to_s)}).flatten]
|
68
72
|
end
|
69
|
-
|
73
|
+
|
70
74
|
def extract_query_params(options)
|
71
|
-
query_params = %w(lang format callback select appid)
|
75
|
+
query_params = %w(lang format callback select appid view)
|
72
76
|
Hash[*(options.select{|k,v| query_params.include?(k.to_s)}).flatten]
|
73
77
|
end
|
74
78
|
end
|
75
79
|
end
|
76
|
-
end
|
80
|
+
end
|
data/lib/geoplanet/place.rb
CHANGED
@@ -12,7 +12,7 @@ module GeoPlanet
|
|
12
12
|
attr_reader :locality1, :locality1_placetype
|
13
13
|
attr_reader :locality2, :locality2_placetype
|
14
14
|
attr_reader :pop_rank, :area_rank
|
15
|
-
alias_method :lat, :latitude
|
15
|
+
alias_method :lat, :latitude
|
16
16
|
alias_method :lon, :longitude
|
17
17
|
|
18
18
|
# Class methods
|
@@ -22,7 +22,7 @@ module GeoPlanet
|
|
22
22
|
puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
|
23
23
|
get_then_parse(url)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def self.get_then_parse(url)
|
27
27
|
results = JSON.parse get(url).to_s
|
28
28
|
return results['places']['place'].map{|attrs| Place.new attrs} if results['places']
|
@@ -32,7 +32,7 @@ module GeoPlanet
|
|
32
32
|
nil
|
33
33
|
end
|
34
34
|
|
35
|
-
%w(parent ancestors belongtos neighbors siblings children).each do |association|
|
35
|
+
%w(parent ancestors belongtos neighbors siblings children descendants).each do |association|
|
36
36
|
self.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
|
37
37
|
def self.#{association}_of(woeid, options = {})
|
38
38
|
url = build_url("place/\#{woeid}/#{association}", options.merge(:format => "json"))
|
@@ -41,7 +41,7 @@ module GeoPlanet
|
|
41
41
|
end
|
42
42
|
RUBY
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Instance methods
|
46
46
|
def initialize(woe_or_attrs, options = {})
|
47
47
|
case woe_or_attrs
|
@@ -51,14 +51,14 @@ module GeoPlanet
|
|
51
51
|
raise ArgumentError
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def initialize_with_woe(woe, options = {})
|
56
56
|
url = self.class.build_url("place/#{woe}", options.merge(:format => "json"))
|
57
57
|
puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
|
58
58
|
initialize_with_attrs JSON.parse(Place.get(url))['place']
|
59
59
|
end
|
60
|
-
|
61
|
-
|
60
|
+
|
61
|
+
|
62
62
|
def initialize_with_attrs(attrs)
|
63
63
|
@version = attrs['centroid'] ? 'long' : 'short'
|
64
64
|
|
@@ -96,31 +96,31 @@ module GeoPlanet
|
|
96
96
|
@locality2 = attrs['locality2']
|
97
97
|
@locality2_placetype = attrs['locality2 attrs']['type'] rescue nil
|
98
98
|
@pop_rank = attrs['popRank']
|
99
|
-
@area_rank = attrs['areaRank']
|
99
|
+
@area_rank = attrs['areaRank']
|
100
100
|
end
|
101
101
|
self
|
102
102
|
end
|
103
103
|
|
104
104
|
# Association Collections
|
105
|
-
%w(parent ancestors belongtos neighbors siblings children).each do |association|
|
105
|
+
%w(parent ancestors belongtos neighbors siblings children descendants).each do |association|
|
106
106
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
107
107
|
def #{association}(options = {})
|
108
108
|
Place.send("#{association}_of", self.woeid, options)
|
109
109
|
end
|
110
110
|
RUBY
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
def to_s
|
114
114
|
self.name
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
def to_i
|
118
118
|
self.woeid.to_i
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def inspect
|
122
122
|
"#<GeoPlanet::Place #{instance_variables.map{|ivar| "#{ivar}: #{instance_variable_get(ivar).inspect}"}.join(', ')}>"
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
end
|
126
|
-
end
|
126
|
+
end
|
metadata
CHANGED
@@ -1,103 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoplanet
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease: false
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 6
|
10
|
-
version: 0.2.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.7
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Carlos Paramio
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
22
14
|
name: rest-client
|
23
|
-
|
24
|
-
|
25
|
-
none: false
|
26
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
27
17
|
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 9
|
33
|
-
version: "0.9"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
34
20
|
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: json
|
38
21
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
42
31
|
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
hash: 21
|
45
|
-
segments:
|
46
|
-
- 1
|
47
|
-
- 1
|
48
|
-
- 3
|
32
|
+
- !ruby/object:Gem::Version
|
49
33
|
version: 1.1.3
|
50
34
|
type: :runtime
|
51
|
-
|
52
|
-
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.3
|
41
|
+
description: A Ruby wrapper for the Yahoo! GeoPlanet API. It uses JSON format by default
|
42
|
+
to minimize bandwidth usage. See http://developer.yahoo.com/geo/ for more information
|
43
|
+
about the API.
|
53
44
|
email: carlosparamio@gmail.com
|
54
45
|
executables: []
|
55
|
-
|
56
46
|
extensions: []
|
57
|
-
|
58
47
|
extra_rdoc_files: []
|
59
|
-
|
60
|
-
|
48
|
+
files:
|
49
|
+
- CONTRIBUTORS
|
61
50
|
- README.rdoc
|
62
51
|
- geoplanet.gemspec
|
63
52
|
- lib/geoplanet.rb
|
64
53
|
- lib/geoplanet/base.rb
|
65
54
|
- lib/geoplanet/place.rb
|
66
55
|
- lib/geoplanet/version.rb
|
67
|
-
has_rdoc: true
|
68
56
|
homepage: http://github.com/carlosparamio/geoplanet/
|
69
57
|
licenses: []
|
70
|
-
|
58
|
+
metadata: {}
|
71
59
|
post_install_message:
|
72
|
-
rdoc_options:
|
73
|
-
- --main
|
60
|
+
rdoc_options:
|
61
|
+
- "--main"
|
74
62
|
- README.rdoc
|
75
|
-
require_paths:
|
63
|
+
require_paths:
|
76
64
|
- lib
|
77
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
-
|
79
|
-
requirements:
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
80
67
|
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
version: "0"
|
86
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
-
none: false
|
88
|
-
requirements:
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
89
72
|
- - ">="
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
segments:
|
93
|
-
- 0
|
94
|
-
version: "0"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
95
75
|
requirements: []
|
96
|
-
|
97
76
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.2.2
|
99
78
|
signing_key:
|
100
|
-
specification_version:
|
79
|
+
specification_version: 4
|
101
80
|
summary: A Ruby wrapper for the Yahoo! GeoPlanet API.
|
102
81
|
test_files: []
|
103
|
-
|