module Active module Services class RegCenterError < StandardError; end class RegCenter < IActivity require 'nokogiri' require 'open-uri' require 'digest/sha1' attr_accessor :asset_type_id # attr_reader :metadata_loaded # EXAMPLE Data hash # {:asset_id=>"A9EF9D79-F859-4443-A9BB-91E1833DF2D5", :substitution_url=>"1878023", :asset_type_name=>"Active.com Event Registration", # :asset_name=>"Fitness, Pilates Mat Class (16 Yrs. & Up)", :url=>"http://www.active.com/page/Event_Details.htm?event_id=1878023", # :asset_type_id=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", :xmlns=>"http://api.asset.services.active.com"} def initialize(data={}) @data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new @asset_type_id = "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65" end def source :reg_center end def title if @data.has_key?("event") && @data["event"].has_key?("eventName") cleanup_reg_string(@data["event"]["eventName"]) end end def event_image_url if @data.has_key?("event") && @data["event"].has_key?("eventImageUrl") @data["event"]["eventImageUrl"] end end def url if @data.has_key?("event") && @data["event"].has_key?("eventDetailsPageUrl") @data["event"]["eventDetailsPageUrl"] elsif @data.has_key?("event") && @data["event"].has_key?("registrationUrl") @data["event"]["registrationUrl"] elsif @data.has_key?("event") && @data["event"].has_key?("eventContactUrl") @data["event"]["eventContactUrl"] end end def event_url @data[:event][:eventUrl] end def categories if @data.has_key?("event") && @data["event"].has_key?("channels") && @data["event"]["channels"]!=nil && @data["event"]["channels"].has_key?("channel") && @data["event"]["channels"]["channel"]!=nil channels = @data["event"]["channels"]["channel"] if channels.class==Array @data["event"]["channels"]["channel"].collect {|e| e["channelName"]} else #hash [channels["channelName"]] end end end def asset_id if @data.has_key?("event") && @data["event"].has_key?("assetID") @data["event"]["assetID"] end end def primary_category if @data["event"]["channels"]["channel"]!=nil channels = @data["event"]["channels"]["channel"] if channels.class==Array channels.each do |c| return c["channelName"] if c.has_key?("primaryChannel") && c["primaryChannel"]=="true" end nil else #hash return channels["channelName"] if channels.has_key?("primaryChannel") && channels["primaryChannel"]=="true" return nil end end end def address @address = validated_address({ :name => @data["event"]["eventLocation"], :address => @data["event"]["eventAddress"], :city => @data["event"]["eventCity"], :state => @data["event"]["eventState"], :zip => @data["event"]["eventZip"], :lat => @data["event"]["latitude"], :lng => @data["event"]["longitude"], :country => @data["event"]["eventCountry"] } ) end def start_date DateTime.parse @data["event"]["eventDate"] if @data.has_key?("event") && @data["event"].has_key?("eventDate") end def start_time start_date end def end_time nil end def end_date nil end # The date and time that registration closes def registration_close_date DateTime.parse(@data["event"]["eventCloseDate"]) end def category primary_category end def user email = contact_email u = User.new u.email = email if Validators.email(email) # u.first_name = @data["meta"]["contactName"] || nil # u.phone = @data["meta"]["contactPhone"] || nil u end def desc_old if @data.has_key?("event") && @data["event"].has_key?("briefDescription") ret = @data["event"]["briefDescription"] if @data["event"].has_key?("eventDetails") && @data["event"]["eventDetails"] != nil && @data["event"]["eventDetails"].has_key?("eventDetail") eventDetail = @data["event"]["eventDetails"]["eventDetail"] if eventDetail.class == Array @data["event"]["eventDetails"]["eventDetail"].each do |detail| ret +="