Active 0.0.42 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.irbrc +21 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/Active.gemspec +28 -29
- data/Gemfile +4 -0
- data/History.txt +5 -2
- data/{README.txt → README.md} +4 -20
- data/Rakefile +11 -17
- data/lib/Active.rb +11 -79
- data/lib/active/activity.rb +7 -0
- data/lib/active/article.rb +7 -0
- data/lib/active/asset.rb +205 -0
- data/lib/active/errors.rb +9 -0
- data/lib/active/query.rb +225 -0
- data/lib/active/result.rb +7 -0
- data/lib/active/results.rb +6 -0
- data/lib/active/training.rb +7 -0
- data/lib/active/version.rb +3 -0
- data/lib/ext/hash_extensions.rb +8 -0
- data/spec/asset_spec.rb +47 -0
- data/spec/search_spec.rb +383 -432
- data/spec/spec_helper.rb +23 -2
- metadata +113 -116
- data/bin/Active +0 -7
- data/lib/.DS_Store +0 -0
- data/lib/services/.DS_Store +0 -0
- data/lib/services/IActivity.rb +0 -39
- data/lib/services/_ats.rb +0 -215
- data/lib/services/active_works.rb +0 -167
- data/lib/services/activity.rb +0 -512
- data/lib/services/address.rb +0 -17
- data/lib/services/ats.rb +0 -229
- data/lib/services/dto/user.rb +0 -9
- data/lib/services/gsa.rb +0 -205
- data/lib/services/reg_center.rb +0 -270
- data/lib/services/sanitize.rb +0 -108
- data/lib/services/search.rb +0 -494
- data/lib/services/validators.rb +0 -124
- data/rspec-tm +0 -1
- data/rvmrc +0 -1
- data/spec/.DS_Store +0 -0
- data/spec/Active_spec.rb +0 -28
- data/spec/activeworks_spec.rb +0 -60
- data/spec/activity_spec.rb +0 -421
- data/spec/ats_spec.rb +0 -106
- data/spec/benchmark/search_bench.rb +0 -55
- data/spec/custom_matchers_spec.rb +0 -27
- data/spec/gsa_spec.rb +0 -210
- data/spec/reg_spec.rb +0 -173
- data/spec/search_memcached_spec.rb +0 -42
- data/spec/validators_spec.rb +0 -19
- data/test/test_Active.rb +0 -0
- data/version.txt +0 -1
data/lib/active/query.rb
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Active
|
5
|
+
class Query
|
6
|
+
|
7
|
+
attr_accessor :options
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
@options = {
|
11
|
+
:s => "relevance",
|
12
|
+
:f => options[:facet],
|
13
|
+
:meta => {},
|
14
|
+
:m => [],
|
15
|
+
:v => 'json'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def page(value=1)
|
20
|
+
raise Active::InvalidOption if value.to_i <= 0
|
21
|
+
@options[:page] = value
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def limit(value)
|
26
|
+
@options[:num] = value
|
27
|
+
self
|
28
|
+
end
|
29
|
+
alias per_page limit
|
30
|
+
|
31
|
+
# s = sort
|
32
|
+
# The default sort for results is by relevance. The available values are:
|
33
|
+
# date_asc
|
34
|
+
# date_desc
|
35
|
+
# relevance
|
36
|
+
def sort(value)
|
37
|
+
@options[:s] = value
|
38
|
+
self
|
39
|
+
end
|
40
|
+
alias order sort
|
41
|
+
|
42
|
+
# LatLngBounds(sw?:LatLng, ne?:LatLng)
|
43
|
+
# Constructs a rectangle from the points at its south-west and north-east corners.
|
44
|
+
def bounding_box(box)
|
45
|
+
latitude1 = box[:sw].split(",").first.to_f+90
|
46
|
+
latitude2 = box[:ne].split(",").first.to_f+90
|
47
|
+
longitude1 = box[:sw].split(",").last.to_f+180
|
48
|
+
longitude2 = box[:ne].split(",").last.to_f+180
|
49
|
+
options[:meta][:latitudeShifted] = "#{latitude1}..#{latitude2}"
|
50
|
+
options[:meta][:longitudeShifted] = "#{longitude1}..#{longitude2}"
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def near(value)
|
55
|
+
raise Active::InvalidOption unless value[:latitude] and value[:longitude] and value[:radius]
|
56
|
+
@options[:l] = "#{value[:latitude]},#{value[:longitude]}"
|
57
|
+
@options[:r] = value[:radius]
|
58
|
+
self
|
59
|
+
end
|
60
|
+
|
61
|
+
def location(value)
|
62
|
+
if value.kind_of?(Hash)
|
63
|
+
options[:meta].merge!(value)
|
64
|
+
elsif value.kind_of?(String)
|
65
|
+
@options[:l] = single_encode(value)
|
66
|
+
end
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def radius(value)
|
71
|
+
raise Active::InvalidOption unless value
|
72
|
+
@options[:r] = value.to_i
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def keywords(value)
|
77
|
+
if value.kind_of?(Array)
|
78
|
+
@options[:k] = value.join("+")
|
79
|
+
elsif value.kind_of?(String)
|
80
|
+
@options[:k] = single_encode(value)
|
81
|
+
end
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
def date_range(start_date,end_date)
|
86
|
+
if start_date.kind_of?(String)
|
87
|
+
start_date = Date.parse(start_date)
|
88
|
+
end
|
89
|
+
if end_date.kind_of?(String)
|
90
|
+
end_date = Date.parse(end_date)
|
91
|
+
end
|
92
|
+
start_date = URI.escape(start_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
|
93
|
+
end_date = URI.escape(end_date.strftime("%m/%d/%Y")).gsub(/\//,"%2F")
|
94
|
+
options[:meta][:startDate] = "daterange:#{start_date}..#{end_date}"
|
95
|
+
self
|
96
|
+
end
|
97
|
+
|
98
|
+
def future
|
99
|
+
options[:meta][:startDate] = "daterange:today..+"
|
100
|
+
self
|
101
|
+
end
|
102
|
+
|
103
|
+
def past
|
104
|
+
options[:meta][:startDate] = "daterange:..#{Date.today}"
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
def today
|
109
|
+
options[:meta][:startDate] = Date.today
|
110
|
+
self
|
111
|
+
end
|
112
|
+
|
113
|
+
[:state, :city, :category, :channel, :splitMediaType, :zip, :dma].each do |method_name|
|
114
|
+
define_method(method_name) do |val|
|
115
|
+
|
116
|
+
options[:meta][method_name] ||= []
|
117
|
+
if val.kind_of?(Array)
|
118
|
+
options[:meta][method_name] += val
|
119
|
+
elsif val.kind_of?(Hash)
|
120
|
+
options[:meta].merge!(val)
|
121
|
+
else
|
122
|
+
options[:meta][method_name] << val
|
123
|
+
end
|
124
|
+
self
|
125
|
+
end
|
126
|
+
end
|
127
|
+
alias zips zip
|
128
|
+
|
129
|
+
def to_query
|
130
|
+
opts = @options.deep_copy
|
131
|
+
|
132
|
+
# Extract :meta and turn it into a single string for :m
|
133
|
+
# Nested options inside meta get joined as OR
|
134
|
+
# Top-level options get joined with AND
|
135
|
+
opts[:m] += opts[:meta].collect { |k,v|
|
136
|
+
next unless v
|
137
|
+
if v.kind_of?(Array)
|
138
|
+
# Second-level options get joined with OR
|
139
|
+
v.collect do |v2|
|
140
|
+
# clean out empty values
|
141
|
+
if v2.nil?
|
142
|
+
next
|
143
|
+
elsif v2.kind_of?(String) and v2.empty?
|
144
|
+
next
|
145
|
+
elsif k == :assetId
|
146
|
+
"meta:#{k}=#{single_encode(v2)}"
|
147
|
+
else
|
148
|
+
"meta:#{k}=#{double_encode(v2)}"
|
149
|
+
end
|
150
|
+
end.join('+OR+')
|
151
|
+
else
|
152
|
+
# these keys need meta :
|
153
|
+
if k == :latitudeShifted or k == :longitudeShifted or k == :startDate
|
154
|
+
# encoding works for longitudeShifted
|
155
|
+
if k == :latitudeShifted or k == :longitudeShifted
|
156
|
+
double_encode("meta:#{k}:#{v}") # WTF encode the : ? and we don't have to encode it for assetId?
|
157
|
+
else
|
158
|
+
# encoding doesn't work for asset_id, daterange
|
159
|
+
"meta:#{k}:#{v}"
|
160
|
+
end
|
161
|
+
else# these keys need meta=
|
162
|
+
"meta:#{k}=#{double_encode(v)}"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
}
|
166
|
+
|
167
|
+
opts[:m] << double_encode("meta:startDate:daterange:01-01-2000..") if opts[:meta][:startDate].nil?
|
168
|
+
# clean out empty values
|
169
|
+
opts[:m] = opts[:m].compact.reject { |s| s.nil? or s.empty? }
|
170
|
+
opts[:m] = opts[:m].join('+AND+')
|
171
|
+
opts.delete(:meta)
|
172
|
+
opts.delete_if { |k, v| v.nil? || v.to_s.empty? } # Remove all blank keys
|
173
|
+
"http://search.active.com/search?" + opts.collect{|k,v| "#{k}=#{v}"}.join('&')
|
174
|
+
end
|
175
|
+
|
176
|
+
def search
|
177
|
+
searchurl = URI.parse(to_query)
|
178
|
+
http = Net::HTTP.new(searchurl.host, searchurl.port)
|
179
|
+
|
180
|
+
res = http.start do |http|
|
181
|
+
http.get("#{searchurl.path}?#{searchurl.query}")
|
182
|
+
end
|
183
|
+
|
184
|
+
if (200..307).include?(res.code.to_i)
|
185
|
+
# TODO HANDLE JSON PARSE ERROR
|
186
|
+
return JSON.parse(res.body)
|
187
|
+
else
|
188
|
+
raise Active::ActiveError, "Active Search responded to your query with code: #{res.code}"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def results
|
193
|
+
return @a if @a
|
194
|
+
@res ||= search
|
195
|
+
@a ||= Active::Results.new()
|
196
|
+
# GSA will only return 1000 events but will give us a number larger then 1000.
|
197
|
+
@a.number_of_results = (@res['numberOfResults'] <= 1000) ? @res['numberOfResults'] : 1000
|
198
|
+
@a.end_index = @res['endIndex']
|
199
|
+
@a.page_size = @res['pageSize']
|
200
|
+
@a.search_time = @res['searchTime']
|
201
|
+
|
202
|
+
@res['_results'].collect do |d|
|
203
|
+
@a << Active::Asset.factory(d)
|
204
|
+
end
|
205
|
+
@a
|
206
|
+
end
|
207
|
+
|
208
|
+
private
|
209
|
+
# good for assetId only.. maybe
|
210
|
+
def single_encode(str)
|
211
|
+
str = URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
212
|
+
str.gsub!(/\-/,"%252D")
|
213
|
+
str
|
214
|
+
end
|
215
|
+
# good for all other values like city and state
|
216
|
+
def double_encode(str)
|
217
|
+
str = str.to_s
|
218
|
+
str = URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
219
|
+
str = URI.escape(str, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
220
|
+
str.gsub!(/\-/,"%252D")
|
221
|
+
str
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
end
|
data/spec/asset_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
2
|
+
describe "Search" do
|
3
|
+
describe "Asset Accessors" do
|
4
|
+
|
5
|
+
describe "invalid UTF-8 byte sequences" do
|
6
|
+
# TODO: Test pipe separately from UTF-8
|
7
|
+
it "should gracefully handle invalid UTF-8 byte sequences in the title" do
|
8
|
+
asset = Active::Asset.new()
|
9
|
+
asset['title'] = "one | \xB7 two"
|
10
|
+
asset.title.should eql("one")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "HTML and special character sanitizing" do
|
15
|
+
it "should convert HTML special characters in the title" do
|
16
|
+
asset = Active::Asset.new()
|
17
|
+
asset['title'] = "one & two"
|
18
|
+
asset.title.should eql("one & two")
|
19
|
+
end
|
20
|
+
it "should remove HTML tags from the title" do
|
21
|
+
asset = Active::Asset.new()
|
22
|
+
asset['title'] = "one <b>two</b>"
|
23
|
+
asset.title.should eql("one two")
|
24
|
+
end
|
25
|
+
it "should remove HTML tags from the description" do
|
26
|
+
asset = Active::Asset.new({"meta" => { "summary"=>"one <b>two</b>" }})
|
27
|
+
asset.description.should eql("one two")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Address and Location" do
|
32
|
+
it "should return an address if one exists in meta" do
|
33
|
+
asset = Active::Asset.new({"meta" => { "address"=>"123 Main St" }})
|
34
|
+
asset.address.should eql("123 Main St")
|
35
|
+
end
|
36
|
+
it "should return location if no address is present" do
|
37
|
+
asset = Active::Asset.new({"meta" => { "location"=>"123 Main St" }})
|
38
|
+
asset.address.should eql("123 Main St")
|
39
|
+
end
|
40
|
+
it "should return city, state if no location or address" do
|
41
|
+
asset = Active::Asset.new({"meta" => { "city"=>"Brooklyn", "state"=>"New York" }})
|
42
|
+
asset.address.should eql("Brooklyn, New York")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/spec/search_spec.rb
CHANGED
@@ -1,465 +1,416 @@
|
|
1
|
-
require 'fake_web'
|
2
|
-
# Require the spec helper relative to this file
|
3
1
|
require File.join(File.dirname(__FILE__), %w[spec_helper])
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
include Active::Services
|
8
|
-
# Active.memcache_host "localhost:11211"
|
2
|
+
describe "Search" do
|
3
|
+
describe "Asset" do
|
4
|
+
# describe HTTP and JSON Parse Errors
|
9
5
|
|
10
|
-
describe
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
it "should search by city" do
|
20
|
-
uri = URI.parse( Search.new({:city=>"Oceanside"}).end_point )
|
21
|
-
uri.query.should have_param("meta:city=Oceanside")
|
22
|
-
uri.query.should_not have_param("l=")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should double encode the city" do
|
26
|
-
uri = URI.parse( Search.new({:city=>"San Marcos"}).end_point )
|
27
|
-
uri.query.should have_param("meta:city=San%2520Marcos")
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should pass California as the meta state" do
|
31
|
-
uri = URI.parse( Search.new({:state=>"California"}).end_point )
|
32
|
-
uri.query.should have_param("meta:state=California")
|
33
|
-
uri.query.should_not have_param("l=")
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should search by the SF DMA" do
|
37
|
-
uri = URI.parse( Search.new({:dma=>"San Francisco - Oakland - San Jose"}).end_point )
|
38
|
-
uri.query.should have_param("meta:dma=San%2520Francisco%2520%252D%2520Oakland%2520%252D%2520San%2520Jose")
|
39
|
-
uri.query.should_not have_param("l=")
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should place lat and lng in the l param" do
|
43
|
-
location = {:latitude=>"37.785895", :longitude=>"-122.40638"}
|
44
|
-
uri = URI.parse( Search.new(location).end_point )
|
45
|
-
uri.query.should have_param("l=37.785895;-122.40638")
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should escape the location" do
|
49
|
-
s = Search.new()
|
50
|
-
s.location.should be_nil
|
51
|
-
s = Search.new({:location => "San Diego"})
|
52
|
-
s.location.should eql("San+Diego")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should have an array of keywords" do
|
56
|
-
s = Search.new()
|
57
|
-
s.should have(0).keywords
|
58
|
-
s = Search.new({:keywords => "Dog,Cat,Cow"})
|
59
|
-
s.should have(3).keywords
|
60
|
-
s = Search.new({:keywords => %w(Dog Cat Cow)})
|
61
|
-
s.should have(3).keywords
|
62
|
-
s = Search.new({:keywords => ["Dog","Cat","Cow"]})
|
63
|
-
s.should have(3).keywords
|
6
|
+
describe "pagination" do
|
7
|
+
it "should show the number of results" do
|
8
|
+
asset = Active::Asset.location(:city=>"Oceanside")
|
9
|
+
results = asset.results
|
10
|
+
results.number_of_results.should_not be_nil
|
11
|
+
results.end_index.should_not be_nil
|
12
|
+
results.page_size.should_not be_nil
|
13
|
+
results.search_time.should_not be_nil
|
14
|
+
end
|
64
15
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
16
|
+
|
17
|
+
describe "Instance Methods - Query Builder - Default Options" do
|
18
|
+
it "should build a query" do
|
19
|
+
asset = Active::Query.new
|
20
|
+
asset.to_query.should have_param("http://search.active.com/search?")
|
21
|
+
end
|
22
|
+
it "should have a facet in the query" do
|
23
|
+
asset = Active::Query.new(:facet => 'activities')
|
24
|
+
asset.to_query.should have_param("f=activities")
|
25
|
+
end
|
72
26
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
uri.query.should have_param("daterange:today..+")
|
89
|
-
uri.query.should_not have_param("assetId=")
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should construct a valid url with location" do
|
93
|
-
s = Search.new( {:location => "San Diego, CA, US"} )
|
94
|
-
uri = URI.parse(s.end_point)
|
95
|
-
uri.scheme.should eql("http")
|
96
|
-
uri.host.should eql("search.active.com")
|
97
|
-
uri.query.should have_param("l=#{CGI.escape("San Diego, CA, US")}")
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should send an array of zips" do
|
101
|
-
uri = URI.parse( Search.new( {:zips => "92121, 92078, 92114"} ).end_point )
|
102
|
-
uri.query.should have_param("l=92121,92078,92114")
|
103
|
-
uri = URI.parse( Search.new( {:zips => [92121, 92078, 92114]} ).end_point )
|
104
|
-
uri.query.should have_param("l=92121,92078,92114")
|
105
|
-
end
|
106
|
-
|
107
|
-
# it "should construct a valid url from a zip code" do
|
108
|
-
# s = Search.new( {:zip => "92121"} )
|
109
|
-
# uri = URI.parse(s.end_point)
|
110
|
-
# uri.query.should have_param("l=#{CGI.escape("92121")}")
|
111
|
-
# end
|
112
|
-
|
113
|
-
it "should construct a valid url with CSV keywords" do
|
114
|
-
s = Search.new( {:keywords => "running, tri"} )
|
115
|
-
uri = URI.parse( s.end_point )
|
116
|
-
uri.query.should have_param("k=running+tri")
|
117
|
-
s = Search.new( {:keywords => ["running","tri","cycling"]} )
|
118
|
-
uri = URI.parse( s.end_point )
|
119
|
-
uri.query.should have_param("k=running+tri+cycling")
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should construct a valid url with channels array" do
|
123
|
-
s = Search.new( {:channels => [:running, :tri,:cycling, :yoga]} )
|
124
|
-
uri = URI.parse( s.end_point )
|
125
|
-
uri.query.should have_param("m=meta:channel=Running+OR+meta:channel=Cycling+OR+meta:channel=Mind%2520%2526%2520Body%255CYoga")
|
126
|
-
end
|
27
|
+
it "should specify sort and return itself" do
|
28
|
+
asset = Active::Asset.sort(:date_desc)
|
29
|
+
asset.should be_an_instance_of(Active::Query)
|
30
|
+
asset.to_query.should have_param("s=date_desc")
|
31
|
+
asset.sort(:relevance).should === asset
|
32
|
+
asset.to_query.should have_param("s=relevance")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should specify order and return itself" do
|
36
|
+
asset = Active::Asset.order(:date_asc)
|
37
|
+
asset.should be_an_instance_of(Active::Query)
|
38
|
+
asset.to_query.should have_param("s=date_asc")
|
39
|
+
asset.order(:relevance).should === asset
|
40
|
+
asset.to_query.should have_param("s=relevance")
|
41
|
+
end
|
127
42
|
|
128
|
-
|
129
|
-
|
130
|
-
|
43
|
+
it "should specify limit and return itself" do
|
44
|
+
asset = Active::Asset.limit(5)
|
45
|
+
asset.should be_an_instance_of(Active::Query)
|
46
|
+
asset.to_query.should have_param("num=5")
|
47
|
+
asset.limit(16).should === asset
|
48
|
+
asset.to_query.should have_param("num=16")
|
49
|
+
# alias per_page to limit
|
50
|
+
asset.per_page(3).should === asset
|
51
|
+
asset.to_query.should have_param("num=3")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should specify a per_page and return itself" do
|
55
|
+
asset = Active::Asset.per_page(3)
|
56
|
+
asset.should be_an_instance_of(Active::Query)
|
57
|
+
asset.to_query.should have_param("num=3")
|
58
|
+
end
|
59
|
+
it "should raise an invalid option error" do
|
60
|
+
lambda { Active::Asset.page(0) }.should raise_error(Active::InvalidOption)
|
61
|
+
lambda { Active::Asset.page(-1) }.should raise_error(Active::InvalidOption)
|
62
|
+
end
|
63
|
+
it "should specify page and return itself" do
|
64
|
+
asset = Active::Asset.page()
|
65
|
+
asset.should be_an_instance_of(Active::Query)
|
66
|
+
asset.to_query.should have_param("page=1")
|
67
|
+
asset.page(5).should === asset
|
68
|
+
asset.to_query.should have_param("page=5")
|
69
|
+
end
|
70
|
+
it "does something" do
|
71
|
+
asset = Active::Asset.page(2).limit(5).sort(:date_asc)
|
72
|
+
asset.to_query.should have_param("page=2")
|
73
|
+
asset.to_query.should have_param("s=date_asc")
|
74
|
+
asset.to_query.should have_param("num=5")
|
75
|
+
end
|
131
76
|
end
|
77
|
+
|
78
|
+
describe "Instance Methods - Query Builder - Location" do
|
79
|
+
it "should search by city" do
|
80
|
+
asset = Active::Asset.location(:city=>"Oceanside")
|
81
|
+
asset.to_query.should have_param("meta:city=Oceanside")
|
82
|
+
end
|
83
|
+
it "should double encode the city" do
|
84
|
+
asset = Active::Asset.city("San Marcos")
|
85
|
+
asset.to_query.should have_param("meta:city=San%2520Marcos")
|
86
|
+
|
87
|
+
asset = Active::Asset.location(:city=>"San Marcos")
|
88
|
+
asset.to_query.should have_param("meta:city=San%2520Marcos")
|
89
|
+
|
90
|
+
end
|
91
|
+
it "should pass California as the meta state" do
|
92
|
+
asset = Active::Asset.state("California")
|
93
|
+
asset.to_query.should have_param("meta:state=California")
|
132
94
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
95
|
+
asset = Active::Asset.state(["California", "Oregon"])
|
96
|
+
asset.to_query.should have_param("meta:state=California+OR+meta:state=Oregon")
|
97
|
+
|
98
|
+
asset = Active::Asset.location(:state=>"California")
|
99
|
+
asset.to_query.should have_param("meta:state=California")
|
100
|
+
end
|
101
|
+
it "should search by the SF DMA" do
|
102
|
+
asset = Active::Asset.dma("San Francisco - Oakland - San Jose")
|
103
|
+
asset.to_query.should have_param("meta:dma=San%2520Francisco%2520%252D%2520Oakland%2520%252D%2520San%2520Jose")
|
104
|
+
end
|
105
|
+
it "should place lat and lng in the l param" do
|
106
|
+
asset = Active::Asset.near({:latitude=>"37.785895", :longitude=>"-122.40638", :radius => 25})
|
107
|
+
asset.to_query.should have_param("l=37.785895,-122.40638")
|
108
|
+
asset.to_query.should have_param("r=25")
|
109
|
+
end
|
110
|
+
it "should find by zip" do
|
111
|
+
asset = Active::Activity.zip("92121")
|
112
|
+
asset.to_query.should have_param("zip=92121")
|
113
|
+
asset.results.each do |result|
|
114
|
+
result.zip.should == "92121"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
it "should find many zips" do
|
118
|
+
asset = Active::Activity.zips([92121, 92114])
|
119
|
+
asset.to_query.should have_param("meta:zip=92121+OR+meta:zip=92114")
|
120
|
+
asset.results.each do |result|
|
121
|
+
result.zip.should satisfy do |zip|
|
122
|
+
true if zip == "92121" or zip == "92114"
|
123
|
+
end
|
124
|
+
end
|
143
125
|
|
144
|
-
it "should send the correct channel value for everything in Search.CHANNELS" do
|
145
|
-
Categories.CHANNELS.each do |key,value|
|
146
|
-
uri = URI.parse( Search.new({:channels => [key]}).end_point )
|
147
|
-
value = URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
148
|
-
value = URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
149
|
-
value.gsub!(/\-/,"%252D")
|
150
|
-
uri.query.should have_param("meta:channel=#{value}")
|
151
126
|
end
|
127
|
+
it "should construct a valid url with location" do
|
128
|
+
asset = Active::Asset.location("San Diego, CA, US")
|
129
|
+
asset.to_query.should have_param("l=San%20Diego%2C%20CA%2C%20US")
|
130
|
+
end
|
131
|
+
it "should construct a valid url with radius" do
|
132
|
+
asset = Active::Asset.radius(50)
|
133
|
+
asset.to_query.should have_param("r=50")
|
134
|
+
end
|
135
|
+
it "should send bounding_box" do
|
136
|
+
pending
|
137
|
+
asset = Active::Activity.bounding_box({ :sw => "33.007407,-117.332985", :ne => "33.179984,-117.003395"} )
|
138
|
+
asset.to_query.should have_param("meta%253AlongitudeShifted%253A62.667015..62.996605")
|
139
|
+
asset.to_query.should have_param("meta%253AlatitudeShifted%253A123.007407..123.179984")
|
140
|
+
# asset.results.each do |result|
|
141
|
+
# puts "#{result.meta.latitude}, #{result.meta.longitude}<br/>"
|
142
|
+
# # result.meta.latitude.should satisfy do |lat|
|
143
|
+
# # puts "<br/> latitude #{lat}"
|
144
|
+
# # lat.to_f >= 33.007407 and lat.to_f <= 33.179984
|
145
|
+
# # end
|
146
|
+
# result.meta.longitude.should satisfy do |lng|
|
147
|
+
# puts "<br/> longitude #{lng.to_f}"
|
148
|
+
# lng.to_f <= -117.003395# and lng.to_f <= -117.332985
|
149
|
+
# end
|
150
|
+
# end
|
151
|
+
end
|
152
|
+
it "should send bounding_box" do
|
153
|
+
pending
|
154
|
+
asset = Active::Activity.bounding_box({:ne=>"38.8643,-121.208199", :sw=>"36.893089,-123.533684"})
|
155
|
+
#puts asset.to_query
|
156
|
+
asset.to_query.should have_param("meta%253AlatitudeShifted%253A126.893089..128.8643")
|
157
|
+
asset.to_query.should have_param("meta%253AlongitudeShifted%253A56.466316..58.791801")
|
158
|
+
# asset.results.each do |result|
|
159
|
+
# puts "#{result.meta.latitude}, #{result.meta.longitude}<br/>"
|
160
|
+
# # result.meta.latitude.should satisfy do |lat|
|
161
|
+
# # puts "<br/> latitude #{lat}"
|
162
|
+
# # lat.to_f >= 33.007407 and lat.to_f <= 33.179984
|
163
|
+
# # end
|
164
|
+
# result.meta.longitude.should satisfy do |lng|
|
165
|
+
# puts "<br/> longitude #{lng.to_f}"
|
166
|
+
# # lng.to_f <= -117.003395# and lng.to_f <= -117.332985
|
167
|
+
# end
|
168
|
+
# end
|
169
|
+
end
|
170
|
+
|
152
171
|
end
|
153
172
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
173
|
+
describe "Instance Methods - Query Builder - Meta" do
|
174
|
+
it "should search keywords" do
|
175
|
+
asset = Active::Asset.keywords('Running')
|
176
|
+
asset.to_query.should have_param("k=Running")
|
177
|
+
asset = Active::Asset.keywords(['Running', 'Hiking'])
|
178
|
+
asset.to_query.should have_param("k=Running+Hiking")
|
179
|
+
end
|
180
|
+
it "should search channels" do
|
181
|
+
asset = Active::Asset.channel('Running')
|
182
|
+
asset.to_query.should have_param("meta:channel=Running")
|
183
|
+
end
|
184
|
+
it "should search splitMediaType" do
|
185
|
+
asset = Active::Asset.splitMediaType('5k')
|
186
|
+
asset.to_query.should have_param("meta:splitMediaType=5k")
|
187
|
+
# open_url(asset.to_query)
|
188
|
+
end
|
162
189
|
end
|
163
190
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
191
|
+
describe "Instance Methods - Query Builder - Dates" do
|
192
|
+
it "should send a valid start and end date" do
|
193
|
+
sd = Date.new(2011, 11, 1)
|
194
|
+
ed = Date.new(2011, 11, 3)
|
195
|
+
asset = Active::Asset.date_range( sd, ed )
|
196
|
+
asset.should be_an_instance_of(Active::Query)
|
197
|
+
asset.to_query.should have_param("meta:startDate:daterange:11%2F01%2F2011..11%2F03%2F2011")
|
198
|
+
asset.results.size.should eq(10)
|
199
|
+
asset.results.each do |result|
|
200
|
+
result.meta.startDate.should satisfy { |date|
|
201
|
+
d = Date.parse(date)
|
202
|
+
d >= sd and d <= ed
|
203
|
+
}
|
204
|
+
end
|
205
|
+
end
|
206
|
+
it "should send a valid start and end date" do
|
207
|
+
asset = Active::Asset.date_range( "2011-11-1", "2011-11-3" )
|
208
|
+
asset.should be_an_instance_of(Active::Query)
|
209
|
+
asset.to_query.should have_param("meta:startDate:daterange:11%2F01%2F2011..11%2F03%2F2011")
|
210
|
+
asset.results.size.should eq(10)
|
211
|
+
asset.results.each do |result|
|
212
|
+
result.meta.startDate.should satisfy { |date|
|
213
|
+
d = Date.parse(date)
|
214
|
+
d >= Date.parse("2011-11-1") and d <= Date.parse("2011-11-3")
|
215
|
+
}
|
216
|
+
end
|
217
|
+
end
|
218
|
+
it "should send a valid start and end date" do
|
219
|
+
asset = Active::Asset.date_range( "1/11/2011", "3/11/2011" )
|
220
|
+
asset.should be_an_instance_of(Active::Query)
|
221
|
+
asset.to_query.should have_param("meta:startDate:daterange:11%2F01%2F2011..11%2F03%2F2011")
|
222
|
+
asset.results.size.should eq(10)
|
223
|
+
asset.results.each do |result|
|
224
|
+
result.meta.startDate.should satisfy { |date|
|
225
|
+
d = Date.parse(date)
|
226
|
+
d >= Date.parse("2011-11-1") and d <= Date.parse("2011-11-3")
|
227
|
+
}
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
it "should search past" do
|
234
|
+
asset = Active::Asset.past
|
235
|
+
asset.should be_an_instance_of(Active::Query)
|
236
|
+
asset.to_query.should have_param("meta:startDate:daterange:..#{Date.today}")
|
237
|
+
asset.results.each do |result|
|
238
|
+
result.meta.startDate.should satisfy { |date|
|
239
|
+
Date.parse(date) <= Date.today
|
240
|
+
}
|
241
|
+
end
|
242
|
+
end
|
243
|
+
it "should search future" do
|
244
|
+
asset = Active::Asset.future
|
245
|
+
asset.should be_an_instance_of(Active::Query)
|
246
|
+
asset.to_query.should have_param("daterange:today..+")
|
247
|
+
asset.results.each do |result|
|
248
|
+
result.meta.startDate.should satisfy { |date|
|
249
|
+
Date.parse(date) >= Date.today
|
250
|
+
}
|
251
|
+
end
|
252
|
+
end
|
253
|
+
it "should search today" do
|
254
|
+
asset = Active::Asset.today
|
255
|
+
asset.should be_an_instance_of(Active::Query)
|
256
|
+
asset.to_query.should have_param("meta:startDate:#{Date.today}")
|
257
|
+
asset.results.each do |result|
|
258
|
+
result.meta.startDate.should satisfy { |date|
|
259
|
+
Date.parse(date) == Date.today
|
260
|
+
}
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
169
264
|
end
|
170
265
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
:start_date => Date.new(2010, 11, 1),
|
191
|
-
:end_date => Date.new(2010, 11, 15)}).end_point )
|
192
|
-
uri.query.should have_param("meta:channel=Running+OR+meta:channel=Triathlon")
|
193
|
-
uri.query.should have_param("daterange:11%2F01%2F2010..11%2F15%2F2010")
|
266
|
+
describe "Instance Methods - Catching empty and nill values" do
|
267
|
+
it "should not pass empty values" do
|
268
|
+
asset = Active::Activity.page(1).limit(10)
|
269
|
+
asset.keywords("")
|
270
|
+
asset.state("")
|
271
|
+
asset.channel("Running")
|
272
|
+
asset.to_query.should_not have_param("meta:state=")
|
273
|
+
asset.to_query.should_not have_param("k=")
|
274
|
+
asset.to_query.should have_param("meta:channel=Running")
|
275
|
+
asset.to_query.should_not have_param("+OR++OR+")
|
276
|
+
asset.to_query.should_not have_param("+AND++AND+")
|
277
|
+
end
|
278
|
+
it "should not pass nil values" do
|
279
|
+
asset = Active::Activity.page(1).limit(10)
|
280
|
+
asset.keywords("")
|
281
|
+
asset.state(nil)
|
282
|
+
asset.channel("Running")
|
283
|
+
asset.to_query.should_not have_param("meta:state=")
|
284
|
+
end
|
194
285
|
end
|
195
286
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should decode this JSON" do
|
227
|
-
# if the location is not in the correct format there is a json error.
|
228
|
-
# s = Active::Services::Search.search({:location => "belvedere-tiburon-ca"})
|
229
|
-
# /search?api_key=&num=10&page=1&l=belvedere-tiburon-ca&f=activities&v=json&r=50&s=date_asc&k=&m=meta:startDate:daterange:today..+
|
230
|
-
# I think the JSON spec says that only arrays or objects can be at the top level.
|
231
|
-
# JSON::ParserError: A JSON text must at least contain two octets!
|
232
|
-
pending
|
233
|
-
end
|
234
|
-
|
235
|
-
it "should find 5 items when doing a DMA search" do
|
236
|
-
Search.new({:dma=>"San Francisco - Oakland - San Jose", :num_results => 5}).num_results.should eql(5)
|
237
|
-
Search.search({:dma=>"San Francisco - Oakland - San Jose", :num_results => 5}).should have(5).results
|
238
|
-
Search.search({:dma=>"San Francisco - Oakland - San Jose", :num_results => 2}).should have(2).results
|
287
|
+
describe "Static Find Methods" do
|
288
|
+
it "should raise error if no id is specified" do
|
289
|
+
lambda { Active::Asset.find() }.should raise_error(Active::InvalidOption, "Couldn't find Asset without an ID")
|
290
|
+
end
|
291
|
+
it "should find record: Dean Karnazes Silicon Valley Marathon" do
|
292
|
+
result = Active::Asset.find("DD8F427F-6188-465B-8C26-71BBA22D2DB7")
|
293
|
+
result.should be_an_instance_of(Active::Asset)
|
294
|
+
result.asset_id.should eql("DD8F427F-6188-465B-8C26-71BBA22D2DB7")
|
295
|
+
end
|
296
|
+
it "should have two asset_id's in the query" do
|
297
|
+
results = Active::Asset.find(["DD8F427F-6188-465B-8C26-71BBA22D2DB7", "2C384907-D683-4E83-BD97-63A46F38437A"])
|
298
|
+
results.should be_an_instance_of(Array)
|
299
|
+
end
|
300
|
+
it "should throw an error if one or more asset_ids weren't found" do
|
301
|
+
lambda { Active::Asset.find(["DD8F427F-6188-465B-8C26-71BBA22D2DB7", "123"])
|
302
|
+
}.should raise_error(Active::RecordNotFound, "Couldn't find record with asset_id: 123")
|
303
|
+
end
|
304
|
+
it "should find a record by url" do
|
305
|
+
# event = Active::Activity.find_by_url("http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011")
|
306
|
+
event = Active::Activity.find_by_url("www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011")
|
307
|
+
event.title.should eql("2011 Rohto Ironman 70.3 California")
|
308
|
+
end
|
309
|
+
describe "Result Object" do
|
310
|
+
it "should have a title via dot notation" do
|
311
|
+
result = Active::Asset.find("DD8F427F-6188-465B-8C26-71BBA22D2DB7")
|
312
|
+
result.title.should eql("Dean Karnazes Silicon Valley Marathon")
|
313
|
+
end
|
314
|
+
end
|
239
315
|
end
|
240
|
-
end
|
241
316
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
:status => ["302", "Found"])
|
253
|
-
s = Search.search( {:location => "San Diego, CA, US"} )
|
254
|
-
s.should have(3).results
|
255
|
-
end
|
256
|
-
|
257
|
-
end
|
258
|
-
describe "Calls with FakeWeb" do
|
259
|
-
after(:each) do
|
260
|
-
FakeWeb.clean_registry
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should have some channels" do
|
264
|
-
Categories.CHANNELS.should_not be_nil
|
265
|
-
end
|
266
|
-
|
267
|
-
it "should describe pagination info on search object" do
|
268
|
-
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&s=date_asc&m=meta:startDate:daterange:today..+",
|
269
|
-
:body => '{"endIndex":3,"numberOfResults":3,"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"]}},
|
270
|
-
{"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"}},
|
271
|
-
{"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"]}}]}',
|
272
|
-
:status => ["200", "Found"])
|
273
|
-
s = Search.search( {:location => "San Diego, CA, US"} )
|
274
|
-
s.should be_a_kind_of(Search)
|
275
|
-
s.should have(3).results
|
276
|
-
s.endIndex.should == 3
|
277
|
-
s.numberOfResults.should == 3
|
278
|
-
s.pageSize.should == 5
|
279
|
-
s.searchTime.should == 0.600205
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should raise and error during a 404" do
|
284
|
-
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&s=date_asc&m=meta:startDate:daterange:today..+",
|
285
|
-
:body => "Nothing to be found 'round here", :status => ["404", "Not Found"])
|
286
|
-
lambda { Search.search( {:location => "San Diego, CA, US"} ) }.should raise_error(RuntimeError)
|
287
|
-
end
|
288
|
-
|
289
|
-
it "should search by location (san diego)" do
|
290
|
-
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&s=date_asc&m=meta:startDate:daterange:today..+",
|
291
|
-
:body => '{"endIndex":3,"numberOfResults":3,"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"]}},
|
292
|
-
{"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"}},
|
293
|
-
{"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"]}}]}',
|
294
|
-
:status => ["200", "Found"])
|
295
|
-
s = Search.search( {:location => "San Diego, CA, US"} )
|
296
|
-
s.should be_a_kind_of(Search)
|
297
|
-
s.should have(3).results
|
298
|
-
s.results.each do |a|
|
299
|
-
a.should be_an_instance_of(Activity)
|
300
|
-
a.title.should_not be_nil
|
301
|
-
# a.start_date.should_not be_nil
|
302
|
-
# a.end_date.should_not be_nil
|
303
|
-
# a.categories.should_not be_nil
|
304
|
-
# a.desc.should_not be_nil
|
305
|
-
# a.start_time.should_not be_nil
|
306
|
-
# a.end_time.should_not be_nil
|
307
|
-
# a.address.should_not be_nil
|
308
|
-
# a.address[:name].should_not be_nil
|
309
|
-
# a.address[:city].should_not be_nil
|
310
|
-
# a.address[:state].should_not be_nil
|
311
|
-
# a.address[:zip].should_not be_nil
|
312
|
-
# a.address[:country].should_not be_nil
|
313
|
-
# a.address[:lat].should_not be_nil
|
314
|
-
# a.address[:lng].should_not be_nil
|
317
|
+
describe "Results Object" do
|
318
|
+
it "should find only 4 results" do
|
319
|
+
asset = Active::Asset.order(:relevance)
|
320
|
+
asset.page(1)
|
321
|
+
asset.limit(4)
|
322
|
+
asset.order(:date_asc)
|
323
|
+
asset.should have_exactly(4).results
|
324
|
+
asset.results.first.should be_an_instance_of(Active::Activity)
|
325
|
+
asset.results.first.url.should_not be_nil
|
326
|
+
asset.results.first.meta.eventId.should_not be_nil
|
315
327
|
end
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
# :body => '{"endIndex":10,"numberOfResults":2790,"pageSize":10,"searchTime":0.253913,"_results":[{"escapedUrl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","language":"en","title":"Myrtle Beach Mini Marathon | Myrtle Beach, South Carolina \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","summary":"","meta":{"eventDate":"2010-10-24T07:00:00-07:00","location":"Myrtle Beach, South Carolina","tag":["event:10","Running:10"],"endDate":"2010-10-24","eventLongitude":"-78.92921","splitMediaType":["Event","5K","Half Marathon","Marathon","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"lastModifiedDateTime":"2010-09-13 18:15:04.753","locationName":"Myrtle Beach, South Carolina","endTime":"7:00:00","google-site-verification":"","city":"Myrtle Beach","startTime":"7:00:00","eventId":"1797753","description":"","longitude":"-78.92921","substitutionUrl":"1797753","eventLatitude":"33.75043","eventState":"South Carolina","sortDate":"2000-10-24","keywords":"Event","eventAddress":"Medieval Times","dma":"Florence - Myrtle Beach","seourl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","country":"United States","category":"Activities","market":"Florence - Myrtle Beach","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Robert Pozo","eventZip":"29579","latitude":"33.75043","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-24","state":"South Carolina","mediaType":["Event","Event\\5K","Event\\Half Marathon","Event\\Marathon","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"estParticipants":"6000","assetId":["008540A9-C2AB-4D7F-BE68-298758B324CD","008540a9-c2ab-4d7f-be68-298758b324cd"],"participationCriteria":"Adult,Men,Women","onlineDonationAvailable":"1","assetName":["Myrtle Beach Mini Marathon","Myrtle Beach Mini Marathon"],"eventURL":"http://runmyrtlebeach.com","zip":"29579","contactPhone":"1-800-733-7089","contactEmail":"info@runmyrtlebeach.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-13","channel":"Running"}},{"escapedUrl":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-2010","language":"en","title":"Fans on the Field 2010 - Denver Stadium 5K/10K | Denver \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-2010","summary":"","meta":{"startDate":"2010-10-10","eventDate":"2010-10-10T00:00:00-07:00","location":"INVESCO Field at Mile High","tag":["event:10","Running:10"],"state":"Colorado","eventLongitude":"-105.0265","endDate":"2010-10-10","lastModifiedDateTime":"2010-08-05 16:15:18.14","splitMediaType":["Event","10K","5K"],"locationName":"INVESCO Field at Mile High","endTime":"0:00:00","mediaType":["Event","Event\\10K","Event\\5K"],"city":"Denver","google-site-verification":"","startTime":"0:00:00","assetId":["4850BB73-3701-493D-936C-C38CC0B3FD4C","4850bb73-3701-493d-936c-c38cc0b3fd4c"],"eventId":"1869635","participationCriteria":"All","description":"","longitude":"-105.0265","onlineDonationAvailable":"false","substitutionUrl":"1869635","assetName":["Fans on the Field 2010 - Denver Stadium 5K/10K","Fans on the Field 2010 - Denver Stadium 5K/10K"],"zip":"80204","contactPhone":"303-293-5315","eventLatitude":"39.73804","eventState":"Colorado","sortDate":"2000-10-10","keywords":"Event","eventAddress":"1801 Bryant Street","contactEmail":"ahinkle@nscd.org","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-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-08-05","eventZip":"80204","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"39.73804","channel":["Running","Walking"]}},{"escapedUrl":"http://www.active.com/triathlon/sedalia-mo/sedalia-duathlon-2010","language":"en","title":"Sedalia Duathlon | Sedalia, Missouri 65301 | Sunday \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/sedalia-mo/sedalia-duathlon-2010","summary":"","meta":{"startDate":"2010-09-26","eventDate":"2010-09-26T08:00:00-07:00","location":"Centennial Park/Parview School","state":"Missouri","endDate":"2010-09-26","eventLongitude":"-93.22826","lastModifiedDateTime":"2010-07-29 17:15:03.313","splitMediaType":["Event","Sprint"],"locationName":"Centennial Park/Parview School","endTime":"8:00:00","mediaType":["Event","Event\\Sprint"],"city":"Sedalia","google-site-verification":"","startTime":"8:00:00","assetId":["F11300A4-0A56-4321-AD4C-17502CEE8503","f11300a4-0a56-4321-ad4c-17502cee8503"],"eventId":"1879447","participationCriteria":"All","description":"","longitude":"-93.22826","onlineDonationAvailable":"false","substitutionUrl":"1879447","assetName":["Sedalia Duathlon","Sedalia Duathlon"],"zip":"65301","contactPhone":"660-827-6809","eventLatitude":"38.70446","eventState":"Missouri","sortDate":"2000-09-26","keywords":"Event","eventAddress":"1901 S. New York","contactEmail":"jamm@iland.net","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/sedalia-mo/sedalia-duathlon-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-07-29","eventZip":"65301","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"38.70446","channel":["More Sports\\Duathlon","Triathlon"]}},{"escapedUrl":"http://www.active.com/triathlon/tempe-az/pbr-urban-dirt-duathlon-2010","language":"en","title":"PBR Urban Dirt Duathlon | Tempe, Arizona 85281 | Sunday \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/tempe-az/pbr-urban-dirt-duathlon-2010","summary":"","meta":{"eventDate":"2010-10-10T07:30:00-07:00","location":"North side of Tempe Town Lake near sand Volleyball courts, east of Mill Ave. Race thru Papago!","tag":["event:10","Triathlon:10"],"endDate":"2010-10-10","eventLongitude":"-111.9305","splitMediaType":["Event","Off-Road","Sprint","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"lastModifiedDateTime":"2010-09-08 15:15:42.507","locationName":"North side of Tempe Town Lake near sand Volleyball courts, east of Mill Ave. Race thru Papago!","endTime":"7:30:00","google-site-verification":"","city":"Tempe","startTime":"7:30:00","eventId":"1814945","description":"","longitude":"-111.9305","substitutionUrl":"1814945","eventLatitude":"33.42507","eventState":"Arizona","sortDate":"2000-10-10","keywords":"Event","eventAddress":"54 West Rio Salado Parkway","dma":"Phoenix","seourl":"http://www.active.com/triathlon/tempe-az/pbr-urban-dirt-duathlon-2010","country":"United States","category":"Activities","market":"Phoenix","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Red Rock Co","eventZip":"85281","latitude":"33.42507","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-10","state":"Arizona","mediaType":["Event","Event\\Off-Road","Event\\Sprint","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"estParticipants":"400","assetId":["C47BA275-BFFF-41F1-8915-42F9159456B6","c47ba275-bfff-41f1-8915-42f9159456b6"],"participationCriteria":"Adult,Family,Kids,Men,Women","onlineDonationAvailable":"0","assetName":["PBR Urban Dirt Duathlon","PBR Urban Dirt Duathlon"],"eventURL":"http://www.redrockco.com","zip":"85281","contactPhone":"877-681-7223","contactEmail":"mike@redrockco.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/tempe-az/pbr-urban-dirt-duathlon-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-08","channel":["More Sports\\Duathlon","Triathlon"]}},{"escapedUrl":"http://www.active.com/triathlon/hayesville-nc/fall-chill-duathlon-2010","language":"en","title":"Fall Chill Duathlon 2010 | Hayesville, North Carolina 28904 \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/hayesville-nc/fall-chill-duathlon-2010","summary":"","meta":{"eventDate":"2010-10-24T10:00:00-07:00","location":"Clay County Recreation Park: 5 miles from Hiawassee Ga","tag":["event:10","Triathlon:10"],"endDate":"2010-10-24","eventLongitude":"-83.73081","splitMediaType":["Event","Sprint","\u003ddifficulty:Intermediate"],"lastModifiedDateTime":"2010-09-16 03:11:56.37","locationName":"Clay County Recreation Park: 5 miles from Hiawassee Ga","endTime":"10:00:00","google-site-verification":"","city":"Hayesville","startTime":"10:00:00","eventId":"1816551","description":"","longitude":"-83.73081","substitutionUrl":"1816551","eventLatitude":"35.04112","eventState":"North Carolina","sortDate":"2000-10-24","keywords":"Event","eventAddress":"Clay County Recreation Park Road, Hayesville, NC 28904","dma":"Atlanta","seourl":"http://www.active.com/triathlon/hayesville-nc/fall-chill-duathlon-2010","country":"United States","category":"Activities","market":"Atlanta","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Scott Hanna","eventZip":"28904","latitude":"35.04112","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-24","state":"North Carolina","mediaType":["Event","Event\\Sprint","\u003ddifficulty:Intermediate"],"estParticipants":"150","assetId":["2B2DD142-23EA-42AE-A86A-C3BAAF8089F0","2b2dd142-23ea-42ae-a86a-c3baaf8089f0"],"participationCriteria":"Adult","onlineDonationAvailable":"0","assetName":["Fall Chill Duathlon 2010","Fall Chill Duathlon 2010"],"eventURL":"http://www.thebeastoftheeast.net","zip":"28904","contactPhone":"828-389-6982","contactEmail":"tri20001@msn.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/hayesville-nc/fall-chill-duathlon-2010","onlineRegistrationAvailable":"true","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-16","channel":["More Sports\\Duathlon","Triathlon"]}},{"escapedUrl":"http://www.active.com/triathlon/congers-ny/fall-toga-duathlon-2010","language":"en","title":"2010 Fall Toga Duathlon | Congers, New York 10920 \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/congers-ny/fall-toga-duathlon-2010","summary":"","meta":{"startDate":"2010-10-17","eventDate":"2010-10-17T08:30:00-07:00","location":"Rockland Lake","tag":["event:10","Triathlon:10"],"state":"New York","endDate":"2010-10-17","eventLongitude":"-73.93904","splitMediaType":["Event","Sprint"],"locationName":"Rockland Lake","endTime":"8:30:00","mediaType":["Event","Event\\Sprint"],"city":"Congers","google-site-verification":"","startTime":"8:30:00","assetId":["096853C1-151A-4EED-9931-79275795AAA9","096853c1-151a-4eed-9931-79275795aaa9"],"eventId":"1821127","participationCriteria":"All","description":"","longitude":"-73.93904","onlineDonationAvailable":"false","substitutionUrl":"1821127","assetName":["2010 Fall Toga Duathlon","2010 Fall Toga Duathlon"],"zip":"10920","contactPhone":"8453538331","eventLatitude":"41.15644","eventState":"New York","sortDate":"2000-10-17","keywords":"Event","eventAddress":"Rt 9W","contactEmail":"Lonny@Togabikes.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/congers-ny/fall-toga-duathlon-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-02 15:22:22.54","eventZip":"10920","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"41.15644","channel":["More Sports\\Duathlon","Triathlon"]}},{"escapedUrl":"http://www.active.com/triathlon/mendon-ny/rochester-autumn-classic-duathlon-2010","language":"en","title":"Rochester Autumn Classic Duathlon 2010 | Mendon, New \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/mendon-ny/rochester-autumn-classic-duathlon-2010","summary":"","meta":{"eventDate":"2010-10-03T08:30:00-07:00","location":"Stewart Lodge, Mendon Ponds Park","tag":["event:10","Triathlon:10"],"endDate":"2010-10-03","eventLongitude":"-77.49951","splitMediaType":["Event","Sprint"],"lastModifiedDateTime":"2010-08-30 13:15:51.837","locationName":"Stewart Lodge, Mendon Ponds Park","endTime":"8:30:00","google-site-verification":"","city":"Mendon","startTime":"8:30:00","eventId":"1821816","description":"","longitude":"-77.49951","substitutionUrl":"1821816","eventLatitude":"42.99441","eventState":"New York","sortDate":"2000-10-03","keywords":"Event","eventAddress":"Douglas Rd.","dma":"Rochester, NY","seourl":"http://www.active.com/triathlon/mendon-ny/rochester-autumn-classic-duathlon-2010","country":"United States","category":"Activities","market":"Rochester, NY","contactName":"Dave or Ellen Boutillier","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","eventZip":"14506","latitude":"42.99441","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-03","state":"New York","mediaType":["Event","Event\\Sprint"],"estParticipants":"250","assetId":["39F96A49-A188-4592-A04C-755D12D5D8BB","39f96a49-a188-4592-a04c-755d12d5d8bb"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["Rochester Autumn Classic Duathlon 2010","Rochester Autumn Classic Duathlon 2010"],"eventURL":"http://www.yellowjacketracing.com","zip":"14506","contactPhone":"585-697-3338","contactEmail":"elleneabrenner@aol.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/mendon-ny/rochester-autumn-classic-duathlon-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-08-30","channel":["More Sports\\Duathlon","Triathlon"]}},{"escapedUrl":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-2010","language":"en","title":"IRONMAN 70.3 MIAMI | Miami, Florida 33132 | Saturday \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-2010","summary":"","meta":{"startDate":"2010-10-30","eventDate":"2010-10-30T07:00:00-07:00","location":"Bayfront Park - Downtown Miami","tag":["event:10","Triathlon:10"],"state":"Florida","eventLongitude":"-80.18975","endDate":"2010-10-30","lastModifiedDateTime":"2010-05-10 11:16:04.46","splitMediaType":["Event","Ironman","Long Course","\u003ddifficulty:Advanced","\u003ddifficulty:Intermediate"],"locationName":"Bayfront Park - Downtown Miami","endTime":"7:00:00","mediaType":["Event","Event\\Ironman","Event\\Long Course","\u003ddifficulty:Advanced","\u003ddifficulty:Intermediate"],"city":"Miami","google-site-verification":"","startTime":"7:00:00","assetId":["72FAE9F7-5C68-4DF8-B01C-B63AC188A06A","72fae9f7-5c68-4df8-b01c-b63ac188a06a"],"eventId":"1800302","participationCriteria":"Adult,Family,Men,Women","description":"","longitude":"-80.18975","onlineDonationAvailable":"false","substitutionUrl":"1800302","assetName":["IRONMAN 70.3 MIAMI","IRONMAN 70.3 MIAMI"],"zip":"33132","contactPhone":"3053072285","eventLatitude":"25.78649","eventState":"Florida","sortDate":"2000-10-30","keywords":"Event","eventAddress":"301 N. Biscayne Blvd.","contactEmail":"jennifer@miamitrievents.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-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-05-10","eventZip":"33132","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"25.78649","channel":"Triathlon"}},{"escapedUrl":"http://www.active.com/triathlon/austin-tx/austin-oyster-urban-adventure-race-2010","language":"en","title":"Austin Oyster Urban Adventure Race | Austin, Texas 78704 \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/austin-tx/austin-oyster-urban-adventure-race-2010","summary":"","meta":{"eventDate":"2010-10-16T08:00:00-07:00","location":"Runtex","tag":["event:10","Triathlon:10"],"endDate":"2010-10-16","eventLongitude":"-97.76204","splitMediaType":"Event","lastModifiedDateTime":"2010-09-17 10:16:19.03","locationName":"Runtex","endTime":"8:00:00","google-site-verification":"","city":"Austin","startTime":"8:00:00","eventId":"1831863","description":"","longitude":"-97.76204","substitutionUrl":"1831863","eventLatitude":"30.24495","eventState":"Texas","sortDate":"2000-10-16","keywords":"Event","eventAddress":"422 W. Riverside","dma":"Austin","seourl":"http://www.active.com/triathlon/austin-tx/austin-oyster-urban-adventure-race-2010","country":"United States","category":"Activities","market":"Austin","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Luann Morris","eventZip":"78704","latitude":"30.24495","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-16","state":"Texas","mediaType":"Event","estParticipants":"500","assetId":["5BCA2E67-05F8-49FA-911B-EA007A08A7ED","5bca2e67-05f8-49fa-911b-ea007a08a7ed"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["Austin Oyster Urban Adventure Race","Austin Oyster Urban Adventure Race"],"eventURL":"http://OysterRacingSeries.com","zip":"78704","contactPhone":"3037776887","contactEmail":"luann@teamsage.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/austin-tx/austin-oyster-urban-adventure-race-2010","onlineRegistrationAvailable":"true","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-17","channel":["More Sports\\Adventure Racing","Triathlon"]}},{"escapedUrl":"http://www.active.com/running/colorado-springs-co/fall-series-kids-2010-ov251","language":"en","title":"Fall Series 2010 (Kids) | Colorado Springs, Colorado 80903 \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/colorado-springs-co/fall-series-kids-2010-ov251","summary":"","meta":{"startDate":"2010-10-03","eventDate":"2010-10-03T13:30:00-07:00","location":"Various sites","tag":["event:10","Running:10"],"state":"Colorado","eventLongitude":"-104.8163","endDate":"2010-10-03","lastModifiedDateTime":"2010-08-12 11:19:31.73","splitMediaType":["Event","1 mile","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"locationName":"Various sites","endTime":"13:30:00","mediaType":["Event","Event\\1 mile","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"city":"Colorado Springs","google-site-verification":"","estParticipants":"400","startTime":"13:30:00","assetId":["54A4A562-2A34-4345-8A20-7084EC435C57","54a4a562-2a34-4345-8a20-7084ec435c57"],"eventId":"1882757","participationCriteria":"Kids","description":"","longitude":"-104.8163","onlineDonationAvailable":"true","substitutionUrl":"1882757","assetName":["Fall Series 2010 (Kids)","Fall Series 2010 (Kids)"],"zip":"80903","eventURL":"http://pprrun.org","contactPhone":"719-590-7086","sortDate":"2000-10-03","eventState":"Colorado","eventLatitude":"38.84134","keywords":"Event","contactEmail":"fallseries@aol.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/running/colorado-springs-co/fall-series-kids-2010-ov251","country":"United States","onlineRegistrationAvailable":"true","category":"Activities","image1":"http://www.active.com/images/events/hotrace.gif","market":"Colorado Springs - Pueblo","contactName":"Larry Miller","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate":"2010-08-12","eventZip":"80903","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"38.84134","channel":["Running","Walking"]}}]}',
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
s.results.should_not be_empty
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should handle a JSON parse error" do
|
329
|
-
# /search?api_key=&num=10&page=1&l=0&f=activities&v=json&r=50&s=trending&k=&m=meta:startDate:daterange:today..+
|
330
|
-
# 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=50&s=date_asc&k=&m=meta:startDate:daterange:today..+",
|
331
|
-
# :body => '{"endIndex":10,"numberOfResults":2810,"pageSize":10,"searchTime":0.86581,"_results":[{"escapedUrl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","language":"en","title":"Myrtle Beach Mini Marathon | Myrtle Beach, South Carolina \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","summary":"","meta":{"eventDate":"2010-10-24T07:00:00-07:00","location":"Myrtle Beach, South Carolina","tag":["event:10","Running:10"],"endDate":"2010-10-24","eventLongitude":"-78.92921","splitMediaType":["Event","5K","Half Marathon","Marathon","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"lastModifiedDateTime":"2010-09-13 18:15:04.753","locationName":"Myrtle Beach, South Carolina","endTime":"7:00:00","google-site-verification":"","city":"Myrtle Beach","startTime":"7:00:00","eventId":"1797753","description":"","longitude":"-78.92921","substitutionUrl":"1797753","eventLatitude":"33.75043","eventState":"South Carolina","sortDate":"2000-10-24","keywords":"Event","eventAddress":"Medieval Times","dma":"Florence - Myrtle Beach","seourl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","country":"United States","category":"Activities","market":"Florence - Myrtle Beach","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Robert Pozo","eventZip":"29579","latitude":"33.75043","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-10-24","state":"South Carolina","mediaType":["Event","Event\\5K","Event\\Half Marathon","Event\\Marathon","\u003ddifficulty:Advanced","\u003ddifficulty:Beginner","\u003ddifficulty:Intermediate"],"estParticipants":"6000","assetId":["008540A9-C2AB-4D7F-BE68-298758B324CD","008540a9-c2ab-4d7f-be68-298758b324cd"],"participationCriteria":"Adult,Men,Women","onlineDonationAvailable":"1","assetName":["Myrtle Beach Mini Marathon","Myrtle Beach Mini Marathon"],"eventURL":"http://runmyrtlebeach.com","zip":"29579","contactPhone":"1-800-733-7089","contactEmail":"info@runmyrtlebeach.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/myrtle-beach-sc/myrtle-beach-mini-marathon-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-13","channel":"Running"}},{"escapedUrl":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-2010","language":"en","title":"Fans on the Field 2010 - Denver Stadium 5K/10K | Denver \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-2010","summary":"","meta":{"startDate":"2010-10-10","eventDate":"2010-10-10T00:00:00-07:00","location":"INVESCO Field at Mile High","tag":["event:10","Running:10"],"state":"Colorado","eventLongitude":"-105.0265","endDate":"2010-10-10","lastModifiedDateTime":"2010-08-05 16:15:18.14","splitMediaType":["Event","10K","5K"],"locationName":"INVESCO Field at Mile High","endTime":"0:00:00","mediaType":["Event","Event\\10K","Event\\5K"],"city":"Denver","google-site-verification":"","startTime":"0:00:00","assetId":["4850BB73-3701-493D-936C-C38CC0B3FD4C","4850bb73-3701-493d-936c-c38cc0b3fd4c"],"eventId":"1869635","participationCriteria":"All","description":"","longitude":"-105.0265","onlineDonationAvailable":"false","substitutionUrl":"1869635","assetName":["Fans on the Field 2010 - Denver Stadium 5K/10K","Fans on the Field 2010 - Denver Stadium 5K/10K"],"zip":"80204","contactPhone":"303-293-5315","eventLatitude":"39.73804","eventState":"Colorado","sortDate":"2000-10-10","keywords":"Event","eventAddress":"1801 Bryant Street","contactEmail":"ahinkle@nscd.org","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/running/denver-co/fans-on-the-field-denver-stadium-5k10k-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-08-05","eventZip":"80204","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"39.73804","channel":["Running","Walking"]}},{"escapedUrl":"http://www.active.com/running/west-palm-beach-fl/the-palm-beaches-marathon-festival-2010","language":"en","title":"The Palm Beaches Marathon Festival | West Palm Beach \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/west-palm-beach-fl/the-palm-beaches-marathon-festival-2010","summary":"","meta":{"eventDate":"2010-12-05T06:00:00-08:00","location":"West Palm Beach, Florida","tag":["event:10","Running:10"],"endDate":"2010-12-05","eventLongitude":"-80.06707","splitMediaType":["Event","5K","Half Marathon","Marathon","Relay"],"lastModifiedDateTime":"2010-09-10 13:15:05.057","locationName":"West Palm Beach, Florida","endTime":"6:00:00","google-site-verification":"","city":"West Palm Beach","startTime":"6:00:00","eventId":"1815427","description":"","longitude":"-80.06707","substitutionUrl":"1815427","eventLatitude":"26.72339","eventState":"Florida","sortDate":"2000-12-05","keywords":"Event","eventAddress":"S. Flagler Drive and Evernia St.","dma":"West Palm Beach - Fort Pierce","seourl":"http://www.active.com/running/west-palm-beach-fl/the-palm-beaches-marathon-festival-2010","country":"United States","category":"Activities","market":"West Palm Beach - Fort Pierce","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Iva Grady","eventZip":"33401","latitude":"26.72339","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-12-05","state":"Florida","mediaType":["Event","Event\\5K","Event\\Half Marathon","Event\\Marathon","Event\\Relay"],"estParticipants":"8000","assetId":["EA86AD3C-FBBA-403A-9DDB-1D211C210225","ea86ad3c-fbba-403a-9ddb-1d211c210225"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["The Palm Beaches Marathon Festival","The Palm Beaches Marathon Festival"],"eventURL":"http://www.pbmarathon.com","zip":"33401","contactPhone":"561-833-3711 ex. 222","contactEmail":"info@marathonofthepalmbeaches.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/west-palm-beach-fl/the-palm-beaches-marathon-festival-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-10","channel":"Running"}},{"escapedUrl":"http://www.active.com/running/encino-ca/2nd-annual-wespark-10k-run-and-5k-run-walk-2010","language":"en","title":"2nd Annual weSPARK 10K Run \u0026amp; 5K Run Walk | Encino \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/encino-ca/2nd-annual-wespark-10k-run-and-5k-run-walk-2010","summary":"","meta":{"eventDate":"2010-11-14T08:00:00-08:00","location":"Balboa Park/Lake Balboa","tag":["event:10","Running:10"],"endDate":"2010-11-14","eventLongitude":"-118.4924","splitMediaType":["Event","10K","5K"],"lastModifiedDateTime":"2010-08-23 13:16:00.843","locationName":"Balboa Park/Lake Balboa","endTime":"8:00:00","google-site-verification":"","city":"Encino","startTime":"8:00:00","eventId":"1847738","description":"","longitude":"-118.4924","substitutionUrl":"1847738","eventLatitude":"34.19933","eventState":"California","sortDate":"2000-11-14","keywords":"Event","eventAddress":"6335 Woodley Avenue","dma":"Los Angeles","seourl":"http://www.active.com/running/encino-ca/2nd-annual-wespark-10k-run-and-5k-run-walk-2010","country":"United States","category":"Activities","market":"Los Angeles","contactName":"Lilliane Ballesteros","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","eventZip":"91406","latitude":"34.19933","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-11-14","state":"California","mediaType":["Event","Event\\10K","Event\\5K"],"estParticipants":"1400","assetId":["D9A22F33-8A14-4175-8D5B-D11578212A98","d9a22f33-8a14-4175-8d5b-d11578212a98"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["2nd Annual weSPARK 10K Run \u0026 5K Run Walk","2nd Annual weSPARK 10K Run \u0026 5K Run Walk"],"eventURL":"http://www.wespark.org","zip":"91406","contactPhone":"818-906-3022","contactEmail":"lilliane@wespark.org","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/encino-ca/2nd-annual-wespark-10k-run-and-5k-run-walk-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-08-23","channel":["Running","Walking"]}},{"escapedUrl":"http://www.active.com/running/los-angeles-playa-del-rey-ca/heroes-of-hope-race-for-research-2010","language":"en","title":"Heroes of Hope Race for Research | Los Angeles, Playa Del \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/los-angeles-playa-del-rey-ca/heroes-of-hope-race-for-research-2010","summary":"","meta":{"eventDate":"2010-11-07T08:00:00-08:00","location":"Dockweiler State Beach","tag":["event:10","Running:10"],"endDate":"2010-11-07","eventLongitude":"-118.4392","splitMediaType":["Event","10K","5K"],"lastModifiedDateTime":"2010-09-09 07:15:48.193","locationName":"Dockweiler State Beach","endTime":"8:00:00","google-site-verification":"","city":"Los Angeles, Playa Del Rey","startTime":"8:00:00","eventId":"1858905","description":"","longitude":"-118.4392","substitutionUrl":"1858905","eventLatitude":"33.9495","eventState":"California","sortDate":"2000-11-07","keywords":"Event","eventAddress":"8255 Vista Del Mar Blvd","dma":"Los Angeles","seourl":"http://www.active.com/running/los-angeles-playa-del-rey-ca/heroes-of-hope-race-for-research-2010","country":"United States","category":"Activities","market":"Los Angeles","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","contactName":"Lisa Kaminsky-Millar","eventZip":"90293","latitude":"33.9495","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-11-07","state":"California","mediaType":["Event","Event\\10K","Event\\5K"],"estParticipants":"1000","assetId":["0D92AB40-ED0B-4657-B00B-480B38062F1C","0d92ab40-ed0b-4657-b00b-480b38062f1c"],"participationCriteria":"All","onlineDonationAvailable":"1","assetName":["Heroes of Hope Race for Research","Heroes of Hope Race for Research"],"eventURL":"http://www.heroesofhoperace.org","zip":"90293","contactPhone":"1-866-48-4CURE","contactEmail":"heroesofhoperace@gmail.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/los-angeles-playa-del-rey-ca/heroes-of-hope-race-for-research-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-09","channel":"Running"}},{"escapedUrl":"http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","language":"en","title":"Calabasas Classic 2010 - 5k 10k Runs | Calabasas, California \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","summary":"","meta":{"eventDate":"2010-11-14T08:00:00-08:00","location":"Calabasas Park Centre","tag":["event:10","Green:10","Running:10"],"endDate":"2010-11-14","eventLongitude":"-118.6789","splitMediaType":["Event","1 mile","10K","5K"],"lastModifiedDateTime":"2010-09-14 21:02:55.007","locationName":"Calabasas Park Centre","endTime":"8:00:00","google-site-verification":"","city":"Calabasas","startTime":"8:00:00","eventId":"1810531","description":"","longitude":"-118.6789","substitutionUrl":"1810531","eventLatitude":"34.12794","eventState":"California","sortDate":"2000-11-14","keywords":"Event","eventAddress":"23975 Park Sorrento","dma":"Los Angeles","seourl":"http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","country":"United States","category":"Activities","market":"Los Angeles","contactName":"Julie Talbert","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","eventZip":"91302","latitude":"34.12794","UpdateDateTime":"9/1/2010 6:09:21 PM","startDate":"2010-11-14","state":"California","mediaType":["Event","Event\\1 mile","Event\\10K","Event\\5K"],"estParticipants":"2500","assetId":["11B01475-8C65-4F9C-A4AC-2A3FA55FE8CD","11b01475-8c65-4f9c-a4ac-2a3fa55fe8cd"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["Calabasas Classic 2010 - 5k 10k Runs","Calabasas Classic 2010 - 5k 10k Runs"],"eventURL":"http://www.calabasasclassic.com","zip":"91302","contactPhone":"818-715-0428","contactEmail":"rot10kd@yahoo.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/running/calabasas-ca/calabasas-classic-5k-10k-runs-2010","onlineRegistrationAvailable":"1","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-14","channel":["Running","Walking"]}},{"escapedUrl":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-2010","language":"en","title":"IRONMAN 70.3 MIAMI | Miami, Florida 33132 | Saturday \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-2010","summary":"","meta":{"startDate":"2010-10-30","eventDate":"2010-10-30T07:00:00-07:00","location":"Bayfront Park - Downtown Miami","tag":["event:10","Triathlon:10"],"state":"Florida","eventLongitude":"-80.18975","endDate":"2010-10-30","lastModifiedDateTime":"2010-05-10 11:16:04.46","splitMediaType":["Event","Ironman","Long Course","\u003ddifficulty:Advanced","\u003ddifficulty:Intermediate"],"locationName":"Bayfront Park - Downtown Miami","endTime":"7:00:00","mediaType":["Event","Event\\Ironman","Event\\Long Course","\u003ddifficulty:Advanced","\u003ddifficulty:Intermediate"],"city":"Miami","google-site-verification":"","startTime":"7:00:00","assetId":["72FAE9F7-5C68-4DF8-B01C-B63AC188A06A","72fae9f7-5c68-4df8-b01c-b63ac188a06a"],"eventId":"1800302","participationCriteria":"Adult,Family,Men,Women","description":"","longitude":"-80.18975","onlineDonationAvailable":"false","substitutionUrl":"1800302","assetName":["IRONMAN 70.3 MIAMI","IRONMAN 70.3 MIAMI"],"zip":"33132","contactPhone":"3053072285","eventLatitude":"25.78649","eventState":"Florida","sortDate":"2000-10-30","keywords":"Event","eventAddress":"301 N. Biscayne Blvd.","contactEmail":"jennifer@miamitrievents.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/miami-fl/ironman-703-miami-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-05-10","eventZip":"33132","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"25.78649","channel":"Triathlon"}},{"escapedUrl":"http://www.active.com/triathlon/san-juan-na/ironman-703-san-juan-2011-ig329","language":"en","title":"2011 Ironman 70.3 San Juan | San Juan, 00901 | Saturday \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/san-juan-na/ironman-703-san-juan-2011-ig329","summary":"","meta":{"startDate":"2011-03-19","eventDate":"2011-03-19T07:00:00-07:00","location":"Los Rosales Street, San Geronimo Grounds","tag":["event:10","Triathlon:10"],"state":"N/A","endDate":"2011-03-19","eventLongitude":"-66.10572","lastModifiedDateTime":"2010-06-15 14:15:08.557","splitMediaType":["Event","Ironman","\u003ddifficulty:Advanced"],"locationName":"Los Rosales Street, San Geronimo Grounds","endTime":"7:00:00","mediaType":["Event","Event\\Ironman","\u003ddifficulty:Advanced"],"city":"San Juan","google-site-verification":"","startTime":"7:00:00","assetId":["F6B819B9-9CC1-4E67-A87D-11518B05D4F3","f6b819b9-9cc1-4e67-a87d-11518b05d4f3"],"eventId":"1841595","participationCriteria":"Adult","description":"","longitude":"-66.10572","onlineDonationAvailable":"false","substitutionUrl":"1841595","assetName":["2011 Ironman 70.3 San Juan","2011 Ironman 70.3 San Juan"],"zip":"00901","contactPhone":"813-868-5940","eventLatitude":"18.46633","sortDate":"2001-03-19","keywords":"Event","contactEmail":"info@bnsportsllc.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/san-juan-na/ironman-703-san-juan-2011-ig329","country":"Puerto Rico","onlineRegistrationAvailable":"true","category":"Activities","image1":"http://www.active.com/images/events/hotrace.gif","assetTypeId":"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65","lastModifiedDate":"2010-06-15","eventZip":"00901","latitude":"18.46633","UpdateDateTime":"9/1/2010 6:09:21 PM","channel":"Triathlon"}},{"escapedUrl":"http://www.active.com/triathlon/st-george-ut/ford-ironman-st-george-2011","language":"en","title":"2011 Ford Ironman St. George | St. George, Utah 84737 \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/st-george-ut/ford-ironman-st-george-2011","summary":"","meta":{"startDate":"2011-05-07","eventDate":"2011-05-07T07:00:00-07:00","location":"Sand Hollow State Park,","tag":["event:10","Triathlon:10"],"state":"Utah","eventLongitude":"-113.1508","endDate":"2011-05-07","lastModifiedDateTime":"2010-07-22 11:15:08.46","splitMediaType":["Event","Ironman","Long Course"],"locationName":"Sand Hollow State Park,","endTime":"7:00:00","mediaType":["Event","Event\\Ironman","Event\\Long Course"],"city":"St. George","google-site-verification":"","startTime":"7:00:00","assetId":["A10B5BC1-BD95-4AFE-A1F6-35F6099E3636","a10b5bc1-bd95-4afe-a1f6-35f6099e3636"],"eventId":"1848350","participationCriteria":"All","description":"","longitude":"-113.1508","onlineDonationAvailable":"false","substitutionUrl":"1848350","assetName":["2011 Ford Ironman St. George","2011 Ford Ironman St. George"],"zip":"84737","contactPhone":"813-868-5940","eventLatitude":"37.15574","eventState":"Utah","sortDate":"2001-05-07","keywords":"Event","eventAddress":"4405 West 3600 South","contactEmail":"stgeorge@ironman.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/st-george-ut/ford-ironman-st-george-2011","country":"United States","onlineRegistrationAvailable":"true","category":"Activities","image1":"http://www.active.com/images/events/hotrace.gif","assetTypeId":"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6","lastModifiedDate":"2010-07-22","eventZip":"84737","UpdateDateTime":"9/1/2010 6:09:21 PM","latitude":"37.15574","channel":"Triathlon"}},{"escapedUrl":"http://www.active.com/triathlon/galveston-tx/memorial-hermann-ironman-703-texas-and-lonestar-sprint-triathlon-2011","language":"en","title":"2011 Memorial Hermann Ironman 70.3 Texas \u0026amp; Lonestar \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/galveston-tx/memorial-hermann-ironman-703-texas-and-lonestar-sprint-triathlon-2011","summary":"","meta":{"startDate":"2011-04-09","eventDate":"2011-04-09T07:00:00-07:00","location":"Moody Gardens","state":"Texas","endDate":"2011-04-10","eventLongitude":"-94.90395","lastModifiedDateTime":"2010-05-12 09:16:41.91","splitMediaType":["Event","Ironman","Long Course","Sprint"],"locationName":"Moody Gardens","endTime":"7:00:00","mediaType":["Event","Event\\Ironman","Event\\Long Course","Event\\Sprint"],"city":"Galveston","google-site-verification":"","startTime":"7:00:00","assetId":["A40CC533-D502-4953-8157-DBB64D7FC4C2","a40cc533-d502-4953-8157-dbb64d7fc4c2"],"eventId":"1859810","participationCriteria":"All","description":"","longitude":"-94.90395","onlineDonationAvailable":"false","substitutionUrl":"1859810","assetName":["2011 Memorial Hermann Ironman 70.3 Texas \u0026 Lonestar Sprint Triathlon","2011 Memorial Hermann Ironman 70.3 Texas \u0026 Lonestar Sprint Triathlon"],"zip":"77554","contactPhone":"813-868-5940","eventLatitude":"29.24699","eventState":"Texas","sortDate":"2001-04-09","keywords":"Event","contactEmail":"texas70.3@ironman.com","onlineMembershipAvailable":"false","trackbackurl":"http://www.active.com/triathlon/galveston-tx/memorial-hermann-ironman-703-texas-and-lonestar-sprint-triathlon-2011","country":"United States","onlineRegistrationAvailable":"true","category":"Activities","image1":"http://www.active.com/images/events/hotrace.gif","assetTypeId":"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6","lastModifiedDate":"2010-05-12","eventZip":"77554","latitude":"29.24699","UpdateDateTime":"9/1/2010 6:09:21 PM","channel":"Triathlon"}}]}',
|
332
|
-
# :status => ["200", "Found"])
|
333
|
-
# This query is throwing this error "source did not contain any JSON!" and we need to handle it
|
334
|
-
# s = Search.search( {:radius=>"50", :keywords=>"", :page=>1, :num_results=>10, :location=>"0"} )
|
335
|
-
pending
|
336
|
-
end
|
337
|
-
|
338
|
-
end
|
339
|
-
describe "Call Live Data" do
|
340
|
-
|
341
|
-
it "should find only events in the future" do
|
342
|
-
s = Search.search( { :keywords => ["running"] } )
|
343
|
-
s.should have(10).results
|
344
|
-
s.results.each do |a|
|
345
|
-
a.start_date.should satisfy { |d|
|
346
|
-
d >= Date.today
|
347
|
-
}
|
328
|
+
|
329
|
+
it "should find Running events" do
|
330
|
+
asset = Active::Asset.order(:date_asc)
|
331
|
+
asset.page(1).limit(1)
|
332
|
+
asset.channel('Running')
|
333
|
+
asset.to_query.should have_param('Running')
|
334
|
+
asset.results.first.should be_an_instance_of(Active::Activity)
|
335
|
+
asset.results.first.url.should_not be_nil
|
336
|
+
asset.results.first.meta.eventId.should_not be_nil
|
348
337
|
end
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
a.start_date.should satisfy { |d|
|
356
|
-
d >= Date.new(2010,1,1) and d <= Date.new(2010,2,1)
|
357
|
-
}
|
338
|
+
|
339
|
+
it "should not return more then 1000 results" do
|
340
|
+
# GSA will only return 1000 events but will give us a number larger then 1000.
|
341
|
+
# This test depends on this query returning more than 1000
|
342
|
+
asset = Active::Asset.order(:date_asc)
|
343
|
+
asset.results.number_of_results.should eql(1000)
|
358
344
|
end
|
359
345
|
end
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
d >= Date.new(2010,1,1)
|
367
|
-
}
|
346
|
+
|
347
|
+
describe "Results Object" do
|
348
|
+
|
349
|
+
it "should have a date object for each result" do
|
350
|
+
asset = Active::Asset.new({"meta" => {"startDate"=>"2011-07-16"}})
|
351
|
+
asset.start_date.should be_an_instance_of(Date)
|
368
352
|
end
|
369
|
-
|
370
|
-
|
353
|
+
|
354
|
+
it "should return nil of there isn't a date" do
|
355
|
+
asset = Active::Asset.new()
|
356
|
+
asset.start_date.should be_nil
|
357
|
+
asset = Active::Asset.new({"meta" => { "foo"=>"bar" }})
|
358
|
+
asset.start_date.should be_nil
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should return nil if the title is missing" do
|
362
|
+
asset = Active::Asset.new({"meta" => {"startDate"=>"2011-07-16"}})
|
363
|
+
asset.title.should be_nil
|
371
364
|
end
|
372
|
-
end
|
373
|
-
|
374
|
-
it "should search by keyword" do
|
375
|
-
s = Search.search( {:keywords => "Running Race"} )
|
376
|
-
s.results.should have_at_least(1).items
|
377
|
-
end
|
378
|
-
|
379
|
-
it "shouls search by city" do
|
380
|
-
s = Search.search({:city=>"Oceanside"})
|
381
|
-
s.results.should have_at_least(1).items
|
382
|
-
end
|
383
|
-
# our model should be updated to handle multiple categories
|
384
|
-
# I'm sure running is with in all of these events but we're only storing 1.
|
385
|
-
# it "should find only running activities" do
|
386
|
-
# s = Search.search( {:channels => [:running],
|
387
|
-
# :start_date => Date.new(2010,1,1), :num_results => 20} )
|
388
|
-
# s.should have(20).results
|
389
|
-
# s.results.each do |a|
|
390
|
-
# puts "-#{a.category}-"
|
391
|
-
# a.category.should satisfy { |d|
|
392
|
-
# d.include?('Running' )
|
393
|
-
# }
|
394
|
-
# end
|
395
|
-
# end
|
396
|
-
|
397
|
-
it "should find yoga activities by channel" do
|
398
|
-
s = Search.search( {:channels => [:yoga]} )
|
399
|
-
s.should have_at_least(1).results
|
400
|
-
end
|
401
|
-
|
402
|
-
it "should not set sort to an empty string" do
|
403
|
-
# s = Search.search( {:sort => ""} )
|
404
|
-
# s.sort.should_not be_empty
|
405
|
-
pending
|
406
|
-
end
|
407
|
-
|
408
|
-
it "should get results given these area codes" do
|
409
|
-
s = Search.search( {:zips => "92121, 92078, 92114"} )
|
410
|
-
s.should be_an_instance_of Search
|
411
|
-
s.results.should_not be_empty
|
412
|
-
end
|
413
365
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
# DateTime.parse(a.gsa.last_modified).should satisfy { |d|
|
420
|
-
# d >= DateTime.now-2
|
421
|
-
# }
|
422
|
-
# end
|
366
|
+
it "should return nil if the title is missing" do
|
367
|
+
asset = Active::Asset.new({"meta" => {"startDate"=>"2011-07-16"}})
|
368
|
+
asset.to_json.should eql("{\"meta\":{\"startDate\":\"2011-07-16\"}}")
|
369
|
+
end
|
370
|
+
|
423
371
|
end
|
424
|
-
it "should find events that have online regristration"
|
425
|
-
it "should find events that do not have online regristration"
|
426
372
|
|
427
|
-
|
428
|
-
|
373
|
+
describe "Factory" do
|
374
|
+
it "should type cast results" do
|
375
|
+
asset = Active::Asset.factory({})
|
376
|
+
asset.should be_an_instance_of(Active::Asset)
|
377
|
+
asset2 = Active::Asset.factory({'meta'=>{'category'=>'Activities'}})
|
378
|
+
asset2.should be_an_instance_of(Active::Activity)
|
379
|
+
asset3 = Active::Asset.factory({'meta'=>{'category'=>'Articles'}})
|
380
|
+
asset3.should be_an_instance_of(Active::Article)
|
381
|
+
asset4 = Active::Asset.factory({'meta'=>{'category'=>'Training plans'}})
|
382
|
+
asset4.should be_an_instance_of(Active::Training)
|
383
|
+
end
|
429
384
|
end
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
385
|
+
|
386
|
+
describe "Real world examples" do
|
387
|
+
it "should work in Search.rb" do
|
388
|
+
asset = Active::Activity.page(1).limit(10)
|
389
|
+
asset.date_range( "2000-11-1", "2011-11-3" )
|
390
|
+
asset.keywords("run")
|
391
|
+
asset.state("CA")
|
392
|
+
asset.channel("Running")
|
393
|
+
|
394
|
+
asset.to_query.should have_param("meta:startDate:daterange:11%2F01%2F2000..11%2F03%2F2011")
|
395
|
+
asset.to_query.should have_param("k=run")
|
396
|
+
asset.to_query.should have_param("meta:state=CA")
|
397
|
+
asset.to_query.should have_param("meta:channel=Running")
|
440
398
|
|
441
|
-
|
399
|
+
# open_url asset.to_query
|
400
|
+
asset.should have_exactly(10).results
|
401
|
+
end
|
402
|
+
it "should work in Search.rb" do
|
403
|
+
asset = Active::Activity.page(1).limit(10)
|
404
|
+
asset.date_range( "2000-11-1", "2011-11-3" )
|
405
|
+
asset.keywords("run walk")
|
406
|
+
asset.state("CA")
|
407
|
+
asset.channel("Running")
|
408
|
+
|
409
|
+
# open_url asset.to_query
|
410
|
+
asset.to_query.should have_param("k=run%20walk")
|
411
|
+
asset.should have_at_least(1).results
|
412
|
+
end
|
442
413
|
end
|
443
|
-
describe "Parametric search for triathlon channel" do
|
444
|
-
end
|
445
|
-
end
|
446
414
|
|
415
|
+
end
|
447
416
|
end
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|