woefoo 0.0.10 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/woefoo/config.rb +3 -1
- data/lib/woefoo/town_match_validators.rb +13 -9
- data/lib/woefoo/version.rb +1 -1
- data/lib/woefoo.rb +34 -14
- metadata +4 -4
data/lib/woefoo/config.rb
CHANGED
@@ -6,6 +6,8 @@ module Woefoo
|
|
6
6
|
attr :placefinder_result_count, true
|
7
7
|
# the minimum input quality for a canonical town match
|
8
8
|
attr :min_input_quality, true
|
9
|
+
# the minimum result quality for a canonical town match
|
10
|
+
attr :min_result_quality, true
|
9
11
|
|
10
12
|
def placefinder_result_count
|
11
13
|
(@placefinder_result_count && @placefinder_result_count > 0) ? @placefinder_result_count : 3
|
@@ -16,7 +18,7 @@ module Woefoo
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def min_result_quality
|
19
|
-
(@min_result_quality && @min_result_quality > 0) ? @min_result_quality :
|
21
|
+
(@min_result_quality && @min_result_quality > 0) ? @min_result_quality : 40
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -17,15 +17,19 @@ module Woefoo::TownMatchValidators
|
|
17
17
|
response.results.each do |r|
|
18
18
|
if r[:quality] >= response.input_quality && r[:quality] >= min_result_quality
|
19
19
|
place=Woefoo::GeoplanetPlace.find_by_woeid(r[:woeid])
|
20
|
-
if place
|
21
|
-
|
22
|
-
|
23
|
-
response.query_options
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
response.query_options
|
28
|
-
|
20
|
+
if place
|
21
|
+
if place.place_type=="Town"
|
22
|
+
# If the query included a country code, make sure the place we're picking is in the same country!
|
23
|
+
next if (response.query_options.include?(:country_code) &&
|
24
|
+
response.query_options[:country_code].downcase != place.country_code.downcase)
|
25
|
+
best_match=r[:woeid]
|
26
|
+
elsif ["Zip", "Suburb"].include?(place.place_type) && place.town
|
27
|
+
next if (response.query_options.include?(:country_code) &&
|
28
|
+
response.query_options[:country_code].downcase != place.country_code.downcase)
|
29
|
+
best_match=place.town.woeid
|
30
|
+
end
|
31
|
+
else
|
32
|
+
puts "Encountered a woeid without a geoplanet place #{r[:woeid]}"
|
29
33
|
end
|
30
34
|
end
|
31
35
|
break if best_match
|
data/lib/woefoo/version.rb
CHANGED
data/lib/woefoo.rb
CHANGED
@@ -17,19 +17,34 @@ module Woefoo
|
|
17
17
|
|
18
18
|
def lookup_town_woeid(opts={})
|
19
19
|
validate!(opts)
|
20
|
-
woeid
|
20
|
+
results = {:woeid=>nil}
|
21
21
|
# First try the parameterized query, if the user bothered to separate out the fields
|
22
22
|
if opts.length > 1
|
23
|
-
|
24
|
-
woeid = canonical_town_match(
|
23
|
+
results[:parameterized_response] = perform_parameterized_lookup(opts)
|
24
|
+
results[:woeid] = canonical_town_match(results[:parameterized_response])
|
25
25
|
end
|
26
26
|
|
27
|
-
if !woeid
|
28
|
-
|
29
|
-
woeid = canonical_town_match(
|
27
|
+
if !results[:woeid]
|
28
|
+
results[:query_response] = perform_lookup(opts)
|
29
|
+
results[:woeid] = canonical_town_match(results[:query_response])
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
results
|
33
|
+
end
|
34
|
+
|
35
|
+
def lookup_town_woeid_by_geo(opts={})
|
36
|
+
results = {:woeid=>nil}
|
37
|
+
results[:geo_response] = perform_geo_lookup(opts)
|
38
|
+
results[:woeid] = canonical_town_match(results[:geo_response])
|
39
|
+
|
40
|
+
results
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate!(opts)
|
44
|
+
raise "Woefoo.appid is not defined" if !@appid
|
45
|
+
if opts.length == 0 || opts.include?(:query) && (opts[:query] == "")
|
46
|
+
raise "Invalid query"
|
47
|
+
end
|
33
48
|
end
|
34
49
|
|
35
50
|
|
@@ -43,12 +58,6 @@ module Woefoo
|
|
43
58
|
end
|
44
59
|
end
|
45
60
|
|
46
|
-
def validate!(opts)
|
47
|
-
raise "Woefoo.appid is not defined" if !@appid
|
48
|
-
if opts.length == 0 || opts.include?(:query) && (opts[:query] == "")
|
49
|
-
raise "Invalid query"
|
50
|
-
end
|
51
|
-
end
|
52
61
|
|
53
62
|
# Build a single query url
|
54
63
|
def build_query_url(opts={})
|
@@ -70,12 +79,17 @@ module Woefoo
|
|
70
79
|
build_query_keys(opts).each do |l|
|
71
80
|
if opts.include?(l)
|
72
81
|
val = ::CGI.escape(opts[l])
|
73
|
-
s << "&#{l.to_s}=#{val}
|
82
|
+
s << "&#{l.to_s}=#{val}"
|
74
83
|
end
|
75
84
|
end
|
76
85
|
"http://where.yahooapis.com/geocode?appid=#{@appid}&count=#{placefinder_result_count}#{s}"
|
77
86
|
end
|
78
87
|
|
88
|
+
|
89
|
+
def build_geo_url(opts={})
|
90
|
+
"http://where.yahooapis.com/geocode?appid=#{@appid}&count=#{placefinder_result_count}&gflags=R&q=#{opts[:lat]},+#{opts[:lng]}"
|
91
|
+
end
|
92
|
+
|
79
93
|
def perform_lookup(opts)
|
80
94
|
url = build_query_url(opts)
|
81
95
|
tr = Typhoeus::Request.get(url)
|
@@ -88,6 +102,12 @@ module Woefoo
|
|
88
102
|
Woefoo::Response.new(opts, tr) if tr
|
89
103
|
end
|
90
104
|
|
105
|
+
def perform_geo_lookup(opts)
|
106
|
+
url = build_geo_url(opts)
|
107
|
+
tr = Typhoeus::Request.get(url)
|
108
|
+
Woefoo::Response.new(opts, tr) if tr
|
109
|
+
end
|
110
|
+
|
91
111
|
def build_query_keys(opts={})
|
92
112
|
k = [:line1, :city, :state, :postal, :country]
|
93
113
|
if opts.include?(:country)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woefoo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 14
|
10
|
+
version: 0.0.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- smnirven
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-10 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: typhoeus
|