Active 0.0.25 → 0.0.26

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'net/http'
2
+ require 'uri'
1
3
  module Active
2
4
  module Services
3
5
 
@@ -74,17 +76,21 @@ module Active
74
76
  return @primary_source = ActiveWorks.find_by_id(substitutionUrl)
75
77
  end
76
78
  end
77
-
79
+ # activity.rb:80: warning: else without rescue is useless
80
+ # return true if @primary_source else false
78
81
  def primary_loaded?
79
- return true if @primary_source else false
82
+ return true if @primary_source
83
+ false
80
84
  end
81
85
 
82
86
  def ats_loaded?
83
- return true if @ats else false
87
+ return true if @ats
88
+ false
84
89
  end
85
90
 
86
91
  def gsa_loaded?
87
- return true if @gsa else false
92
+ return true if @gsa
93
+ false
88
94
  end
89
95
 
90
96
  # def load_datasources
@@ -238,46 +244,46 @@ module Active
238
244
  end
239
245
 
240
246
  def desc
241
- return @primary_source.desc if primary_loaded?
242
- return @ats.desc if ats_loaded?
243
- return @gsa.desc if gsa_loaded?
244
- return nil
245
- end
246
-
247
- def _desc
248
- return primary_source.desc unless primary_source.nil? || primary_source.desc.nil?
249
- return ats.desc unless ats.nil? || ats.desc.nil?
250
- return gsa.desc unless gsa.nil? || gsa.desc.nil?
251
- return nil
252
- end
247
+ return @primary_source.desc if primary_loaded?
248
+ return @ats.desc if ats_loaded?
249
+ return @gsa.desc if gsa_loaded?
250
+ return nil
251
+ end
253
252
 
254
- def asset_id
255
- return @primary_source.asset_id if primary_loaded?
256
- return @ats.asset_id if ats_loaded?
257
- return @gsa.asset_id if gsa_loaded?
258
- return nil
259
- end
253
+ def _desc
254
+ return primary_source.desc unless primary_source.nil? || primary_source.desc.nil?
255
+ return ats.desc unless ats.nil? || ats.desc.nil?
256
+ return gsa.desc unless gsa.nil? || gsa.desc.nil?
257
+ return nil
258
+ end
260
259
 
261
- def _asset_id
262
- return primary_source.asset_id unless primary_source.nil? || primary_source.asset_id.nil?
263
- return ats.asset_id unless ats.nil? || ats.asset_id.nil?
264
- return gsa.asset_id unless gsa.nil? || gsa.asset_id.nil?
265
- return nil
266
- end
260
+ def asset_id
261
+ return @primary_source.asset_id if primary_loaded?
262
+ return @ats.asset_id if ats_loaded?
263
+ return @gsa.asset_id if gsa_loaded?
264
+ return nil
265
+ end
267
266
 
268
- def asset_type_id
269
- return @primary_source.asset_type_id if primary_loaded?
270
- return @ats.asset_type_id if ats_loaded?
271
- return @gsa.asset_type_id if gsa_loaded?
272
- return nil
273
- end
267
+ def _asset_id
268
+ return primary_source.asset_id unless primary_source.nil? || primary_source.asset_id.nil?
269
+ return ats.asset_id unless ats.nil? || ats.asset_id.nil?
270
+ return gsa.asset_id unless gsa.nil? || gsa.asset_id.nil?
271
+ return nil
272
+ end
274
273
 
275
- def _asset_type_id
276
- return primary_source.asset_type_id unless primary_source.nil? || primary_source.asset_type_id.nil?
277
- return ats.asset_type_id unless ats.nil? || ats.asset_type_id.nil?
278
- return gsa.asset_type_id unless gsa.nil? || gsa.asset_type_id.nil?
279
- return nil
280
- end
274
+ def asset_type_id
275
+ return @primary_source.asset_type_id if primary_loaded?
276
+ return @ats.asset_type_id if ats_loaded?
277
+ return @gsa.asset_type_id if gsa_loaded?
278
+ return nil
279
+ end
280
+
281
+ def _asset_type_id
282
+ return primary_source.asset_type_id unless primary_source.nil? || primary_source.asset_type_id.nil?
283
+ return ats.asset_type_id unless ats.nil? || ats.asset_type_id.nil?
284
+ return gsa.asset_type_id unless gsa.nil? || gsa.asset_type_id.nil?
285
+ return nil
286
+ end
281
287
 
282
288
  # id within a system
283
289
  def asset_id=(value)
@@ -428,6 +434,20 @@ module Active
428
434
  return nil
429
435
  end
430
436
 
437
+ # reg-unavailable – No online registration
438
+ # reg-not-open – Online registration is available, but is not currently open
439
+ # reg-closed – The registration deadline has passed
440
+ # reg-open – Registration is currently open
441
+ def regristration_available?
442
+ if @gsa.asset_type_id == "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
443
+ Net::HTTP.get URI.parse("http://apij.active.com/regcenter/event/#{@gsa.substitutionUrl}/regstatus")
444
+ elsif @gsa.asset_type_id == "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
445
+ Net::HTTP.get URI.parse("http://apij.active.com/activeworks/event/#{@gsa.asset_id}/regstatus")
446
+ else
447
+ 'reg-open'
448
+ end
449
+ end
450
+
431
451
 
432
452
  # Examples
433
453
  # Adding the asset type id will improve performance
@@ -11,6 +11,7 @@ describe Activity do
11
11
  describe "Creating an activity from a GSA object" do
12
12
  before(:each) do
13
13
  @a = Activity.new( GSA.new(JSON.parse('{"escapedUrl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","language":"en","title":"2011 Rohto Ironman 70.3 California | Oceanside, California \u003cb\u003e...\u003c/b\u003e","url":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","summary":"","meta":{"eventDate":"2011-04-02T00:00:00-07:00","location":"Oceanside Harbor","tag":["event:10","Triathlon:10"],"eventLongitude":"-117.3586","endDate":"2011-04-02","locationName":"Oceanside Harbor","lastModifiedDateTime":"2010-09-30 06:16:05.107","splitMediaType":["Event","Ironman","Long Course"],"endTime":"0:00:00","city":"Oceanside","google-site-verification":"","startTime":"0:00:00","eventId":"1838902","description":"","longitude":"-117.3586","substitutionUrl":"1838902","sortDate":"2001-04-02","eventState":"California","eventLatitude":"33.19783","keywords":"Event","eventAddress":"1540 Harbor Drive North","dma":"San Diego","seourl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","country":"United States","category":"Activities","market":"San Diego","contactName":"World Triathlon Corporation","assetTypeId":"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6","eventZip":"92054","UpdateDateTime":"9/22/2010 11:46:24 AM","latitude":"33.19783","startDate":"2011-04-02","state":"California","mediaType":["Event","Event\\Ironman","Event\\Long Course"],"estParticipants":"2500","assetId":["77ACABBD-BA83-4C78-925D-CE49DEDDF20C","77acabbd-ba83-4c78-925d-ce49deddf20c"],"participationCriteria":"All","onlineDonationAvailable":"0","assetName":["2011 Rohto Ironman 70.3 California","2011 Rohto Ironman 70.3 California"],"zip":"92054","eventURL":"http://www.ironmancalifornia.com/","contactPhone":"813-868-5940","contactEmail":"california70.3@ironman.com","onlineMembershipAvailable":"0","trackbackurl":"http://www.active.com/triathlon/oceanside-ca/rohto-ironman-703-california-2011","onlineRegistrationAvailable":"true","image1":"http://www.active.com/images/events/hotrace.gif","lastModifiedDate":"2010-09-30","channel":"Triathlon"}}')) )
14
+ @ats_activity = Activity.new(ATS.new( {"destinationID"=>"", "assetId"=>"EEBC04D9-EA80-46C6-B9DD-6EBF49F8678F", "substitutionUrl"=>"1875345", "city"=>"San Francisco", "contactName"=>"Pete Berg", "trackbackurl"=>"http://www.active.com/page/Event_Details.htm?event_id=1875345&assetId=EEBC04D9-EA80-46C6-B9DD-6EBF49F8678F", :asset_id=>"EEBC04D9-EA80-46C6-B9DD-6EBF49F8678F", "category"=>"Activities", "zip"=>"94111", "userCommentText"=>nil, "location"=>"San Francisco metro area", "latitude"=>"37.7983181", :asset_type_name=>"Active.com Event Registration", "searchWeight"=>"1", "country"=>"United States", "participationCriteria"=>"Adult,Family,Kids,Men,Women", "dma"=>"San Francisco - Oakland - San Jose", :asset_name=>"URBAN HUNT: San Francisco", :asset_type_id=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "isSearchable"=>"true", :xmlns=>"http://api.asset.services.active.com", :url=>"http://www.active.com/page/Event_Details.htm?event_id=1875345", "row"=>"1", "image1"=>nil, "startDate"=>"2010-10-16", "contactPhone"=>"607-222-9845", "onlineDonationAvailable"=>"0", "avgUserRating"=>nil, "market"=>"San Francisco - Oakland - San Jose", :substitution_url=>"1875345", "assetTypeId"=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "assetName"=>"URBAN HUNT: San Francisco", "channel"=>["More Sports\\Adventure Racing", "Running"], "seourl"=>"http://www.active.com/running/san-francisco-ca/urban-hunt-san-francisco-2010", "mediaType"=>["Event", "Event\\5 mile", "=difficulty:Beginner", "=difficulty:Intermediate"], "startTime"=>"11:00:00", "endTime"=>"11:00:00", "contactEmail"=>"info@realityrush.com", "eventResults"=>nil, "longitude"=>"-122.4000032", "endDate"=>"2010-10-16", "onlineRegistrationAvailable"=>"false", "onlineMembershipAvailable"=>"0", "state"=>"California", "estParticipants"=>"100", "eventURL"=>"http://www.realityrush.com/events/urban-hunt-san-francisco-oct-16th-2010/"}))
14
15
  end
15
16
  it "should have asset ids" do
16
17
  @a.asset_id.should_not be_nil
@@ -275,5 +276,144 @@ describe Activity do
275
276
  @a._url.should eql("http://www.active.com/not-specified-recware-activities/antioch-ca/young-rembrandts-drawing-612-yrs-2010")
276
277
  @a.ats_loaded?.should eql(true)
277
278
  end
279
+
280
+ it "should load url from ats and _title from primary" do
281
+ @ats_activity.url.should eql("http://www.active.com/running/san-francisco-ca/urban-hunt-san-francisco-2010")
282
+ @ats_activity.primary_loaded?.should eql(false)
283
+ @ats_activity._title.should eql("URBAN HUNT: San Francisco")
284
+ @ats_activity.primary_loaded?.should eql(true)
285
+ end
286
+
287
+ it "should have an ats title" do
288
+ @ats_activity.primary_loaded?.should eql(false)
289
+ @ats_activity.title.should eql( "URBAN HUNT: San Francisco")
290
+ @ats_activity.primary_loaded?.should eql(false)
291
+ end
292
+ it "should have a primary title" do
293
+ @ats_activity.primary_loaded?.should eql(false)
294
+ @ats_activity._title.should eql( "URBAN HUNT: San Francisco")
295
+ @ats_activity.primary_loaded?.should eql(true)
296
+ end
297
+
298
+ it "should have an ats categories" do
299
+ @ats_activity.primary_loaded?.should eql(false)
300
+ @ats_activity.categories.should eql(["Adventure Racing", "Running"])
301
+ @ats_activity.primary_loaded?.should eql(false)
302
+ end
303
+ it "should have a primary categories" do
304
+ @ats_activity.primary_loaded?.should eql(false)
305
+ @ats_activity._categories.should eql( ["Running", "Adventure Racing"])
306
+ @ats_activity.primary_loaded?.should eql(true)
307
+ end
308
+
309
+ it "should have an ats address" do
310
+ @ats_activity.primary_loaded?.should eql(false)
311
+ @ats_activity.address["city"].should eql("San Francisco")
312
+ @ats_activity.primary_loaded?.should eql(false)
313
+ end
314
+ it "should have a primary address" do
315
+ @ats_activity.primary_loaded?.should eql(false)
316
+ # puts @ats_activity._address.inspect
317
+ # puts @ats_activity.primary_source.data.inspect
318
+ @ats_activity._address["address"].should eql( "1 Embarcadero Center, San Francisco, CA 94111")
319
+ @ats_activity.primary_loaded?.should eql(true)
320
+ end
321
+
322
+
323
+ it "should have a ats start_date" do
324
+ @ats_activity.primary_loaded?.should eql(false)
325
+ @ats_activity.start_date.should be_an_instance_of(DateTime)
326
+ @ats_activity.primary_loaded?.should eql(false)
327
+ end
328
+ it "should have an primary source start_date" do
329
+ @ats_activity.primary_loaded?.should eql(false)
330
+ @ats_activity._start_date.should be_an_instance_of(DateTime)
331
+ @ats_activity.primary_loaded?.should eql(true)
332
+ end
333
+ it "should have a ats start_time" do
334
+ @ats_activity.primary_loaded?.should eql(false)
335
+ @ats_activity.start_time.should be_an_instance_of(DateTime)
336
+ @ats_activity.primary_loaded?.should eql(false)
337
+ end
338
+ it "should have an primary source start_time" do
339
+ @ats_activity.primary_loaded?.should eql(false)
340
+ @ats_activity._start_time.should be_an_instance_of(DateTime)
341
+ @ats_activity.primary_loaded?.should eql(true)
342
+ end
343
+
344
+ it "should have a ats end_date" do
345
+ @ats_activity.primary_loaded?.should eql(false)
346
+ @ats_activity.end_date.should be_an_instance_of(DateTime)
347
+ @ats_activity.primary_loaded?.should eql(false)
348
+ end
349
+ it "should have an primary source end_date" do
350
+ @ats_activity.primary_loaded?.should eql(false)
351
+ @ats_activity._end_date.should be_an_instance_of(DateTime)
352
+ @ats_activity.primary_loaded?.should eql(true)
353
+ end
354
+
355
+ it "should have a ats end_time" do
356
+ @ats_activity.primary_loaded?.should eql(false)
357
+ @ats_activity.end_time.should be_an_instance_of(DateTime)
358
+ @ats_activity.primary_loaded?.should eql(false)
359
+ end
360
+ it "should have an primary source end_time" do
361
+ @ats_activity.primary_loaded?.should eql(false)
362
+ @ats_activity._end_time.should be_an_instance_of(DateTime)
363
+ @ats_activity.primary_loaded?.should eql(true)
364
+ end
365
+
366
+ it "should have a ats category" do
367
+ @ats_activity.primary_loaded?.should eql(false)
368
+ @ats_activity.category.should eql("Adventure Racing")
369
+ @ats_activity.primary_loaded?.should eql(false)
370
+ end
371
+
372
+ it "should have a primay category" do
373
+ @ats_activity.primary_loaded?.should eql(false)
374
+ @ats_activity._category.should eql("Running")
375
+ @ats_activity.primary_loaded?.should eql(true)
376
+ end
377
+
378
+ # SHOULD DESC be null or empty
379
+ it "should have a ats desc" do
380
+ @ats_activity.primary_loaded?.should eql(false)
381
+ @ats_activity.desc.should eql("")
382
+ @ats_activity.primary_loaded?.should eql(false)
383
+ end
384
+ it "should have an primary source desc" do
385
+ @ats_activity.primary_loaded?.should eql(false)
386
+ @ats_activity._desc.should_not eql("")
387
+ # puts @ats_activity._desc
388
+ @ats_activity.primary_loaded?.should eql(true)
389
+ end
390
+
391
+ it "should have a ats asset_id" do
392
+ @ats_activity.primary_loaded?.should eql(false)
393
+ @ats_activity.asset_id.should eql("EEBC04D9-EA80-46C6-B9DD-6EBF49F8678F")
394
+ @ats_activity.primary_loaded?.should eql(false)
395
+ end
396
+ it "should have an primary source asset_id" do
397
+ @ats_activity.primary_loaded?.should eql(false)
398
+ @ats_activity._asset_id.should eql("eebc04d9-ea80-46c6-b9dd-6ebf49f8678f")
399
+ @ats_activity.primary_loaded?.should eql(true)
400
+ end
401
+
402
+ it "should have a ats asset_type_id" do
403
+ @ats_activity.primary_loaded?.should eql(false)
404
+ @ats_activity.asset_type_id.should eql("EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65")
405
+ @ats_activity.primary_loaded?.should eql(false)
406
+ end
407
+
408
+ end
409
+ describe "regristration_available?" do
410
+ it "should have a valid response for regristration_available?" do
411
+ results = Search.search( { :num_results => 50, :keywords => ["running"] } )
412
+ results.should have(50).results
413
+ # results.results.first.regristration_available?.should match(/reg-open|reg-unavailable|reg-not-open|reg-closed/)
414
+ results.results.each do |a|
415
+ a.regristration_available?.should match(/reg-open|reg-unavailable|reg-not-open|reg-closed/)
416
+ end
417
+ end
278
418
  end
279
419
  end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.0.25
1
+ 0.0.26
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 25
9
- version: 0.0.25
8
+ - 26
9
+ version: 0.0.26
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jonathan Spooner, Brian Levine
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-12 00:00:00 -07:00
17
+ date: 2010-10-29 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency