carlosparamio-geoplanet 0.1.1 → 0.1.3
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.rdoc +26 -6
- data/geoplanet.gemspec +3 -3
- data/lib/geoplanet/base.rb +2 -4
- data/lib/geoplanet/place.rb +9 -7
- data/lib/geoplanet/version.rb +1 -1
- data/lib/geoplanet.rb +1 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -35,11 +35,11 @@ but this version supports better usage of matrix and query parameters, uses JSON
|
|
35
35
|
a.placetype # "Town"
|
36
36
|
a.placetype_code # 7
|
37
37
|
a.admin1 # "Andalucia"
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
a.admin1_code # "ES-AN"
|
39
|
+
a.admin1_placetype # "Autonomous Community"
|
40
|
+
a.admin2 # "Cadiz"
|
41
|
+
a.admin2_code # ""
|
42
|
+
a.admin2_placetype # "Province"
|
43
43
|
a.latitude # 36.127602
|
44
44
|
# Latitude and Longitude are values at Centroid
|
45
45
|
a.bounding_box # [[36.109779, -5.47725], [36.164268, -5.43527]]
|
@@ -56,6 +56,26 @@ but this version supports better usage of matrix and query parameters, uses JSON
|
|
56
56
|
|
57
57
|
# Postal Codes at Algeciras
|
58
58
|
a.children(:select => "long", :type => 11)
|
59
|
+
|
60
|
+
# You can use multiple types on the same query.
|
61
|
+
# e.g. Country and Province for Algeciras
|
62
|
+
a.belongtos(:type => [12, 9])
|
63
|
+
|
64
|
+
# You can specify the language you want for the results.
|
65
|
+
a.belongtos(:type => 12, :lang => 'es_ES').first.name # España
|
66
|
+
|
67
|
+
a = GeoPlanet::Place.new(752067, :lang => :es)
|
68
|
+
a.country # España
|
69
|
+
|
70
|
+
=== Debug Mode
|
71
|
+
|
72
|
+
If you want to look at the requests that are being executed against the Yahoo GeoPlanet API, you can enable the debug mode. It uses the standard output.
|
73
|
+
|
74
|
+
GeoPlanet.debug = true
|
75
|
+
GeoPlanet::Place.new(752067, :lang => :es)
|
76
|
+
# outputs:
|
77
|
+
# Yahoo GeoPlanet: GET http://where.yahooapis.com/v1/place/752067?appid=[your_appid]&format=json&lang=es
|
78
|
+
|
59
79
|
|
60
80
|
== REQUIREMENTS:
|
61
81
|
|
@@ -69,7 +89,7 @@ Additionally, geoplanet has the following gem dependencies:
|
|
69
89
|
|
70
90
|
== INSTALL:
|
71
91
|
|
72
|
-
* gem install
|
92
|
+
* gem install carlosparamio-geoplanet --source http://gems.github.com
|
73
93
|
|
74
94
|
== LICENSE:
|
75
95
|
|
data/geoplanet.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "geoplanet"
|
3
|
-
s.version = "0.1.
|
4
|
-
s.date = "2009-02-
|
3
|
+
s.version = "0.1.3"
|
4
|
+
s.date = "2009-02-26"
|
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/"
|
@@ -22,6 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency("rest-client", [">= 0.9"])
|
23
23
|
s.add_dependency("json", [">= 1.1.3"])
|
24
24
|
|
25
|
-
s.has_rdoc =
|
25
|
+
s.has_rdoc = false
|
26
26
|
s.rdoc_options = ["--main", "README.rdoc"]
|
27
27
|
end
|
data/lib/geoplanet/base.rb
CHANGED
@@ -10,7 +10,7 @@ module GeoPlanet
|
|
10
10
|
|
11
11
|
query_params[:appid] ||= GeoPlanet.appid # use default appid if not provided
|
12
12
|
|
13
|
-
raise ArgumentError if query_params[:appid].nil? || resource_path == 'places' && filters[:q].nil? # required
|
13
|
+
raise ArgumentError, "appid or q filter missing" if query_params[:appid].nil? || resource_path == 'places' && filters[:q].nil? # required
|
14
14
|
|
15
15
|
q = ".q('#{filters[:q]}')" if filters[:q]
|
16
16
|
type = ".type('#{filters[:type].is_a?(Array) ? filters[:type].to_a.join(',') : filters[:type]}')" if filters[:type]
|
@@ -28,11 +28,9 @@ module GeoPlanet
|
|
28
28
|
def get(url)
|
29
29
|
RestClient.get(url)
|
30
30
|
rescue RestClient::RequestFailed
|
31
|
-
raise BadRequest, "appid
|
31
|
+
raise BadRequest, "appid, q filter or format invalid"
|
32
32
|
rescue RestClient::ResourceNotFound
|
33
33
|
raise NotFound, "woeid or URI invalid"
|
34
|
-
rescue RestClient::RequestFailed
|
35
|
-
raise NotAcceptable, "format invalid"
|
36
34
|
end
|
37
35
|
|
38
36
|
protected
|
data/lib/geoplanet/place.rb
CHANGED
@@ -14,18 +14,18 @@ module GeoPlanet
|
|
14
14
|
alias_method :lat, :latitude
|
15
15
|
alias_method :lon, :longitude
|
16
16
|
|
17
|
-
def initialize(woe_or_attrs)
|
17
|
+
def initialize(woe_or_attrs, options = {})
|
18
18
|
case woe_or_attrs
|
19
|
-
when Integer then initialize_with_woe(woe_or_attrs)
|
19
|
+
when Integer then initialize_with_woe(woe_or_attrs, options)
|
20
20
|
when Hash then initialize_with_attrs(woe_or_attrs)
|
21
21
|
else
|
22
22
|
raise ArgumentError
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def initialize_with_woe(woe)
|
27
|
-
url = self.class.build_url("place/#{woe}", :format => "json")
|
28
|
-
puts "Yahoo GeoPlanet: GET #{url}"
|
26
|
+
def initialize_with_woe(woe, options = {})
|
27
|
+
url = self.class.build_url("place/#{woe}", options.merge(:format => "json"))
|
28
|
+
puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
|
29
29
|
initialize_with_attrs JSON.parse(Place.get(url))['place']
|
30
30
|
end
|
31
31
|
|
@@ -75,7 +75,7 @@ module GeoPlanet
|
|
75
75
|
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
76
76
|
def #{association}(options = {})
|
77
77
|
url = Place.build_url("place/\#{self.woeid}/#{association}", options.merge(:format => "json"))
|
78
|
-
puts "Yahoo GeoPlanet: GET \#{url}"
|
78
|
+
puts "Yahoo GeoPlanet: GET \#{url}" if GeoPlanet.debug
|
79
79
|
Place.get_then_parse(url)
|
80
80
|
end
|
81
81
|
RUBY
|
@@ -93,7 +93,7 @@ module GeoPlanet
|
|
93
93
|
def search(text, options = {})
|
94
94
|
text = URI.encode(text)
|
95
95
|
url = build_url('places', options.merge(:q => text, :format => 'json'))
|
96
|
-
puts "Yahoo GeoPlanet: GET #{url}"
|
96
|
+
puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
|
97
97
|
get_then_parse(url)
|
98
98
|
end
|
99
99
|
|
@@ -102,6 +102,8 @@ module GeoPlanet
|
|
102
102
|
return results['places']['place'].map{|attrs| Place.new attrs} if results['places']
|
103
103
|
return Place.new(results['place']) if results['place']
|
104
104
|
nil
|
105
|
+
rescue
|
106
|
+
nil
|
105
107
|
end
|
106
108
|
end
|
107
109
|
end
|
data/lib/geoplanet/version.rb
CHANGED
data/lib/geoplanet.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carlosparamio-geoplanet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Paramio
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-26 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -47,7 +47,7 @@ files:
|
|
47
47
|
- lib/geoplanet/base.rb
|
48
48
|
- lib/geoplanet/place.rb
|
49
49
|
- lib/geoplanet/version.rb
|
50
|
-
has_rdoc:
|
50
|
+
has_rdoc: false
|
51
51
|
homepage: http://github.com/carlosparamio/geoplanet/
|
52
52
|
post_install_message:
|
53
53
|
rdoc_options:
|