Active 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +7 -0
- data/bin/Active +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/services/activity.rb +19 -8
- data/lib/services/search.rb +11 -4
- data/spec/activity_spec.rb +12 -1
- data/spec/search_spec.rb +20 -3
- data/version.txt +1 -1
- metadata +6 -11
data/README.txt
CHANGED
data/bin/Active
CHANGED
File without changes
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/services/activity.rb
CHANGED
@@ -2,17 +2,21 @@ module Active
|
|
2
2
|
module Services
|
3
3
|
class Activity
|
4
4
|
attr_accessor :title, :url, :category, :address, :start_date, :start_time, :end_time, :end_date, :category, :desc,
|
5
|
-
:asset_id, :data
|
5
|
+
:asset_id, :asset_type_id, :data, :endIndex, :pageSize, :searchTime, :numberOfResults
|
6
6
|
def initialize data
|
7
7
|
@data = HashWithIndifferentAccess.new(data)
|
8
|
-
self.title
|
9
|
-
@url
|
8
|
+
self.title = @data[:title]
|
9
|
+
@url = @data[:url]
|
10
|
+
@pageSize = @data[:pageSize]
|
11
|
+
@searchTime = @data[:searchTime]
|
12
|
+
@numberOfResults = @data[:numberOfResults]
|
10
13
|
|
11
14
|
unless @data[:meta].nil?
|
12
|
-
self.asset_id
|
13
|
-
|
14
|
-
@
|
15
|
-
|
15
|
+
self.asset_id = @data[:meta][:assetId]
|
16
|
+
self.asset_type_id = @data[:meta][:assetTypeId]
|
17
|
+
@start_date = Date.parse(@data[:meta][:startDate])
|
18
|
+
@end_date = Date.parse(@data[:meta][:endDate]) if @data[:meta][:endDate]
|
19
|
+
self.category = @data[:meta][:channel] ||= ""
|
16
20
|
|
17
21
|
@desc = @data[:meta][:description] ||= ""
|
18
22
|
@start_time = @data[:meta][:startTime] ||= ""
|
@@ -37,7 +41,14 @@ module Active
|
|
37
41
|
|
38
42
|
end
|
39
43
|
|
40
|
-
|
44
|
+
def title=(value)
|
45
|
+
@title = value.gsub(/<\/?[^>]*>/, "")
|
46
|
+
if value.include?("|")
|
47
|
+
@title = @title.split("|")[0].strip!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO add many channels
|
41
52
|
def category=(value)
|
42
53
|
@category = (value.class == Array) ? value[0] : value
|
43
54
|
end
|
data/lib/services/search.rb
CHANGED
@@ -174,9 +174,12 @@ module Active
|
|
174
174
|
http.get("#{searchurl.path}?#{searchurl.query}")
|
175
175
|
}
|
176
176
|
|
177
|
-
if res.code == '200'
|
177
|
+
# if res.code == '200' or res.code == '307'
|
178
|
+
if (200..307).include?(res.code.to_i)
|
178
179
|
parsed_json = JSON.parse(res.body)
|
179
|
-
parsed_json[
|
180
|
+
return parsed_json["numberOfResults"] if data.has_key?(:show_number_of_results)
|
181
|
+
query_addl_info= {:endIndex=>parsed_json["endIndex"], :pageSize=>parsed_json["pageSize"], :searchTime=>parsed_json["searchTime"], :numberOfResults=>parsed_json["numberOfResults"]}
|
182
|
+
parsed_json['_results'].collect { |a| Activity.new(a.merge query_addl_info) }
|
180
183
|
else
|
181
184
|
raise RuntimeError, "Active Search responded with a #{res.code} for your query."
|
182
185
|
end
|
@@ -188,7 +191,7 @@ module Active
|
|
188
191
|
:view => "json",
|
189
192
|
:facet => Facet.ACTIVITIES,
|
190
193
|
:sort => Sort.DATE_ASC,
|
191
|
-
:radius => "
|
194
|
+
:radius => "50",
|
192
195
|
:meta => "",
|
193
196
|
:num_results => "10",
|
194
197
|
:page => "1",
|
@@ -200,6 +203,8 @@ module Active
|
|
200
203
|
:end_date => "+"
|
201
204
|
}
|
202
205
|
options.merge!(arg_options)
|
206
|
+
|
207
|
+
return arg_options[:url] if arg_options.keys.index(:url) #a search url was specified - bypass parsing the options (trending)
|
203
208
|
|
204
209
|
options[:location] = CGI.escape(options[:location]) if options[:location]
|
205
210
|
|
@@ -239,7 +244,9 @@ module Active
|
|
239
244
|
# end
|
240
245
|
#
|
241
246
|
url = "#{SEARCH_URL}/search?api_key=#{options[:api_key]}&num=#{options[:num_results]}&page=#{options[:page]}&l=#{options[:location]}&f=#{options[:facet]}&v=#{options[:view]}&r=#{options[:radius]}&s=#{options[:sort]}&k=#{options[:keywords].join("+")}&m=#{meta_data}"
|
242
|
-
|
247
|
+
puts "//////"
|
248
|
+
puts url
|
249
|
+
puts "//////"
|
243
250
|
url
|
244
251
|
end
|
245
252
|
|
data/spec/activity_spec.rb
CHANGED
@@ -9,7 +9,7 @@ include Active::Services
|
|
9
9
|
describe Activity do
|
10
10
|
before(:each) do
|
11
11
|
@valid_attributes = {
|
12
|
-
:title => "2011 Walt Disney World\xAE Marathon | Lake Buena Vista, Florida <b>...</b>",
|
12
|
+
:title => "<b>2011 Walt Disney World\xAE Marathon \u003cb\u003e...\u003c/b\u003e | Lake Buena Vista, Florida <b>...</b>",
|
13
13
|
:url => "http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011",
|
14
14
|
:language => "en",
|
15
15
|
:meta => {
|
@@ -56,6 +56,17 @@ describe Activity do
|
|
56
56
|
}
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should strip out html from the title" do
|
60
|
+
a = Activity.new(@valid_attributes)
|
61
|
+
a.title.should eql("2011 Walt Disney World Marathon")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should strip out unicode from the title"
|
65
|
+
|
66
|
+
it "should use the first group if title contains pipes." do
|
67
|
+
|
68
|
+
end
|
69
|
+
|
59
70
|
it "should be a valid activity" do
|
60
71
|
a = Activity.new(@valid_attributes)
|
61
72
|
a.url.should eql("http://www.active.com/running/lake-buena-vista-fl/walt-disney-world-marathon-2011")
|
data/spec/search_spec.rb
CHANGED
@@ -13,6 +13,23 @@ describe "Set up" do
|
|
13
13
|
it "should call search.active.com when told to"
|
14
14
|
end
|
15
15
|
|
16
|
+
describe "Handle http server codes" do
|
17
|
+
after(:each) do
|
18
|
+
FakeWeb.clean_registry
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should follow a 302" do
|
22
|
+
FakeWeb.register_uri(:get, "http://search.active.com/search?api_key=&num=10&page=1&l=San+Diego%2C+CA%2C+US&f=activities&v=json&r=10&s=date_asc&k=&m=meta:startDate:daterange:today..+",
|
23
|
+
:body => '{"endIndex":5,"numberOfResults":2,"pageSize":5,"searchTime":0.600205,"_results":[{"escapedUrl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","language": "en","title": "Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","summary": "\u003cb\u003e...\u003c/b\u003e Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs. Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e Recent Reviews Calabasas\u003cbr\u003e Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs reviews. Get Directions. Start Address. End Address \u003cb\u003e...\u003c/b\u003e ","meta": {"startDate": "2010-11-14","eventDate": "2010-11-14T08:00:00-08:00","location": "Calabasas Park Centre","tag": ["event:10", "Green:10", "Running:10"],"state": "California","eventLongitude": "-118.6789","endDate": "2010-11-14","locationName": "Calabasas Park Centre","splitMediaType": ["Event", "1 mile", "10K", "5K"],"endTime": "8:00:00","mediaType": ["Event", "Event\\1 mile", "Event\\10K", "Event\\5K"],"google-site-verification": "","city": "Calabasas","startTime": "8:00:00","assetId": ["11B01475-8C65-4F9C-A4AC-2A3FA55FE8CD", "11b01475-8c65-4f9c-a4ac-2a3fa55fe8cd"],"eventId": "1810531","participationCriteria": "All","description": "","longitude": "-118.6789","onlineDonationAvailable": "false","substitutionUrl": "1810531","assetName": ["Calabasas Classic 2010 - 5k 10k Runs", "Calabasas Classic 2010 - 5k 10k Runs"],"zip": "91302","contactPhone": "818-715-0428","sortDate": "2000-11-14","eventState": "California","eventLatitude": "34.12794","keywords": "Event","eventAddress": "23975 Park Sorrento","contactEmail": "rot10kd@yahoo.com","onlineMembershipAvailable": "false","trackbackurl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://www.active.com/images/events/hotrace.gif","assetTypeId": "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate": "2010-03-04 07:30:26.307","eventZip": "91302","latitude": "34.12794","UpdateDateTime": "8/18/2010 10:16:26 AM","channel": ["Running", "Walking"]}},
|
24
|
+
{"escapedUrl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","language": "en","title": "Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10/17, 11/21) \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","summary": "\u003cb\u003e...\u003c/b\u003e Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10/17, 11/21). Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e\u003cbr\u003e Reviews of Fitness For Vitality 5k/\u003cb\u003e10k\u003c/b\u003e 3-Race Series (9/19, 10. \u003cb\u003e...\u003c/b\u003e ","meta": {"summary": "\u003cp style\u003dtext-align:left\u003e\u003cfont style\u003dfont-family:UniversEmbedded;font-size:12;color:#000000; LETTERSPACING\u003d0 KERNING\u003d0\u003eRace or walk on a flat, fast, and fun course! The entire event is along the Puget Sound. Do all 3 events in the series and watch your time and fitness improve! Oatmeal post-race. 10% proceeds sh","startDate": "2010-09-19","eventDate": "2010-09-19","location": "Alki Beach Park, Seattle","tag": ["event:10", "Running:10"],"state": "Washington","endDate": "2010-11-22","locationName": "1702 Alki Ave. SW","splitMediaType": ["5K", "difficulty:Beginner", "difficulty:Advanced", "Event", "difficulty:Intermediate", "10K"],"lastModifiedDateTime": "2010-08-19 23:35:50.117","endTime": "07:59:59","mediaType": ["5K", "difficulty:Beginner", "difficulty:Advanced", "Event", "difficulty:Intermediate", "10K"],"google-site-verification": "","city": "Seattle","startTime": "07:00:00","assetId": ["39e8177e-dd0e-42a2-8a2b-24055e5325f3", "39e8177e-dd0e-42a2-8a2b-24055e5325f3"],"eventId": "E-000NGFS9","participationCriteria": "Kids,Family","description": "","longitude": "-122.3912","substitutionUrl": "E-000NGFS9","assetName": ["Fitness For Vitality 5k/10k 3-Race Series (9/19, 10/17, 11/21)", "Fitness For Vitality 5k/10k 3-Race Series (9/19, 10/17, 11/21)"],"zip": "98136","contactPhone": "n/a","eventState": "WA","sortDate": "2000-09-19","keywords": "Event","eventAddress": "1702 Alki Ave. SW","contactEmail": "n/a","dma": "Seattle - Tacoma","trackbackurl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","seourl": "http://www.active.com/10k-race/seattle-wa/fitness-for-vitality-5k10k-3race-series-919-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://photos-images.active.com/file/3/1/optimized/9015e50d-3a2e-4ce4-9ddc-80b05b973b01.jpg","allText": "\u003cp style\u003dtext-align:left\u003e\u003cfont style\u003dfont-family:UniversEmbedded;font-size:12;color:#000000; LETTERSPACING\u003d0 KERNING\u003d0\u003eRace or walk on a flat, fast, and fun course! The entire event is along the Puget Sound. Do all 3 events in the series and watch your time and fitness improve! Oatmeal post-race. 10% proceeds sh","address": "1702 Alki Ave. SW","assetTypeId": "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1","lastModifiedDate": "2010-08-19","eventZip": "98136","latitude": "47.53782","UpdateDateTime": "8/18/2010 10:16:08 AM","channel": "Running"}},
|
25
|
+
{"escapedUrl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","language": "en","title": "Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs | Calabasas, California 91302 \u003cb\u003e...\u003c/b\u003e","url": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","summary": "\u003cb\u003e...\u003c/b\u003e Calabasas Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs. Based on 0 reviews. \u003cb\u003e...\u003c/b\u003e Recent Reviews Calabasas\u003cbr\u003e Classic 2010 - 5k \u003cb\u003e10k\u003c/b\u003e Runs reviews. Get Directions. Start Address. End Address \u003cb\u003e...\u003c/b\u003e ","meta": {"startDate": "2010-11-14","eventDate": "2010-11-14T08:00:00-08:00","location": "Calabasas Park Centre","tag": ["event:10", "Green:10", "Running:10"],"state": "California","eventLongitude": "-118.6789","endDate": "2010-11-14","locationName": "Calabasas Park Centre","splitMediaType": ["Event", "1 mile", "10K", "5K"],"endTime": "8:00:00","mediaType": ["Event", "Event\\1 mile", "Event\\10K", "Event\\5K"],"google-site-verification": "","city": "Calabasas","startTime": "8:00:00","assetId": ["11B01475-8C65-4F9C-A4AC-2A3FA55FE8CD", "11b01475-8c65-4f9c-a4ac-2a3fa55fe8cd"],"eventId": "1810531","participationCriteria": "All","description": "","longitude": "-118.6789","onlineDonationAvailable": "false","substitutionUrl": "1810531","assetName": ["Calabasas Classic 2010 - 5k 10k Runs", "Calabasas Classic 2010 - 5k 10k Runs"],"zip": "91302","contactPhone": "818-715-0428","sortDate": "2000-11-14","eventState": "California","eventLatitude": "34.12794","keywords": "Event","eventAddress": "23975 Park Sorrento","contactEmail": "rot10kd@yahoo.com","onlineMembershipAvailable": "false","trackbackurl": "http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","country": "United States","onlineRegistrationAvailable": "true","category": "Activities","image1": "http://www.active.com/images/events/hotrace.gif","assetTypeId": "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate": "2010-03-04 07:30:26.307","eventZip": "91302","latitude": "34.12794","UpdateDateTime": "8/18/2010 10:16:26 AM","channel": ["Running", "Walking"]}}]}',
|
26
|
+
:status => ["302", "Found"])
|
27
|
+
results = Search.search( {:location => "San Diego, CA, US"} )
|
28
|
+
results.should have(3).items
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
16
33
|
describe "Search URL Construction" do
|
17
34
|
|
18
35
|
it "should construct a valid url with location" do
|
@@ -42,7 +59,7 @@ describe "Search URL Construction" do
|
|
42
59
|
uri = URI.parse( Search.construct_url() )
|
43
60
|
uri.query.include?("f=#{Facet.ACTIVITIES}").should be_true
|
44
61
|
uri.query.include?("s=#{Sort.DATE_ASC}").should be_true
|
45
|
-
uri.query.include?("r=
|
62
|
+
uri.query.include?("r=50").should be_true
|
46
63
|
uri.query.include?("v=json").should be_true
|
47
64
|
uri.query.include?("page=1").should be_true
|
48
65
|
uri.query.include?("num=10").should be_true
|
@@ -141,8 +158,9 @@ describe Search do
|
|
141
158
|
end
|
142
159
|
|
143
160
|
describe "Call Live Data" do
|
161
|
+
|
144
162
|
it "should find only events in the future" do
|
145
|
-
results = Search.search( { :keywords => ["
|
163
|
+
results = Search.search( { :keywords => ["running"] } )
|
146
164
|
results.should have(10).items
|
147
165
|
results.each do |a|
|
148
166
|
a.start_date.should satisfy { |d|
|
@@ -189,7 +207,6 @@ describe "Call Live Data" do
|
|
189
207
|
results = Search.search( {:channels => [:yoga]} )
|
190
208
|
results.should have(10).items
|
191
209
|
end
|
192
|
-
|
193
210
|
|
194
211
|
it "should find activities that have been recently added"
|
195
212
|
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Active
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 6
|
9
|
+
version: 0.0.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Jonathan Spooner, Brian Levine
|
@@ -15,18 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-10 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: bones
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 25
|
30
27
|
segments:
|
31
28
|
- 3
|
32
29
|
- 4
|
@@ -44,6 +41,7 @@ extra_rdoc_files:
|
|
44
41
|
- History.txt
|
45
42
|
- README.txt
|
46
43
|
- bin/Active
|
44
|
+
- lib/.DS_Store
|
47
45
|
- version.txt
|
48
46
|
files:
|
49
47
|
- .bnsignore
|
@@ -52,6 +50,7 @@ files:
|
|
52
50
|
- README.txt
|
53
51
|
- Rakefile
|
54
52
|
- bin/Active
|
53
|
+
- lib/.DS_Store
|
55
54
|
- lib/Active.rb
|
56
55
|
- lib/services/activity.rb
|
57
56
|
- lib/services/search.rb
|
@@ -73,27 +72,23 @@ rdoc_options:
|
|
73
72
|
require_paths:
|
74
73
|
- lib
|
75
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
75
|
requirements:
|
78
76
|
- - ">="
|
79
77
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
78
|
segments:
|
82
79
|
- 0
|
83
80
|
version: "0"
|
84
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
82
|
requirements:
|
87
83
|
- - ">="
|
88
84
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
85
|
segments:
|
91
86
|
- 0
|
92
87
|
version: "0"
|
93
88
|
requirements: []
|
94
89
|
|
95
90
|
rubyforge_project: Active
|
96
|
-
rubygems_version: 1.3.
|
91
|
+
rubygems_version: 1.3.6
|
97
92
|
signing_key:
|
98
93
|
specification_version: 3
|
99
94
|
summary: Search api for Active Network
|