Class: Active::Services::RegCenter

Inherits:
IActivity
  • Object
show all
Defined in:
lib/services/reg_center.rb

Instance Attribute Summary collapse

Attributes inherited from IActivity

#data, #online_registration

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IActivity

#validated_address

Constructor Details

#initialize(data = {}) ⇒ RegCenter

EXAMPLE Data hash :substitution_url=>“1878023”, :asset_type_name=>“Active.com Event Registration”, :asset_name=>“Fitness, Pilates Mat Class (16 Yrs. & Up)”, :url=>“www.active.com/page/Event_Details.htm?event_id=1878023”, :asset_type_id=>“EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65”, :xmlns=>“api.asset.services.active.com



18
19
20
21
# File 'lib/services/reg_center.rb', line 18

def initialize(data={})
  @data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new
  @asset_type_id = "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
end

Instance Attribute Details

#asset_type_idObject

Returns the value of attribute asset_type_id.



10
11
12
# File 'lib/services/reg_center.rb', line 10

def asset_type_id
  @asset_type_id
end

Class Method Details

.find_by_id(id) ⇒ Object

EXAMPLE lazy load the data for some_crazy_method def some_crazy

return @some_crazy unless @some_crazy.nil?
@some_crazy = @data[:some_crazy_method_from_ats].split replace twist bla bla bla

end local id



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/services/reg_center.rb', line 209

def self.find_by_id(id) 
  begin
    doc  = Nokogiri::XML(open("http://apij.active.com/regcenter/event/#{id}"))
    puts "////////<br/>"
    puts doc.to_s
    puts "////////<br/>"
    reg  = RegCenter.new(Hash.from_xml(doc.to_s))
  rescue Exception => e
    raise RegCenterError, "Couldn't find Reg Center activity with the id of #{id} - #{e.inspect}"
    return nil
  end
  reg
end

.get_asset_metadata(id) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/services/reg_center.rb', line 224

def self.(id)
  c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService?wsdl")
  c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
  r = c. do |soap|
    soap.namespace = "http://api.asset.services.active.com"
    soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
  end
  puts "==========="
  puts r.to_hash[:get_asset_metadata_response][:out].inspect
  return r
end

Instance Method Details

#addressObject



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/services/reg_center.rb', line 95

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

#asset_idObject



73
74
75
76
77
# File 'lib/services/reg_center.rb', line 73

def asset_id
  if @data.has_key?("event") && @data["event"].has_key?("assetID")
    @data["event"]["assetID"]
  end
end

#categoriesObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/services/reg_center.rb', line 61

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

#categoryObject



128
129
130
# File 'lib/services/reg_center.rb', line 128

def category
  primary_category
end

#cleanup_reg_string(input) ⇒ Object



191
192
193
# File 'lib/services/reg_center.rb', line 191

def cleanup_reg_string(input)
  input.gsub("\r","").gsub("\n","").gsub("\"","""").gsub("\342\200\234","""").gsub("\342\200\235","""")
end

#contact_emailObject



195
196
197
198
199
# File 'lib/services/reg_center.rb', line 195

def contact_email
  if @data.has_key?("event") && @data["event"].has_key?("eventContactEmail")
    return @data["event"]["eventContactEmail"]
  end
end

#contentObject

Content should be a array of hashes.

{:title => “briefDescription”, :type => “html”, :content => “…” }

It should contain everything in briefDescription description and eventDetails. It should just be one big happy

TODO: Need to order this by detail TODO: Add the other description blocks to this



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/services/reg_center.rb', line 177

def content
  if @data["event"] and @data["event"]["eventDetails"] 

    if @data["event"]["eventDetails"]["eventDetail"].class == Array
      return @data["event"]["eventDetails"]["eventDetail"].collect { |obj| {:title => obj[:eventDetailsName], :content => obj[:eventDetailsValue]} } 
    else
      return [{:title => @data["event"]["eventDetails"]["eventDetail"]["eventDetailsName"],:content => @data["event"]["eventDetails"]["eventDetail"]["eventDetailsValue"]}]
    end
    
  else
    return []
  end
end

#desc(length = :full) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/services/reg_center.rb', line 161

def desc(length = :full)
  if length == :full
    @data["event"]["eventDescription"]
  else
    @data["event"]["briefDescription"]
  end
end

#desc_oldObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/services/reg_center.rb', line 141

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 +="<div><b>" + detail["eventDetailsName"] + ":</b> " + cleanup_reg_string(detail["eventDetailsValue"]) + "</div>"
        end
      else
        #hash
        ret +="<div><b>" + eventDetail["eventDetailsName"] + ":</b> " + cleanup_reg_string(eventDetail["eventDetailsValue"]) + "</div>"
      end
    end
    return ret
  elsif @data.has_key?("event") && @data["event"].has_key?("eventDescription")
    return @data["event"]["eventDescription"]
  end
end

#end_dateObject



120
121
122
# File 'lib/services/reg_center.rb', line 120

def end_date
  nil
end

#end_timeObject



116
117
118
# File 'lib/services/reg_center.rb', line 116

def end_time
  nil
end

#event_image_urlObject



33
34
35
36
37
# File 'lib/services/reg_center.rb', line 33

def event_image_url
  if @data.has_key?("event") && @data["event"].has_key?("eventImageUrl")
    @data["event"]["eventImageUrl"]
  end
end

#event_urlObject



57
58
59
# File 'lib/services/reg_center.rb', line 57

def event_url
  @data[:event][:eventUrl]
end

#primary_categoryObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/services/reg_center.rb', line 79

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

#registration_close_dateObject

The date and time that registration closes



124
125
126
# File 'lib/services/reg_center.rb', line 124

def registration_close_date
  DateTime.parse(@data["event"]["eventCloseDate"])
end

#registration_urlObject



49
50
51
52
53
54
55
# File 'lib/services/reg_center.rb', line 49

def registration_url
  if @data.has_key?("event") && @data["event"].has_key?("registrationUrl")
    @data["event"]["registrationUrl"]
  else
    ""
  end
end

#sourceObject



23
24
25
# File 'lib/services/reg_center.rb', line 23

def source
  :reg_center
end

#start_dateObject



108
109
110
# File 'lib/services/reg_center.rb', line 108

def start_date
  DateTime.parse @data["event"]["eventDate"] if @data.has_key?("event") && @data["event"].has_key?("eventDate")
end

#start_timeObject



112
113
114
# File 'lib/services/reg_center.rb', line 112

def start_time
  start_date
end

#titleObject



27
28
29
30
31
# File 'lib/services/reg_center.rb', line 27

def title
  if @data.has_key?("event") && @data["event"].has_key?("eventName")
    cleanup_reg_string(@data["event"]["eventName"])
  end
end

#urlObject



39
40
41
42
43
44
45
46
47
# File 'lib/services/reg_center.rb', line 39

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

#userObject



132
133
134
135
136
137
138
139
# File 'lib/services/reg_center.rb', line 132

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