ym4r 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ym4r/yahoo_maps/building_block/local_search.rb +47 -54
- data/rakefile.rb +2 -2
- data/test/test_geocoding.rb +1 -0
- data/test/test_local_search.rb +6 -4
- metadata +3 -3
@@ -41,71 +41,64 @@ module Ym4r
|
|
41
41
|
url << "category=#{param[:category]}&" if param.has_key?(:category)
|
42
42
|
url << "omit_category=#{param[:omit_category]}&" if param.has_key?(:omit_category)
|
43
43
|
url << "minimum_rating=#{param[:minimum_rating]}&" if param.has_key?(:minimum_rating)
|
44
|
-
url << "output=
|
44
|
+
url << "output=xml"
|
45
45
|
|
46
46
|
begin
|
47
|
-
|
47
|
+
xml = open(URI.encode(url)).read
|
48
48
|
rescue OpenURI::HTTPError => error
|
49
49
|
raise BadRequestException.new(error.to_s)
|
50
50
|
rescue
|
51
51
|
raise ConnectionException.new("Unable to connect to Yahoo! Maps REST service")
|
52
52
|
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
raise RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Traffic REST service")
|
54
|
+
doc = REXML::Document.new(xml)
|
55
|
+
|
56
|
+
if doc.root.name == "Error"
|
57
|
+
raise RateLimitExceededException.new("Rate limit exceeded for Yahoo! Maps Geocoding service")
|
59
58
|
else
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
unless json_result_set['Result'].nil?
|
68
|
-
json_results = [json_result_set['Result']].flatten #uniform processing in case there is only one result
|
59
|
+
doc_root = doc.root
|
60
|
+
result_set = LocalSearch::ResultSet.new(doc_root.elements['ResultSetMapUrl'].text,
|
61
|
+
doc_root.attributes['totalResultsAvailable'].to_i,
|
62
|
+
doc_root.attributes['totalResultsReturned'].to_i,
|
63
|
+
doc_root.attributes['firstResultPosition'].to_i)
|
64
|
+
doc.elements.each("//Result") do |result|
|
65
|
+
data = result.elements
|
69
66
|
|
70
|
-
|
67
|
+
rating_data = data['Rating'].elements
|
68
|
+
if rating_data['AverageRating'].text != "NaN"
|
69
|
+
rating = LocalSearch::Rating.new(rating_data['AverageRating'].text.to_f, #when NaN, converted to 0 but can be tested (since TotalRating is 0 in this case) with is_rated? on the rating object
|
70
|
+
rating_data['TotalRatings'].text.to_i,
|
71
|
+
rating_data['TotalReviews'].text.to_i,
|
72
|
+
Time.at(rating_data['LastReviewDate'].text.to_i),
|
73
|
+
rating_data['LastReviewIntro'].text)
|
74
|
+
else
|
75
|
+
rating = LocalSearch::Rating.new(0,0,0,Time.at(0),"")
|
76
|
+
end
|
77
|
+
|
78
|
+
categories = []
|
79
|
+
data.each('//Category') do |category|
|
80
|
+
categories << LocalSearch::Category.new(category.attributes['id'].to_i,
|
81
|
+
category.text)
|
82
|
+
end
|
71
83
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
result_set << LocalSearch::Result.new(json_result['id'].to_i,
|
91
|
-
json_result['Title'],
|
92
|
-
json_result['Address'],
|
93
|
-
json_result['City'],
|
94
|
-
json_result['State'],
|
95
|
-
json_result['Phone'],
|
96
|
-
json_result['Latitude'].to_f,
|
97
|
-
json_result['Longitude'].to_f,
|
98
|
-
rating,
|
99
|
-
json_result['Distance'].to_f,
|
100
|
-
json_result['Url'],
|
101
|
-
json_result['ClickUrl'],
|
102
|
-
json_result['MapUrl'],
|
103
|
-
json_result['BusinessUrl'],
|
104
|
-
json_result['BusinessClickUrl'],
|
105
|
-
categories)
|
106
|
-
|
107
|
-
end
|
108
|
-
end #unless json_result_set['Result'].nil?
|
84
|
+
result_set << LocalSearch::Result.new(result.attributes['id'].to_i,
|
85
|
+
data['Title'].text || "",
|
86
|
+
data['Address'].text || "",
|
87
|
+
data['City'].text || "",
|
88
|
+
data['State'].text || "",
|
89
|
+
data['Phone'].text || "",
|
90
|
+
data['Latitude'].text.to_f,
|
91
|
+
data['Longitude'].text.to_f,
|
92
|
+
rating,
|
93
|
+
data['Distance'].text.to_f,
|
94
|
+
data['Url'].text || "",
|
95
|
+
data['ClickUrl'].text || "",
|
96
|
+
data['MapUrl'].text || "",
|
97
|
+
data['BusinessUrl'].text || "",
|
98
|
+
data['BusinessClickUrl'].text || "",
|
99
|
+
categories)
|
100
|
+
|
101
|
+
end
|
109
102
|
|
110
103
|
result_set
|
111
104
|
|
data/rakefile.rb
CHANGED
@@ -24,12 +24,12 @@ spec = Gem::Specification::new do |s|
|
|
24
24
|
s.platform = Gem::Platform::RUBY
|
25
25
|
|
26
26
|
s.name = 'ym4r'
|
27
|
-
s.version = "0.5.
|
27
|
+
s.version = "0.5.4"
|
28
28
|
s.summary = "Helping the use of Google Maps and Yahoo! Maps API's from Ruby and Rails"
|
29
29
|
s.description = <<EOF
|
30
30
|
EOF
|
31
31
|
s.author = 'Guilhem Vellut'
|
32
|
-
s.email = 'guilhem.vellut
|
32
|
+
s.email = 'guilhem.vellut@gmail.com'
|
33
33
|
s.homepage = "http://thepochisuperstarmegashow.com"
|
34
34
|
|
35
35
|
s.requirements << 'none'
|
data/test/test_geocoding.rb
CHANGED
data/test/test_local_search.rb
CHANGED
@@ -13,9 +13,7 @@ class TestLocalSearch< Test::Unit::TestCase
|
|
13
13
|
:state => "CA",
|
14
14
|
:zip => "95014",
|
15
15
|
:query => "chinese")
|
16
|
-
|
17
16
|
assert(! results.nil?)
|
18
|
-
|
19
17
|
results.each do |result|
|
20
18
|
assert(!result.id.nil?)
|
21
19
|
assert(!result.title.nil?)
|
@@ -34,9 +32,7 @@ class TestLocalSearch< Test::Unit::TestCase
|
|
34
32
|
assert(!result.business_click_url.nil?)
|
35
33
|
assert(!result.categories.nil?)
|
36
34
|
assert(result.categories.is_a?(Array))
|
37
|
-
|
38
35
|
end
|
39
|
-
|
40
36
|
end
|
41
37
|
|
42
38
|
def test_no_query
|
@@ -59,4 +55,10 @@ class TestLocalSearch< Test::Unit::TestCase
|
|
59
55
|
assert_equal(0,results.length)
|
60
56
|
|
61
57
|
end
|
58
|
+
|
59
|
+
def test_ooo
|
60
|
+
results = LocalSearch::get(:query => 'Daily Grind', :city => 'Portland',:state => 'OR')
|
61
|
+
assert(!results.nil?)
|
62
|
+
end
|
63
|
+
|
62
64
|
end
|
metadata
CHANGED
@@ -3,12 +3,12 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ym4r
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.5.
|
7
|
-
date: 2006-10-
|
6
|
+
version: 0.5.4
|
7
|
+
date: 2006-10-30 00:00:00 +01:00
|
8
8
|
summary: Helping the use of Google Maps and Yahoo! Maps API's from Ruby and Rails
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
|
-
email: guilhem.vellut
|
11
|
+
email: guilhem.vellut@gmail.com
|
12
12
|
homepage: http://thepochisuperstarmegashow.com
|
13
13
|
rubyforge_project:
|
14
14
|
description: ""
|