Class: Active::Services::ActiveWorks

Inherits:
IActivity
  • Object
show all
Defined in:
lib/services/active_works.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 = {}) ⇒ ActiveWorks

Returns a new instance of ActiveWorks.



13
14
15
16
17
18
# File 'lib/services/active_works.rb', line 13

def initialize(data={})
  # need to hold on to original data
  @data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new
  @api_data_loaded = false
  @asset_type_id = Activity::ACTIVE_WORKS_ASSET_TYPE_ID
end

Instance Attribute Details

#asset_type_idObject

Returns the value of attribute asset_type_id.



11
12
13
# File 'lib/services/active_works.rb', line 11

def asset_type_id
  @asset_type_id
end

Class Method Details

.find_by_id(id) ⇒ Object

Finds an active works event by substitution url or returns nil



112
113
114
115
116
117
118
119
120
# File 'lib/services/active_works.rb', line 112

def self.find_by_id(id)
  begin
    doc              = Nokogiri::XML(open("http://apij.active.com/activeworks/event/#{id}"))
    ActiveWorks.new( Hash.from_xml(doc.to_s) )
  rescue
    # raise ActiveWorksError, "Couldn't find ActiveWorks activity with the id of #{id}"
    return nil
  end
end

Instance Method Details

#addressObject



57
58
59
60
61
62
63
64
65
# File 'lib/services/active_works.rb', line 57

def address
    @address = validated_address({
      :address => @data["eventDetailDto"]["addressLine1"],
      :city    => @data["eventDetailDto"]["addressCity"],
      :state   => @data["eventDetailDto"]["state"],
      :zip     => @data["eventDetailDto"]["addressPostalCode"],
      :country => @data["eventDetailDto"]["countryName"]
    })
end

#asset_idObject



24
25
26
27
28
# File 'lib/services/active_works.rb', line 24

def asset_id
  if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("id")
    @data["eventDetailDto"]["id"]
  end
end

#categoriesObject



49
50
51
# File 'lib/services/active_works.rb', line 49

def categories
  [@data["eventDetailDto"]["channels"]]
end

#categoryObject



95
96
97
# File 'lib/services/active_works.rb', line 95

def category
  primary_category
end

#contact_emailObject



87
88
89
# File 'lib/services/active_works.rb', line 87

def contact_email
  nil
end

#contact_nameObject



83
84
85
# File 'lib/services/active_works.rb', line 83

def contact_name
  nil
end

#descObject



99
100
101
102
103
# File 'lib/services/active_works.rb', line 99

def desc
  if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("description")
    sanitize( @data["eventDetailDto"]["description"] )
  end
end

#end_dateObject



75
76
77
# File 'lib/services/active_works.rb', line 75

def end_date
  DateTime.parse @data["eventDetailDto"]["endDateTime"] if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("endDateTime")
end

#end_timeObject



79
80
81
# File 'lib/services/active_works.rb', line 79

def end_time
  end_date
end

#event_image_urlObject



37
38
39
40
41
# File 'lib/services/active_works.rb', line 37

def event_image_url
  if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("logoUrl")
    @data["eventDetailDto"]["logoUrl"]
  end
end

#primary_categoryObject



53
54
55
# File 'lib/services/active_works.rb', line 53

def primary_category
  categories.first
end

#registration_urlObject



105
106
107
108
109
# File 'lib/services/active_works.rb', line 105

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

#sourceObject



20
21
22
# File 'lib/services/active_works.rb', line 20

def source
  :active_works
end

#start_dateObject



67
68
69
# File 'lib/services/active_works.rb', line 67

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

#start_timeObject



71
72
73
# File 'lib/services/active_works.rb', line 71

def start_time
  start_date
end

#titleObject



31
32
33
34
35
# File 'lib/services/active_works.rb', line 31

def title
  if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("name")
    @data["eventDetailDto"]["name"]
  end
end

#urlObject



43
44
45
46
47
# File 'lib/services/active_works.rb', line 43

def url
  if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("registrationUrl")
    @data["eventDetailDto"]["registrationUrl"]
  end
end

#userObject



91
92
93
# File 'lib/services/active_works.rb', line 91

def user
  User.new
end