Class: Active::Services::Activity
- Defined in:
- lib/services/activity.rb
Constant Summary collapse
- REG_CENTER_ASSET_TYPE_ID =
ecffc8b6-51ed-43af-82d3-540e607e5af5 Search Assets (This is a generic page (currently hosts Class Assets, Tournaments, and Swim Schools). This data comes from ATS.) 71D917DE-FA90-448A-90DA-C8852F7E03E2 tennislink.usta.com Tournaments (Tennis Tournaments, don’t know much about this one.) 2b22b4e6-5aa4-44d7-bf06-f7a71f9fa8a6 AW Camps (These are Foundations Camps pages. They have a SOAP service.) 2ba50aba-080e-4e3d-a01c-1b4f56648a2e Asset Quality DB - Thriva (These are Thriva Camps. This data come from ATS.)
"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
- REG_CENTER_ASSET_TYPE_ID2 =
"3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6"
- ACTIVE_WORKS_ASSET_TYPE_ID =
"DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
- LOCAL_ASSET_TYPE_ID =
"EC6E96A5-6900-4A0E-8B83-9AA935F45A73"
- THRIVA =
"2ba50aba-080e-4e3d-a01c-1b4f56648a2e"
- AW_CAMPS =
"2b22b4e6-5aa4-44d7-bf06-f7a71f9fa8a6"
- TENNIS_TOURNAMENTS =
"71D917DE-FA90-448A-90DA-C8852F7E03E2"
- GENERIC_SEARCH =
"ecffc8b6-51ed-43af-82d3-540e607e5af5"
Instance Attribute Summary collapse
-
#ats ⇒ Object
Returns the value of attribute ats.
-
#datasources_loaded ⇒ Object
readonly
Returns the value of attribute datasources_loaded.
-
#gsa ⇒ Object
Returns the value of attribute gsa.
-
#primary ⇒ Object
Returns the value of attribute primary.
Attributes inherited from IActivity
Class Method Summary collapse
-
.find(data) ⇒ Object
Examples Adding the asset type id will improve performance Activity.find_by_asset_id(:asset_id => “A9EF9D79-F859-4443-A9BB-91E1833DF2D5”, :asset_type_id => “EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65”) Activity.find_by_asset_id(:asset_id => “A9EF9D79-F859-4443-A9BB-91E1833DF2D5”).
Instance Method Summary collapse
- #_address ⇒ Object
- #_asset_id ⇒ Object
- #_asset_type_id ⇒ Object
- #_categories ⇒ Object
- #_category ⇒ Object
- #_desc ⇒ Object
- #_end_date ⇒ Object
- #_end_time ⇒ Object
- #_start_date ⇒ Object
- #_start_time ⇒ Object
- #_title ⇒ Object
- #_url ⇒ Object
- #_user ⇒ Object
- #address ⇒ Object
- #asset_id ⇒ Object
-
#asset_id=(value) ⇒ Object
id within a system.
- #asset_type_id ⇒ Object
- #ats_loaded? ⇒ Boolean
- #categories ⇒ Object
- #category ⇒ Object
- #contact_email ⇒ Object
- #contact_name ⇒ Object
- #desc ⇒ Object
- #end_date ⇒ Object
- #end_time ⇒ Object
- #event_image_url ⇒ Object
-
#full_address ⇒ Object
end returns the best address possible by loading other data sources 2.
- #gsa_loaded? ⇒ Boolean
-
#initialize(iactivity, preload_data = false) ⇒ Activity
constructor
data is a GSA object.
-
#online_registration ⇒ Object
The asset type id lets us know what system is came from.
-
#origin ⇒ Object
todo remove.
- #primary_category ⇒ Object
-
#primary_loaded? ⇒ Boolean
activity.rb:80: warning: else without rescue is useless return true if @primary_source else false.
- #primary_source ⇒ Object
-
#regristration_status ⇒ Object
reg-unavailable – No online registration reg-not-open – Online registration is available, but is not currently open reg-closed – The registration deadline has passed reg-open – Registration is currently open.
- #source ⇒ Object
- #start_date ⇒ Object
- #start_time ⇒ Object
- #substitutionUrl ⇒ Object
-
#title ⇒ Object
def load_datasources return if @datasources_loaded==true @ats = ATS.find_by_id(@asset_id,true) if @ats==nil @ats.load_metadata @gsa = Search.search(:start_date=>“01/01/2000”).results.first if @gsa==nil.
- #url ⇒ Object
- #user ⇒ Object
Methods inherited from IActivity
Constructor Details
#initialize(iactivity, preload_data = false) ⇒ Activity
data is a GSA object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/services/activity.rb', line 35 def initialize(iactivity,preload_data=false) @datasources_loaded=false if iactivity.source==:gsa @gsa = iactivity elsif iactivity.source==:ats @ats = iactivity else @primary_source = iactivity end # if data.respond_to?('source') # @ats = gsa if data.source == :ats # @gsa = gsa if data['source'] == :gsa # @primary = gsa if data.source == :primary # # @asset_id = @ats.asset_id if @ats!=nil # @asset_id = @gsa.asset_id if @gsa!=nil # @asset_id = @primary.asset_id if @primary!=nil # # load_datasources if preload_data # end end |
Instance Attribute Details
#ats ⇒ Object
Returns the value of attribute ats.
31 32 33 |
# File 'lib/services/activity.rb', line 31 def ats @ats end |
#datasources_loaded ⇒ Object (readonly)
Returns the value of attribute datasources_loaded.
32 33 34 |
# File 'lib/services/activity.rb', line 32 def datasources_loaded @datasources_loaded end |
#gsa ⇒ Object
Returns the value of attribute gsa.
31 32 33 |
# File 'lib/services/activity.rb', line 31 def gsa @gsa end |
#primary ⇒ Object
Returns the value of attribute primary.
31 32 33 |
# File 'lib/services/activity.rb', line 31 def primary @primary end |
Class Method Details
.find(data) ⇒ Object
Examples Adding the asset type id will improve performance Activity.find_by_asset_id(:asset_id => “A9EF9D79-F859-4443-A9BB-91E1833DF2D5”, :asset_type_id => “EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65”) Activity.find_by_asset_id(:asset_id => “A9EF9D79-F859-4443-A9BB-91E1833DF2D5”)
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/services/activity.rb', line 486 def self.find(data) data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new if data.has_key?(:substitutionUrl) and data.has_key?(:asset_type_id) puts "look up data form the original source" if data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID || data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID2 return Activity.new(RegCenter.find_by_id(data[:substitutionUrl])) elsif data[:asset_type_id]==ACTIVE_WORKS_ASSET_TYPE_ID return Activity.new(ActiveWorks.find_by_id(data[:substitutionUrl])) else return Activity.new(ATS.find_by_id(@asset_id)) end elsif data.has_key?(:asset_id) @asset_id = data[:asset_id] begin return Activity.new(ATS.find_by_id(@asset_id)) rescue ATSError => e raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}" end end raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}" end |
Instance Method Details
#_address ⇒ Object
188 189 190 191 192 193 |
# File 'lib/services/activity.rb', line 188 def _address return primary_source.address unless primary_source.nil? || primary_source.address["address"].nil? return ats.address unless ats.nil? || ats.address["address"].nil? return gsa.address unless gsa.nil? || gsa.address["address"].nil? return nil end |
#_asset_id ⇒ Object
287 288 289 290 291 292 |
# File 'lib/services/activity.rb', line 287 def _asset_id return primary_source.asset_id unless primary_source.nil? || primary_source.asset_id.nil? return ats.asset_id unless ats.nil? || ats.asset_id.nil? return gsa.asset_id unless gsa.nil? || gsa.asset_id.nil? return nil end |
#_asset_type_id ⇒ Object
301 302 303 304 305 306 |
# File 'lib/services/activity.rb', line 301 def _asset_type_id return primary_source.asset_type_id unless primary_source.nil? || primary_source.asset_type_id.nil? return ats.asset_type_id unless ats.nil? || ats.asset_type_id.nil? return gsa.asset_type_id unless gsa.nil? || gsa.asset_type_id.nil? return nil end |
#_categories ⇒ Object
174 175 176 177 178 179 |
# File 'lib/services/activity.rb', line 174 def _categories return primary_source.categories unless primary_source.nil? || primary_source.categories.length==0 return ats.categories unless ats.nil? || ats.categories.length==0 return gsa.categories unless gsa.nil? || gsa.categories.length==0 return [] end |
#_category ⇒ Object
259 260 261 262 263 264 |
# File 'lib/services/activity.rb', line 259 def _category return primary_source.category unless primary_source.nil? || primary_source.category.nil? return ats.category unless ats.nil? || ats.category.nil? return gsa.category unless gsa.nil? || gsa.category.nil? return nil end |
#_desc ⇒ Object
273 274 275 276 277 278 |
# File 'lib/services/activity.rb', line 273 def _desc return primary_source.desc unless primary_source.nil? || primary_source.desc.nil? return ats.desc unless ats.nil? || ats.desc.nil? return gsa.desc unless gsa.nil? || gsa.desc.nil? return nil end |
#_end_date ⇒ Object
231 232 233 234 235 236 |
# File 'lib/services/activity.rb', line 231 def _end_date return primary_source.end_date unless primary_source.nil? || primary_source.end_date.nil? return ats.end_date unless ats.nil? || ats.end_date.nil? return gsa.end_date unless gsa.nil? || gsa.end_date.nil? return nil end |
#_end_time ⇒ Object
245 246 247 248 249 250 |
# File 'lib/services/activity.rb', line 245 def _end_time return primary_source.end_time unless primary_source.nil? || primary_source.end_time.nil? return ats.end_time unless ats.nil? || ats.end_time.nil? return gsa.end_time unless gsa.nil? || gsa.end_time.nil? return nil end |
#_start_date ⇒ Object
202 203 204 205 206 207 |
# File 'lib/services/activity.rb', line 202 def _start_date return primary_source.start_date unless primary_source.nil? || primary_source.start_date.nil? return ats.start_date unless ats.nil? || ats.start_date.nil? return gsa.start_date unless gsa.nil? || gsa.start_date.nil? return nil end |
#_start_time ⇒ Object
216 217 218 219 220 221 |
# File 'lib/services/activity.rb', line 216 def _start_time return primary_source.start_time unless primary_source.nil? || primary_source.start_time.nil? return ats.start_time unless ats.nil? || ats.start_time.nil? return gsa.start_time unless gsa.nil? || gsa.start_time.nil? return nil end |
#_title ⇒ Object
140 141 142 |
# File 'lib/services/activity.rb', line 140 def _title primary_source.title || ats.title || gsa.title || nil end |
#_url ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/services/activity.rb', line 151 def _url #prefer seo a2 url first, then non seo a2 url, then primary url sources = [ats,primary_source,gsa] sources.each do |source| return source.url if source.url.downcase.index("www.active.com") && !source.url.downcase.index("detail") end sources.each do |source| return source.url if source.url.downcase.index("www.active.com") end return primary_source.url unless primary_source.nil? return ats.url unless ats.nil? return gsa.url unless gsa.nil? return nil end |
#_user ⇒ Object
425 426 427 428 429 430 431 432 433 434 |
# File 'lib/services/activity.rb', line 425 def _user u = User.new # If GSA doesn't have the email ATS should u.email = @gsa.user.email || ats.user.email || primary_source.user.email || nil # First name is only in ATS but GSA has a username that is kept in first_name u.first_name = ats.user.first_name || @gsa.user.first_name || nil # Last name is only found in ATS u.last_name = ats.user.last_name || nil u end |
#address ⇒ Object
181 182 183 184 185 186 |
# File 'lib/services/activity.rb', line 181 def address return @primary_source.address if primary_loaded? return @ats.address if ats_loaded? return @gsa.address if gsa_loaded? return nil end |
#asset_id ⇒ Object
280 281 282 283 284 285 |
# File 'lib/services/activity.rb', line 280 def asset_id return @primary_source.asset_id if primary_loaded? return @ats.asset_id if ats_loaded? return @gsa.asset_id if gsa_loaded? return nil end |
#asset_id=(value) ⇒ Object
id within a system
309 310 311 312 |
# File 'lib/services/activity.rb', line 309 def asset_id=(value) @gsa.asset_id # @asset_id = (value.class==Array) ? value[0] : value end |
#asset_type_id ⇒ Object
294 295 296 297 298 299 |
# File 'lib/services/activity.rb', line 294 def asset_type_id return @primary_source.asset_type_id if primary_loaded? return @ats.asset_type_id if ats_loaded? return @gsa.asset_type_id if gsa_loaded? return nil end |
#ats_loaded? ⇒ Boolean
106 107 108 109 |
# File 'lib/services/activity.rb', line 106 def ats_loaded? return true if @ats false end |
#categories ⇒ Object
167 168 169 170 171 172 |
# File 'lib/services/activity.rb', line 167 def categories return primary_source.categories if primary_loaded? return ats.categories if ats_loaded? return gsa.categories if gsa_loaded? return [] end |
#category ⇒ Object
252 253 254 255 256 257 |
# File 'lib/services/activity.rb', line 252 def category return @primary_source.category if primary_loaded? return @ats.category if ats_loaded? return @gsa.category if gsa_loaded? return nil end |
#contact_email ⇒ Object
448 449 450 451 452 453 454 455 |
# File 'lib/services/activity.rb', line 448 def contact_email return @primary.contact_email unless @primary.nil? load_datasources return @ats.contact_email unless @ats.nil? return @gsa.contact_email unless @gsa.nil? return @contact_email if @contact_email return nil end |
#contact_name ⇒ Object
439 440 441 442 443 444 445 446 |
# File 'lib/services/activity.rb', line 439 def contact_name return @primary.contact_name unless @primary.nil? load_datasources return @ats.contact_name unless @ats.nil? return @gsa.contact_name unless @gsa.nil? return @contact_name if @contact_name return nil end |
#desc ⇒ Object
266 267 268 269 270 271 |
# File 'lib/services/activity.rb', line 266 def desc return @primary_source.desc if primary_loaded? return @ats.desc if ats_loaded? return @gsa.desc if gsa_loaded? return nil end |
#end_date ⇒ Object
224 225 226 227 228 229 |
# File 'lib/services/activity.rb', line 224 def end_date return @primary_source.end_date if primary_loaded? return @ats.end_date if ats_loaded? return @gsa.end_date if gsa_loaded? return nil end |
#end_time ⇒ Object
238 239 240 241 242 243 |
# File 'lib/services/activity.rb', line 238 def end_time return @primary_source.end_time if primary_loaded? return @ats.end_time if ats_loaded? return @gsa.end_time if gsa_loaded? return nil end |
#event_image_url ⇒ Object
332 333 334 |
# File 'lib/services/activity.rb', line 332 def event_image_url end |
#full_address ⇒ Object
end returns the best address possible by loading other data sources
-
if the primary data source is unknow (ex asset_type_id is unknow ) we will return the GSA address.
-
if no address but we have lat/lng we’ll do a reverse look up
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/services/activity.rb', line 389 def full_address @primary.address # 3. MOVE TO A PRIVATE METHOD OR A NEW CLASS # if (returned_address["lat"]=="") # #geocode # geocode_url="" # if returned_address["zip"]!="" && returned_address["zip"]!="00000" # geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?z=#{returned_address["zip"]}" # elsif returned_address["city"]!="" && returned_address["state"]!="" # geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?c=#{returned_address["city"]}&s=#{returned_address["state"]}" # end # puts "geocode_url: #{geocode_url}" # if geocode_url!="" # require 'open-uri' # begin # Nokogiri::XML(open(geocode_url)).root.children.each do |node| # returned_address["lat"]=node.content if node.name=="Latitude" # returned_address["lng"]=node.content if node.name=="Longitude" # returned_address["city"]=Validators.valid_state(node.content) if node.name=="City" && returned_address["city"]=="" # returned_address["zip"]=node.content if node.name=="ZipCode" && returned_address["zip"]=="" # returned_address["state"]=node.content if node.name=="StateCode" && returned_address["state"]=="" # end # rescue # puts { "[GEO ERROR] #{geocode_url}" } # end # # end # end end |
#gsa_loaded? ⇒ Boolean
111 112 113 114 |
# File 'lib/services/activity.rb', line 111 def gsa_loaded? return true if @gsa false end |
#online_registration ⇒ Object
The asset type id lets us know what system is came from
315 316 317 318 319 320 321 |
# File 'lib/services/activity.rb', line 315 def online_registration if @gsa return @gsa.online_registration else return false end end |
#origin ⇒ Object
todo remove
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/services/activity.rb', line 63 def origin if @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID || @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID2 return "RegCenter id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}" elsif @gsa.asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID return "ActiveWorks id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}" elsif @gsa.asset_type_id == LOCAL_ASSET_TYPE_ID return "Local id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}" else return "Undefined id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}" end end |
#primary_category ⇒ Object
323 324 325 326 327 328 329 330 |
# File 'lib/services/activity.rb', line 323 def primary_category return @primary.primary_category unless @primary.nil? load_datasources return @ats.primary_category unless @ats.nil? return @gsa.primary_category unless @gsa.nil? return @primary_category if @primary_category return categories.first end |
#primary_loaded? ⇒ Boolean
activity.rb:80: warning: else without rescue is useless return true if @primary_source else false
101 102 103 104 |
# File 'lib/services/activity.rb', line 101 def primary_loaded? return true if @primary_source false end |
#primary_source ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/services/activity.rb', line 91 def primary_source return @primary_source if @primary_source if asset_type_id == REG_CENTER_ASSET_TYPE_ID || asset_type_id == REG_CENTER_ASSET_TYPE_ID2 return @primary_source = RegCenter.find_by_id(substitutionUrl) elsif asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID return @primary_source = ActiveWorks.find_by_id(substitutionUrl) end end |
#regristration_status ⇒ Object
reg-unavailable – No online registration reg-not-open – Online registration is available, but is not currently open reg-closed – The registration deadline has passed reg-open – Registration is currently open
470 471 472 473 474 475 476 477 478 |
# File 'lib/services/activity.rb', line 470 def regristration_status if @gsa.asset_type_id == "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65" Net::HTTP.get URI.parse("http://apij.active.com/regcenter/event/#{@gsa.substitutionUrl}/regstatus") elsif @gsa.asset_type_id == "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1" Net::HTTP.get URI.parse("http://apij.active.com/activeworks/event/#{@gsa.asset_id}/regstatus") else 'reg-open' end end |
#source ⇒ Object
59 60 61 |
# File 'lib/services/activity.rb', line 59 def source :active end |
#start_date ⇒ Object
195 196 197 198 199 200 |
# File 'lib/services/activity.rb', line 195 def start_date return @primary_source.start_date if primary_loaded? return @ats.start_date if ats_loaded? return @gsa.start_date if gsa_loaded? return nil end |
#start_time ⇒ Object
209 210 211 212 213 214 |
# File 'lib/services/activity.rb', line 209 def start_time return @primary_source.start_time if primary_loaded? return @ats.start_time if ats_loaded? return @gsa.start_time if gsa_loaded? return nil end |
#substitutionUrl ⇒ Object
458 459 460 461 462 463 464 |
# File 'lib/services/activity.rb', line 458 def substitutionUrl return @gsa.substitutionUrl if !@gsa.nil? return @ats.substitutionUrl if !@ats.nil? return @primary.substitutionUrl if !@primary.nil? return nil end |
#title ⇒ Object
def load_datasources
return if @datasources_loaded==true
@ats = ATS.find_by_id(@asset_id,true) if @ats==nil
@ats.
@gsa = Search.search({:asset_id=>@asset_id, :start_date=>"01/01/2000"}).results.first if @gsa==nil
if @primary==nil
if @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID || @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID2
@primary= RegCenter.find_by_id(@ats.substitutionUrl)
elsif @ats.asset_type_id==ACTIVE_WORKS_ASSET_TYPE_ID
@primary= ActiveWorks.find_by_id(@ats.substitutionUrl)
end
end
@datasources_loaded=true
end
133 134 135 136 137 138 |
# File 'lib/services/activity.rb', line 133 def title return @primary_source.title if primary_loaded? return @ats.title if ats_loaded? return @gsa.title if gsa_loaded? return nil end |
#url ⇒ Object
144 145 146 147 148 149 |
# File 'lib/services/activity.rb', line 144 def url return @primary_source.url if primary_loaded? return @ats.url if ats_loaded? return @gsa.url if gsa_loaded? return nil end |
#user ⇒ Object
419 420 421 422 423 |
# File 'lib/services/activity.rb', line 419 def user return @gsa.user if !@gsa.nil? return @ats.user if !@ats.nil? return @primary.user if !@primary.nil? end |