carlosparamio-geoplanet 0.1.4 → 0.2.0

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 CHANGED
@@ -66,6 +66,12 @@ but this version supports better usage of matrix and query parameters, uses JSON
66
66
 
67
67
  a = GeoPlanet::Place.new(752067, :lang => :es)
68
68
  a.country # España
69
+
70
+ # It is also possible to query for any association directly using a WOE ID, without
71
+ # create a Place object. Append a '_of' suffix to the association name to build the
72
+ # method name to execute. The first argument is the WOE ID.
73
+
74
+ GeoPlanet::Place.belongtos_of(752067, :type => [12, 9])
69
75
 
70
76
  === Debug Mode
71
77
 
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"
4
- s.date = "2009-02-26"
3
+ s.version = "0.2.0"
4
+ s.date = "2009-03-23"
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/"
@@ -14,6 +14,34 @@ module GeoPlanet
14
14
  alias_method :lat, :latitude
15
15
  alias_method :lon, :longitude
16
16
 
17
+ # Class methods
18
+ def self.search(text, options = {})
19
+ text = URI.encode(text)
20
+ url = build_url('places', options.merge(:q => text, :format => 'json'))
21
+ puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
22
+ get_then_parse(url)
23
+ end
24
+
25
+ def self.get_then_parse(url)
26
+ results = JSON.parse get(url)
27
+ return results['places']['place'].map{|attrs| Place.new attrs} if results['places']
28
+ return Place.new(results['place']) if results['place']
29
+ nil
30
+ rescue
31
+ nil
32
+ end
33
+
34
+ %w(parent ancestors belongtos neighbors siblings children).each do |association|
35
+ self.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
36
+ def self.#{association}_of(woeid, options = {})
37
+ url = build_url("place/\#{woeid}/#{association}", options.merge(:format => "json"))
38
+ puts "Yahoo GeoPlanet: GET \#{url}" if GeoPlanet.debug
39
+ get_then_parse(url)
40
+ end
41
+ RUBY
42
+ end
43
+
44
+ # Instance methods
17
45
  def initialize(woe_or_attrs, options = {})
18
46
  case woe_or_attrs
19
47
  when Integer then initialize_with_woe(woe_or_attrs, options)
@@ -74,9 +102,7 @@ module GeoPlanet
74
102
  %w(parent ancestors belongtos neighbors siblings children).each do |association|
75
103
  self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
76
104
  def #{association}(options = {})
77
- url = Place.build_url("place/\#{self.woeid}/#{association}", options.merge(:format => "json"))
78
- puts "Yahoo GeoPlanet: GET \#{url}" if GeoPlanet.debug
79
- Place.get_then_parse(url)
105
+ Place.send("#{association}_of", self.woeid, options)
80
106
  end
81
107
  RUBY
82
108
  end
@@ -89,22 +115,5 @@ module GeoPlanet
89
115
  self.woeid.to_i
90
116
  end
91
117
 
92
- class << self
93
- def search(text, options = {})
94
- text = URI.encode(text)
95
- url = build_url('places', options.merge(:q => text, :format => 'json'))
96
- puts "Yahoo GeoPlanet: GET #{url}" if GeoPlanet.debug
97
- get_then_parse(url)
98
- end
99
-
100
- def get_then_parse(url)
101
- results = JSON.parse get(url)
102
- return results['places']['place'].map{|attrs| Place.new attrs} if results['places']
103
- return Place.new(results['place']) if results['place']
104
- nil
105
- rescue
106
- nil
107
- end
108
- end
109
118
  end
110
119
  end
@@ -1,9 +1,8 @@
1
1
  module GeoPlanet
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 4
6
-
4
+ MINOR = 2
5
+ TINY = 0
7
6
  STRING = [MAJOR, MINOR, TINY].join('.')
8
7
  end
9
8
  end
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
4
+ version: 0.2.0
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-26 00:00:00 -08:00
12
+ date: 2009-03-23 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency