jsl-placemaker 0.0.1.1 → 0.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Justin S. Leitgeb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -6,7 +6,7 @@ Ruby interface for the Yahoo PlaceMaker API.
6
6
 
7
7
  Assuming that you've set up your ruby environment to pull gems from GitHub, install placemaker with the following command:
8
8
 
9
- sudo gem install placemaker
9
+ sudo gem install jsl-placemaker
10
10
 
11
11
  = Usage
12
12
 
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require 'rake'
5
+ require 'spec/rake/spectask'
6
+ require 'rake/rdoctask'
7
+
8
+ require 'lib/placemaker'
9
+
10
+ desc 'Test the plugin.'
11
+ Spec::Rake::SpecTask.new(:spec) do |t|
12
+ t.spec_opts = ["--format", "progress", "--colour"]
13
+ t.libs << 'lib'
14
+ t.verbose = true
15
+ end
16
+
17
+ desc "Run all the tests"
18
+ task :default => :spec
19
+
20
+ desc 'Generate documentation'
21
+ Rake::RDocTask.new(:rdoc) do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'Placemaker'
24
+ rdoc.options << '--line-numbers' << '--inline-source'
25
+ rdoc.rdoc_files.include('README.rdoc')
26
+ rdoc.rdoc_files.include('lib/placemaker/**/*.rb')
27
+ end
28
+
@@ -0,0 +1,8 @@
1
+ class Array
2
+
3
+ # From Rails' ActiveSupport library
4
+ def extract_options!
5
+ last.is_a?(::Hash) ? pop : {}
6
+ end
7
+
8
+ end
@@ -0,0 +1,17 @@
1
+ class Hash
2
+ # Returns a Hash containing only input keys.
3
+ # Method from merb-core.
4
+ def except(*rejected)
5
+ reject { |k,v| rejected.include?(k) }
6
+ end
7
+
8
+ def reverse_merge(other_hash)
9
+ other_hash.merge(self)
10
+ end
11
+
12
+ # Returns a new hash containing only the input keys.
13
+ # Method from merb-core.
14
+ def only(*allowed)
15
+ reject { |k,v| !allowed.include?(k) }
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Placemaker
2
+ class Document
3
+ def initialize(nodeset)
4
+ @nodeset = nodeset
5
+ end
6
+
7
+ def places
8
+ @nodeset.search('.//xmlns:placeDetails', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').map do |p|
9
+ Placemaker::Place.new(p)
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ module Placemaker
2
+ class Point < OpenStruct
3
+ end
4
+
5
+ class Place
6
+ def initialize(nodeset)
7
+ @nodeset = nodeset
8
+ end
9
+
10
+ def centroid
11
+ centroid = @nodeset.search('.//xmlns:centroid', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')
12
+ lat = centroid.search('.//xmlns:latitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
13
+ lng = centroid.search('.//xmlns:longitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
14
+ Placemaker::Point.new(:lat => lat, :lng => lng)
15
+ end
16
+
17
+ def place_type
18
+ nested_node('type')
19
+ end
20
+
21
+ def match_type
22
+ nested_node('matchType').to_i
23
+ end
24
+
25
+ def weight
26
+ nested_node('weight').to_i
27
+ end
28
+
29
+ def confidence
30
+ nested_node('confidence').to_i
31
+ end
32
+
33
+ def name
34
+ nested_node('name')
35
+ end
36
+
37
+ def woe_id
38
+ nested_node('woeId').to_i
39
+ end
40
+
41
+ private
42
+
43
+ def nested_node(name)
44
+ @nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
1
+ module Placemaker
2
+ class Reader
3
+ POST_FIELDS = %w[ appid document_content document_url document_type document_title
4
+ auto_disambiguate focus_woe_id input_language output_type ].map{|f| f.to_sym}
5
+
6
+ attr_reader :documents
7
+
8
+ def initialize(options = {})
9
+ @options = options
10
+ @options[:appid] ||= ENV['PLACEMAKER_APPID']
11
+ @documents = [ ]
12
+ verify_content_set
13
+ verify_document_type_set
14
+ end
15
+
16
+ POST_FIELDS.each do |f|
17
+ define_method(f) do # def appid
18
+ @options[f] # @options[:appid]
19
+ end # end
20
+ end
21
+
22
+ def fetch
23
+ fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
24
+ # Change ruby-form fields to url type, e.g., document_content => documentContent
25
+ cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
26
+ Curl::PostField.content(cgi_param, @options[f])
27
+ end
28
+
29
+ res = Curl::Easy.http_post('http://wherein.yahooapis.com/v1/document', *fields)
30
+ xml_parser = Placemaker::XmlParser.new(res.body_str)
31
+ @documents = xml_parser.documents
32
+ end
33
+
34
+ private
35
+
36
+ def verify_document_type_set
37
+ valid_types = %w[
38
+ text/plain
39
+ text/html text/xml text/rss
40
+ application/xml application/rss+xml
41
+ ]
42
+
43
+ raise ArgumentError, "Document type must be in #{valid_types.join(', ')}" unless valid_types.include?(@options[:document_type])
44
+ end
45
+
46
+ def verify_content_set
47
+ raise ArgumentError, "Either document_url or document_content must be set" if (@options[:document_content].nil? && @options[:document_url].nil?)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ module Placemaker
2
+ class XmlParser
3
+ def initialize(xml_body)
4
+ @body = xml_body
5
+ @xml = Nokogiri::XML(xml_body)
6
+ end
7
+
8
+ # Returns a set of documents corresponding to the RSS entries in input data.
9
+ # Returns a collection of Placemaker::Document objects.
10
+ def documents
11
+ @xml.xpath('//xmlns:document', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').map do |d|
12
+ Placemaker::Document.new(d)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
data/lib/placemaker.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'curb'
3
+ require 'nokogiri'
4
+ require 'cgi'
5
+
6
+ lib_dirs = [ 'core_ext', 'placemaker' ].map do |d|
7
+ File.join(File.dirname(__FILE__), d)
8
+ end
9
+
10
+ lib_dirs.each do |d|
11
+ Dir[File.join(d, "*.rb")].each {|file| require file }
12
+ end
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{placemaker}
5
+ s.version = "0.0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Justin Leitgeb"]
9
+ s.date = %q{2009-05-20}
10
+ s.description = %q{Ruby interface for the Yahoo Placemaker API}
11
+ s.email = %q{justin@phq.org}
12
+ s.extra_rdoc_files = [
13
+ "README.rdoc"
14
+ ]
15
+
16
+
17
+ s.files = ["lib/core_ext/array.rb", "lib/core_ext/hash.rb", "lib/placemaker/document.rb", "lib/placemaker/place.rb",
18
+ "lib/placemaker/reader.rb", "lib/placemaker/xml_parser.rb", "lib/placemaker.rb", "LICENSE",
19
+ "placemaker.gemspec", "Rakefile", "README.rdoc", "spec/fixtures/xml_rss_feed_result.xml",
20
+ "spec/placemaker/document_spec.rb", "spec/placemaker/place_spec.rb", "spec/placemaker/reader_spec.rb",
21
+ "spec/placemaker/xml_parser_spec.rb", "spec/spec_helper.rb"]
22
+
23
+ s.has_rdoc = true
24
+ s.homepage = %q{http://github.com/jsl/placemaker}
25
+ s.rdoc_options = ["--charset=UTF-8"]
26
+ s.require_paths = ["lib"]
27
+ s.rubygems_version = %q{1.3.1}
28
+ s.summary = %q{Ruby interface over the Yahoo Placemaker API}
29
+ s.test_files = ["spec/fixtures/xml_rss_feed_result.xml", "spec/placemaker/document_spec.rb", "spec/placemaker/place_spec.rb",
30
+ "spec/placemaker/reader_spec.rb", "spec/placemaker/xml_parser_spec.rb", "spec/spec_helper.rb"]
31
+
32
+ s.extra_rdoc_files = [ "README.rdoc" ]
33
+
34
+ s.rdoc_options += [
35
+ '--title', 'Placemaker',
36
+ '--main', 'README.rdoc',
37
+ '--line-numbers',
38
+ '--inline-source'
39
+ ]
40
+
41
+ %w[ curb nokogiri ].each do |dep|
42
+ s.add_dependency(dep)
43
+ end
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 2
48
+ end
49
+ end
@@ -0,0 +1,636 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <contentlocation xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" xmlns="http://wherein.yahooapis.com/v1/schema" xml:lang="en">
3
+ <processingTime>0.028125</processingTime>
4
+ <version> build 090508</version>
5
+ <documentLength>29700</documentLength>
6
+ <document>
7
+ </document>
8
+ <document>
9
+ </document>
10
+ <document>
11
+ <administrativeScope>
12
+ <woeId>2344681</woeId>
13
+ <type>State</type>
14
+ <name><![CDATA[Ciudad de Buenos Aires, AR]]></name>
15
+ <centroid>
16
+ <latitude>-34.5465</latitude>
17
+ <longitude>-58.4597</longitude>
18
+ </centroid>
19
+ </administrativeScope>
20
+ <geographicScope>
21
+ <woeId>2344681</woeId>
22
+ <type>State</type>
23
+ <name><![CDATA[Ciudad de Buenos Aires, AR]]></name>
24
+ <centroid>
25
+ <latitude>-34.5465</latitude>
26
+ <longitude>-58.4597</longitude>
27
+ </centroid>
28
+ </geographicScope>
29
+ <extents>
30
+ <center>
31
+ <latitude>-34.5545</latitude>
32
+ <longitude>-58.4691</longitude>
33
+ </center>
34
+ <southWest>
35
+ <latitude>-34.6944</latitude>
36
+ <longitude>-58.6389</longitude>
37
+ </southWest>
38
+ <northEast>
39
+ <latitude>-34.4146</latitude>
40
+ <longitude>-58.2992</longitude>
41
+ </northEast>
42
+ </extents>
43
+ <placeDetails>
44
+ <place>
45
+ <woeId>468739</woeId>
46
+ <type>Town</type>
47
+ <name><![CDATA[Buenos Aires, Ciudad de Buenos Aires, AR]]></name>
48
+ <centroid>
49
+ <latitude>-34.5545</latitude>
50
+ <longitude>-58.4691</longitude>
51
+ </centroid>
52
+ </place>
53
+ <matchType>0</matchType>
54
+ <weight>10</weight>
55
+ <confidence>5</confidence>
56
+ </placeDetails>
57
+ <referenceList>
58
+ <reference>
59
+ <woeIds>468739</woeIds>
60
+ <start>22</start>
61
+ <end>34</end>
62
+ <isPlaintextMarker>0</isPlaintextMarker>
63
+ <text><![CDATA[Buenos Aires]]></text>
64
+ <type>xpathwithcounts</type>
65
+ <xpath><![CDATA[/rss[1]/channel[1]/item[3]/title[1]]]></xpath>
66
+ </reference>
67
+ </referenceList>
68
+ </document>
69
+ <document>
70
+ </document>
71
+ <document>
72
+ <administrativeScope>
73
+ <woeId>2461487</woeId>
74
+ <type>Town</type>
75
+ <name><![CDATA[North Pole, AK, US]]></name>
76
+ <centroid>
77
+ <latitude>64.7491</latitude>
78
+ <longitude>-147.353</longitude>
79
+ </centroid>
80
+ </administrativeScope>
81
+ <geographicScope>
82
+ <woeId>2461487</woeId>
83
+ <type>Town</type>
84
+ <name><![CDATA[North Pole, AK, US]]></name>
85
+ <centroid>
86
+ <latitude>64.7491</latitude>
87
+ <longitude>-147.353</longitude>
88
+ </centroid>
89
+ </geographicScope>
90
+ <extents>
91
+ <center>
92
+ <latitude>64.7491</latitude>
93
+ <longitude>-147.353</longitude>
94
+ </center>
95
+ <southWest>
96
+ <latitude>64.726</latitude>
97
+ <longitude>-147.428</longitude>
98
+ </southWest>
99
+ <northEast>
100
+ <latitude>64.7778</latitude>
101
+ <longitude>-147.304</longitude>
102
+ </northEast>
103
+ </extents>
104
+ <placeDetails>
105
+ <place>
106
+ <woeId>2461487</woeId>
107
+ <type>Town</type>
108
+ <name><![CDATA[North Pole, AK, US]]></name>
109
+ <centroid>
110
+ <latitude>64.7491</latitude>
111
+ <longitude>-147.353</longitude>
112
+ </centroid>
113
+ </place>
114
+ <matchType>0</matchType>
115
+ <weight>1</weight>
116
+ <confidence>4</confidence>
117
+ </placeDetails>
118
+ <referenceList>
119
+ <reference>
120
+ <woeIds>2461487</woeIds>
121
+ <start>900</start>
122
+ <end>910</end>
123
+ <isPlaintextMarker>0</isPlaintextMarker>
124
+ <text><![CDATA[North Pole]]></text>
125
+ <type>xpathwithcounts</type>
126
+ <xpath><![CDATA[/rss[1]/channel[1]/item[5]/description[1]]]></xpath>
127
+ </reference>
128
+ </referenceList>
129
+ </document>
130
+ <document>
131
+ <administrativeScope>
132
+ <woeId>23424977</woeId>
133
+ <type>Country</type>
134
+ <name><![CDATA[United States]]></name>
135
+ <centroid>
136
+ <latitude>48.8907</latitude>
137
+ <longitude>-116.982</longitude>
138
+ </centroid>
139
+ </administrativeScope>
140
+ <geographicScope>
141
+ <woeId>24875662</woeId>
142
+ <type>Colloquial</type>
143
+ <name><![CDATA[Continental United States, US]]></name>
144
+ <centroid>
145
+ <latitude>37.1669</latitude>
146
+ <longitude>-95.9669</longitude>
147
+ </centroid>
148
+ </geographicScope>
149
+ <extents>
150
+ <center>
151
+ <latitude>38.8913</latitude>
152
+ <longitude>-77.0337</longitude>
153
+ </center>
154
+ <southWest>
155
+ <latitude>18.9108</latitude>
156
+ <longitude>-167.276</longitude>
157
+ </southWest>
158
+ <northEast>
159
+ <latitude>72.8961</latitude>
160
+ <longitude>-66.6879</longitude>
161
+ </northEast>
162
+ </extents>
163
+ <placeDetails>
164
+ <place>
165
+ <woeId>2442047</woeId>
166
+ <type>Town</type>
167
+ <name><![CDATA[Los Angeles, CA, US]]></name>
168
+ <centroid>
169
+ <latitude>34.0533</latitude>
170
+ <longitude>-118.245</longitude>
171
+ </centroid>
172
+ </place>
173
+ <matchType>0</matchType>
174
+ <weight>1</weight>
175
+ <confidence>9</confidence>
176
+ </placeDetails>
177
+ <placeDetails>
178
+ <place>
179
+ <woeId>2459115</woeId>
180
+ <type>Town</type>
181
+ <name><![CDATA[New York, NY, US]]></name>
182
+ <centroid>
183
+ <latitude>40.7145</latitude>
184
+ <longitude>-74.0071</longitude>
185
+ </centroid>
186
+ </place>
187
+ <matchType>0</matchType>
188
+ <weight>1</weight>
189
+ <confidence>9</confidence>
190
+ </placeDetails>
191
+ <placeDetails>
192
+ <place>
193
+ <woeId>2514815</woeId>
194
+ <type>Town</type>
195
+ <name><![CDATA[Washington, DC, US]]></name>
196
+ <centroid>
197
+ <latitude>38.8913</latitude>
198
+ <longitude>-77.0337</longitude>
199
+ </centroid>
200
+ </place>
201
+ <matchType>0</matchType>
202
+ <weight>1</weight>
203
+ <confidence>9</confidence>
204
+ </placeDetails>
205
+ <placeDetails>
206
+ <place>
207
+ <woeId>23424977</woeId>
208
+ <type>Country</type>
209
+ <name><![CDATA[United States]]></name>
210
+ <centroid>
211
+ <latitude>48.8907</latitude>
212
+ <longitude>-116.982</longitude>
213
+ </centroid>
214
+ </place>
215
+ <matchType>0</matchType>
216
+ <weight>1</weight>
217
+ <confidence>9</confidence>
218
+ </placeDetails>
219
+ <referenceList>
220
+ <reference>
221
+ <woeIds>23424977</woeIds>
222
+ <start>1997</start>
223
+ <end>2004</end>
224
+ <isPlaintextMarker>0</isPlaintextMarker>
225
+ <text><![CDATA[America]]></text>
226
+ <type>xpathwithcounts</type>
227
+ <xpath><![CDATA[/rss[1]/channel[1]/item[6]/description[1]]]></xpath>
228
+ </reference>
229
+ <reference>
230
+ <woeIds>2514815</woeIds>
231
+ <start>3315</start>
232
+ <end>3325</end>
233
+ <isPlaintextMarker>0</isPlaintextMarker>
234
+ <text><![CDATA[Washington]]></text>
235
+ <type>xpathwithcounts</type>
236
+ <xpath><![CDATA[/rss[1]/channel[1]/item[6]/description[1]]]></xpath>
237
+ </reference>
238
+ <reference>
239
+ <woeIds>2514815</woeIds>
240
+ <start>521</start>
241
+ <end>534</end>
242
+ <isPlaintextMarker>0</isPlaintextMarker>
243
+ <text><![CDATA[Washington DC]]></text>
244
+ <type>xpathwithcounts</type>
245
+ <xpath><![CDATA[/rss[1]/channel[1]/item[6]/description[1]]]></xpath>
246
+ </reference>
247
+ <reference>
248
+ <woeIds>2459115</woeIds>
249
+ <start>634</start>
250
+ <end>642</end>
251
+ <isPlaintextMarker>0</isPlaintextMarker>
252
+ <text><![CDATA[New York]]></text>
253
+ <type>xpathwithcounts</type>
254
+ <xpath><![CDATA[/rss[1]/channel[1]/item[6]/description[1]]]></xpath>
255
+ </reference>
256
+ <reference>
257
+ <woeIds>2442047</woeIds>
258
+ <start>938</start>
259
+ <end>949</end>
260
+ <isPlaintextMarker>0</isPlaintextMarker>
261
+ <text><![CDATA[Los Angeles]]></text>
262
+ <type>xpathwithcounts</type>
263
+ <xpath><![CDATA[/rss[1]/channel[1]/item[6]/description[1]]]></xpath>
264
+ </reference>
265
+ </referenceList>
266
+ </document>
267
+ <document>
268
+ <administrativeScope>
269
+ <woeId>2346016</woeId>
270
+ <type>State</type>
271
+ <name><![CDATA[Bayrut, LB]]></name>
272
+ <centroid>
273
+ <latitude>33.8881</latitude>
274
+ <longitude>35.5139</longitude>
275
+ </centroid>
276
+ </administrativeScope>
277
+ <geographicScope>
278
+ <woeId>2346016</woeId>
279
+ <type>State</type>
280
+ <name><![CDATA[Bayrut, LB]]></name>
281
+ <centroid>
282
+ <latitude>33.8881</latitude>
283
+ <longitude>35.5139</longitude>
284
+ </centroid>
285
+ </geographicScope>
286
+ <extents>
287
+ <center>
288
+ <latitude>33.8927</latitude>
289
+ <longitude>35.4853</longitude>
290
+ </center>
291
+ <southWest>
292
+ <latitude>33.8562</latitude>
293
+ <longitude>35.467</longitude>
294
+ </southWest>
295
+ <northEast>
296
+ <latitude>33.9073</latitude>
297
+ <longitude>35.5751</longitude>
298
+ </northEast>
299
+ </extents>
300
+ <placeDetails>
301
+ <place>
302
+ <woeId>1960307</woeId>
303
+ <type>Town</type>
304
+ <name><![CDATA[Beirut, Bayrut, LB]]></name>
305
+ <centroid>
306
+ <latitude>33.8927</latitude>
307
+ <longitude>35.4853</longitude>
308
+ </centroid>
309
+ </place>
310
+ <matchType>0</matchType>
311
+ <weight>1</weight>
312
+ <confidence>9</confidence>
313
+ </placeDetails>
314
+ <referenceList>
315
+ <reference>
316
+ <woeIds>1960307</woeIds>
317
+ <start>396</start>
318
+ <end>402</end>
319
+ <isPlaintextMarker>0</isPlaintextMarker>
320
+ <text><![CDATA[Beirut]]></text>
321
+ <type>xpathwithcounts</type>
322
+ <xpath><![CDATA[/rss[1]/channel[1]/item[7]/description[1]]]></xpath>
323
+ </reference>
324
+ </referenceList>
325
+ </document>
326
+ <document>
327
+ <administrativeScope>
328
+ <woeId>2459115</woeId>
329
+ <type>Town</type>
330
+ <name><![CDATA[New York, NY, US]]></name>
331
+ <centroid>
332
+ <latitude>40.7145</latitude>
333
+ <longitude>-74.0071</longitude>
334
+ </centroid>
335
+ </administrativeScope>
336
+ <geographicScope>
337
+ <woeId>24701780</woeId>
338
+ <type>Zone</type>
339
+ <name><![CDATA[646 New York, NY, US]]></name>
340
+ <centroid>
341
+ <latitude>40.791</latitude>
342
+ <longitude>-73.9659</longitude>
343
+ </centroid>
344
+ </geographicScope>
345
+ <extents>
346
+ <center>
347
+ <latitude>40.791</latitude>
348
+ <longitude>-73.9659</longitude>
349
+ </center>
350
+ <southWest>
351
+ <latitude>40.6838</latitude>
352
+ <longitude>-74.0477</longitude>
353
+ </southWest>
354
+ <northEast>
355
+ <latitude>40.8819</latitude>
356
+ <longitude>-73.9067</longitude>
357
+ </northEast>
358
+ </extents>
359
+ <placeDetails>
360
+ <place>
361
+ <woeId>12589342</woeId>
362
+ <type>County</type>
363
+ <name><![CDATA[Manhattan, New York, NY, US]]></name>
364
+ <centroid>
365
+ <latitude>40.791</latitude>
366
+ <longitude>-73.9659</longitude>
367
+ </centroid>
368
+ </place>
369
+ <matchType>0</matchType>
370
+ <weight>1</weight>
371
+ <confidence>8</confidence>
372
+ </placeDetails>
373
+ <referenceList>
374
+ <reference>
375
+ <woeIds>12589342</woeIds>
376
+ <start>1939</start>
377
+ <end>1948</end>
378
+ <isPlaintextMarker>0</isPlaintextMarker>
379
+ <text><![CDATA[Manhattan]]></text>
380
+ <type>xpathwithcounts</type>
381
+ <xpath><![CDATA[/rss[1]/channel[1]/item[8]/description[1]]]></xpath>
382
+ </reference>
383
+ </referenceList>
384
+ </document>
385
+ <document>
386
+ </document>
387
+ <document>
388
+ <administrativeScope>
389
+ <woeId>1968212</woeId>
390
+ <type>Town</type>
391
+ <name><![CDATA[Tel Aviv, Tel Aviv, IL]]></name>
392
+ <centroid>
393
+ <latitude>32.0451</latitude>
394
+ <longitude>34.7697</longitude>
395
+ </centroid>
396
+ </administrativeScope>
397
+ <geographicScope>
398
+ <woeId>1968212</woeId>
399
+ <type>Town</type>
400
+ <name><![CDATA[Tel Aviv, Tel Aviv, IL]]></name>
401
+ <centroid>
402
+ <latitude>32.0451</latitude>
403
+ <longitude>34.7697</longitude>
404
+ </centroid>
405
+ </geographicScope>
406
+ <extents>
407
+ <center>
408
+ <latitude>32.0451</latitude>
409
+ <longitude>34.7697</longitude>
410
+ </center>
411
+ <southWest>
412
+ <latitude>32.0312</latitude>
413
+ <longitude>34.7413</longitude>
414
+ </southWest>
415
+ <northEast>
416
+ <latitude>32.146</latitude>
417
+ <longitude>34.8533</longitude>
418
+ </northEast>
419
+ </extents>
420
+ <placeDetails>
421
+ <place>
422
+ <woeId>1968212</woeId>
423
+ <type>Town</type>
424
+ <name><![CDATA[Tel Aviv, Tel Aviv, IL]]></name>
425
+ <centroid>
426
+ <latitude>32.0451</latitude>
427
+ <longitude>34.7697</longitude>
428
+ </centroid>
429
+ </place>
430
+ <matchType>0</matchType>
431
+ <weight>10</weight>
432
+ <confidence>9</confidence>
433
+ </placeDetails>
434
+ <referenceList>
435
+ <reference>
436
+ <woeIds>1968212</woeIds>
437
+ <start>108</start>
438
+ <end>118</end>
439
+ <isPlaintextMarker>0</isPlaintextMarker>
440
+ <text><![CDATA[Tel Aviv's]]></text>
441
+ <type>xpathwithcounts</type>
442
+ <xpath><![CDATA[/rss[1]/channel[1]/item[10]/description[1]]]></xpath>
443
+ </reference>
444
+ <reference>
445
+ <woeIds>1968212</woeIds>
446
+ <start>16</start>
447
+ <end>26</end>
448
+ <isPlaintextMarker>0</isPlaintextMarker>
449
+ <text><![CDATA[Tel Aviv's]]></text>
450
+ <type>xpathwithcounts</type>
451
+ <xpath><![CDATA[/rss[1]/channel[1]/item[10]/title[1]]]></xpath>
452
+ </reference>
453
+ </referenceList>
454
+ </document>
455
+ <document>
456
+ <administrativeScope>
457
+ <woeId>23424925</woeId>
458
+ <type>Country</type>
459
+ <name><![CDATA[Portugal]]></name>
460
+ <centroid>
461
+ <latitude>39.566</latitude>
462
+ <longitude>-7.84516</longitude>
463
+ </centroid>
464
+ </administrativeScope>
465
+ <geographicScope>
466
+ <woeId>23424925</woeId>
467
+ <type>Country</type>
468
+ <name><![CDATA[Portugal]]></name>
469
+ <centroid>
470
+ <latitude>39.566</latitude>
471
+ <longitude>-7.84516</longitude>
472
+ </centroid>
473
+ </geographicScope>
474
+ <extents>
475
+ <center>
476
+ <latitude>39.566</latitude>
477
+ <longitude>-7.84516</longitude>
478
+ </center>
479
+ <southWest>
480
+ <latitude>30.0329</latitude>
481
+ <longitude>-31.266</longitude>
482
+ </southWest>
483
+ <northEast>
484
+ <latitude>42.1542</latitude>
485
+ <longitude>-6.19021</longitude>
486
+ </northEast>
487
+ </extents>
488
+ <placeDetails>
489
+ <place>
490
+ <woeId>23424925</woeId>
491
+ <type>Country</type>
492
+ <name><![CDATA[Portugal]]></name>
493
+ <centroid>
494
+ <latitude>39.566</latitude>
495
+ <longitude>-7.84516</longitude>
496
+ </centroid>
497
+ </place>
498
+ <matchType>0</matchType>
499
+ <weight>1</weight>
500
+ <confidence>8</confidence>
501
+ </placeDetails>
502
+ <referenceList>
503
+ <reference>
504
+ <woeIds>23424925</woeIds>
505
+ <start>598</start>
506
+ <end>606</end>
507
+ <isPlaintextMarker>0</isPlaintextMarker>
508
+ <text><![CDATA[Portugal]]></text>
509
+ <type>xpathwithcounts</type>
510
+ <xpath><![CDATA[/rss[1]/channel[1]/item[11]/description[1]]]></xpath>
511
+ </reference>
512
+ </referenceList>
513
+ </document>
514
+ <document>
515
+ <administrativeScope>
516
+ <woeId>761570</woeId>
517
+ <type>Town</type>
518
+ <name><![CDATA[Gijon, Asturias, ES]]></name>
519
+ <centroid>
520
+ <latitude>43.542</latitude>
521
+ <longitude>-5.6638</longitude>
522
+ </centroid>
523
+ </administrativeScope>
524
+ <geographicScope>
525
+ <woeId>761570</woeId>
526
+ <type>Town</type>
527
+ <name><![CDATA[Gijon, Asturias, ES]]></name>
528
+ <centroid>
529
+ <latitude>43.542</latitude>
530
+ <longitude>-5.6638</longitude>
531
+ </centroid>
532
+ </geographicScope>
533
+ <extents>
534
+ <center>
535
+ <latitude>43.542</latitude>
536
+ <longitude>-5.6638</longitude>
537
+ </center>
538
+ <southWest>
539
+ <latitude>43.495</latitude>
540
+ <longitude>-5.75073</longitude>
541
+ </southWest>
542
+ <northEast>
543
+ <latitude>43.571</latitude>
544
+ <longitude>-5.60209</longitude>
545
+ </northEast>
546
+ </extents>
547
+ <placeDetails>
548
+ <place>
549
+ <woeId>761570</woeId>
550
+ <type>Town</type>
551
+ <name><![CDATA[Gijon, Asturias, ES]]></name>
552
+ <centroid>
553
+ <latitude>43.542</latitude>
554
+ <longitude>-5.6638</longitude>
555
+ </centroid>
556
+ </place>
557
+ <matchType>0</matchType>
558
+ <weight>10</weight>
559
+ <confidence>10</confidence>
560
+ </placeDetails>
561
+ <referenceList>
562
+ <reference>
563
+ <woeIds>761570</woeIds>
564
+ <start>28</start>
565
+ <end>40</end>
566
+ <isPlaintextMarker>0</isPlaintextMarker>
567
+ <text><![CDATA[Gijon, Spain]]></text>
568
+ <type>xpathwithcounts</type>
569
+ <xpath><![CDATA[/rss[1]/channel[1]/item[12]/title[1]]]></xpath>
570
+ </reference>
571
+ </referenceList>
572
+ </document>
573
+ <document>
574
+ </document>
575
+ <document>
576
+ </document>
577
+ <document>
578
+ <administrativeScope>
579
+ <woeId>2459115</woeId>
580
+ <type>Town</type>
581
+ <name><![CDATA[New York, NY, US]]></name>
582
+ <centroid>
583
+ <latitude>40.7145</latitude>
584
+ <longitude>-74.0071</longitude>
585
+ </centroid>
586
+ </administrativeScope>
587
+ <geographicScope>
588
+ <woeId>24701780</woeId>
589
+ <type>Zone</type>
590
+ <name><![CDATA[646 New York, NY, US]]></name>
591
+ <centroid>
592
+ <latitude>40.791</latitude>
593
+ <longitude>-73.9659</longitude>
594
+ </centroid>
595
+ </geographicScope>
596
+ <extents>
597
+ <center>
598
+ <latitude>40.7145</latitude>
599
+ <longitude>-74.0071</longitude>
600
+ </center>
601
+ <southWest>
602
+ <latitude>40.4957</latitude>
603
+ <longitude>-74.2557</longitude>
604
+ </southWest>
605
+ <northEast>
606
+ <latitude>40.9176</latitude>
607
+ <longitude>-73.7004</longitude>
608
+ </northEast>
609
+ </extents>
610
+ <placeDetails>
611
+ <place>
612
+ <woeId>2459115</woeId>
613
+ <type>Town</type>
614
+ <name><![CDATA[New York, NY, US]]></name>
615
+ <centroid>
616
+ <latitude>40.7145</latitude>
617
+ <longitude>-74.0071</longitude>
618
+ </centroid>
619
+ </place>
620
+ <matchType>0</matchType>
621
+ <weight>1</weight>
622
+ <confidence>7</confidence>
623
+ </placeDetails>
624
+ <referenceList>
625
+ <reference>
626
+ <woeIds>2459115</woeIds>
627
+ <start>197</start>
628
+ <end>205</end>
629
+ <isPlaintextMarker>0</isPlaintextMarker>
630
+ <text><![CDATA[New York]]></text>
631
+ <type>xpathwithcounts</type>
632
+ <xpath><![CDATA[/rss[1]/channel[1]/item[15]/description[1]]]></xpath>
633
+ </reference>
634
+ </referenceList>
635
+ </document>
636
+ </contentlocation>
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Placemaker::Document do
4
+ before do
5
+ @xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
6
+ @xmlp = Placemaker::XmlParser.new(@xml_str)
7
+ @doc = @xmlp.documents[5]
8
+ end
9
+
10
+ describe "#places" do
11
+ it "should have 4 places for the given node" do
12
+ @doc.places.size.should == 4
13
+ end
14
+
15
+ it "should return a Placemaker::Place object for the first node" do
16
+ @doc.places.first.should be_a(Placemaker::Place)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Placemaker::Place do
4
+ before do
5
+ @xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
6
+ @xmlp = Placemaker::XmlParser.new(@xml_str)
7
+ @doc = @xmlp.documents[5]
8
+ @place = @doc.places.first
9
+ end
10
+
11
+ describe "#woe_id" do
12
+ it "should equal 2442047" do
13
+ @place.woe_id.should == 2442047
14
+ end
15
+ end
16
+
17
+ describe "place_type" do
18
+ it "should be Town" do
19
+ @place.place_type.should == 'Town'
20
+ end
21
+ end
22
+
23
+ describe "#name" do
24
+ it "should be Los Angeles, CA, US" do
25
+ @place.name.should == 'Los Angeles, CA, US'
26
+ end
27
+ end
28
+
29
+ describe "centroid" do
30
+
31
+ it "should be a Placemaker::Point object" do
32
+ @place.centroid.should be_a(Placemaker::Point)
33
+ end
34
+
35
+ it "should return an object with lat set to 34.0533" do
36
+ @place.centroid.lat.should == 34.0533
37
+ end
38
+
39
+ it "should return an object with lng set to -118.245" do
40
+ @place.centroid.lng.should == -118.245
41
+ end
42
+ end
43
+
44
+ describe "#match_type" do
45
+ it "should be 0" do
46
+ @place.match_type.should == 0
47
+ end
48
+ end
49
+
50
+ describe "#weight" do
51
+ it "should be 1" do
52
+ @place.weight.should == 1
53
+ end
54
+ end
55
+
56
+ describe "#confidence" do
57
+ it "should be 9" do
58
+ @place.confidence.should == 9
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Placemaker::Reader do
4
+ before do
5
+ @valid_opts = {
6
+ :document_url => 'http://www.example.com',
7
+ :document_type => 'text/plain'
8
+ }
9
+ end
10
+
11
+ describe "object initialization" do
12
+ it "should set appid to the value of ENV['PLACEMAKER_APPID']" do
13
+ ENV['PLACEMAKER_APPID'] = 'foo'
14
+ p = Placemaker::Reader.new(@valid_opts)
15
+ p.appid.should == 'foo'
16
+ end
17
+
18
+ it "should initialize #documents to an empty array" do
19
+ p = Placemaker::Reader.new(@valid_opts)
20
+ p.documents.should be_a(Array)
21
+ p.documents.should be_empty
22
+ end
23
+
24
+ it "should raise an argument error if the document_type is not correctly set" do
25
+ lambda {
26
+ Placemaker::Reader.new(@valid_opts.except(:document_type))
27
+ }.should raise_error(ArgumentError)
28
+ end
29
+
30
+ it "should set the appid to the value of options[:appid] if provided" do
31
+ ENV['PLACEMAKER_APPID'] = 'foo'
32
+ p = Placemaker::Reader.new(@valid_opts.merge(:appid => 'fark', :document_url => 'foo'))
33
+ p.appid.should == 'fark'
34
+ end
35
+
36
+ it "should create methods to allow access to configuration parameters" do
37
+ p = Placemaker::Reader.new(@valid_opts.merge(:document_content => 'foo'))
38
+ p.document_content.should == 'foo'
39
+ end
40
+
41
+ it "should raise an error if both document_content and document_url are nil" do
42
+ lambda {
43
+ p = Placemaker::Reader.new
44
+ }.should raise_error(ArgumentError)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,18 @@
1
+ require File.join(File.dirname(__FILE__), %w[ .. spec_helper])
2
+
3
+ describe Placemaker::XmlParser do
4
+ before do
5
+ @xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
6
+ @xmlp = Placemaker::XmlParser.new(@xml_str)
7
+ end
8
+
9
+ describe "#documents" do
10
+ it "should return 15 documents" do
11
+ @xmlp.documents.size.should == 15
12
+ end
13
+
14
+ it "should contain all Placemaker::Document objects" do
15
+ @xmlp.documents.all?{|d| d.class == Placemaker::Document}.should be_true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'mocha'
3
+ require 'spec'
4
+
5
+ require File.join(File.dirname(__FILE__), %w[.. lib placemaker])
6
+
7
+ Spec::Runner.configure do |config|
8
+ config.mock_with(:mocha)
9
+ end
10
+
11
+ shared_examples_for "all backends" do
12
+ it "should respond to #get" do
13
+ @backend.should respond_to(:get)
14
+ end
15
+
16
+ it "should respond to #set" do
17
+ @backend.should respond_to(:set)
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsl-placemaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.1
4
+ version: 0.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Leitgeb
@@ -41,7 +41,23 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - README.rdoc
43
43
  files:
44
+ - lib/core_ext/array.rb
45
+ - lib/core_ext/hash.rb
46
+ - lib/placemaker/document.rb
47
+ - lib/placemaker/place.rb
48
+ - lib/placemaker/reader.rb
49
+ - lib/placemaker/xml_parser.rb
50
+ - lib/placemaker.rb
51
+ - LICENSE
52
+ - placemaker.gemspec
53
+ - Rakefile
44
54
  - README.rdoc
55
+ - spec/fixtures/xml_rss_feed_result.xml
56
+ - spec/placemaker/document_spec.rb
57
+ - spec/placemaker/place_spec.rb
58
+ - spec/placemaker/reader_spec.rb
59
+ - spec/placemaker/xml_parser_spec.rb
60
+ - spec/spec_helper.rb
45
61
  has_rdoc: true
46
62
  homepage: http://github.com/jsl/placemaker
47
63
  post_install_message:
@@ -74,5 +90,10 @@ rubygems_version: 1.2.0
74
90
  signing_key:
75
91
  specification_version: 2
76
92
  summary: Ruby interface over the Yahoo Placemaker API
77
- test_files: []
78
-
93
+ test_files:
94
+ - spec/fixtures/xml_rss_feed_result.xml
95
+ - spec/placemaker/document_spec.rb
96
+ - spec/placemaker/place_spec.rb
97
+ - spec/placemaker/reader_spec.rb
98
+ - spec/placemaker/xml_parser_spec.rb
99
+ - spec/spec_helper.rb