Active 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +6 -0
- data/bin/Active +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/Active.rb +1 -3
- data/lib/services/.DS_Store +0 -0
- data/lib/services/IActivity.rb +22 -0
- data/lib/services/activity.rb +75 -20
- data/lib/services/ats.rb +156 -0
- data/lib/services/reg_center.rb +221 -0
- data/lib/services/search.rb +83 -47
- data/spec/activity_spec.rb +85 -5
- data/spec/ats_spec.rb +57 -0
- data/spec/reg_spec.rb +53 -0
- data/spec/search_spec.rb +62 -2
- data/version.txt +1 -1
- metadata +30 -15
- data/.bnsignore +0 -19
data/Rakefile
CHANGED
@@ -13,5 +13,11 @@ Bones {
|
|
13
13
|
authors 'Jonathan Spooner, Brian Levine'
|
14
14
|
email 'jspooner [at] gmail.com'
|
15
15
|
url 'http://developer.active.com/docs/Activecom_Search_API_Reference'
|
16
|
+
gem.extras[:post_install_message] = <<-MSG
|
17
|
+
--------------------------
|
18
|
+
Welcome to Active Network
|
19
|
+
--------------------------
|
20
|
+
MSG
|
21
|
+
depend_on 'savon'
|
16
22
|
}
|
17
23
|
|
data/bin/Active
CHANGED
File without changes
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/Active.rb
CHANGED
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# require './defaultDriver.rb'
|
2
|
+
|
3
|
+
module Active
|
4
|
+
module Services
|
5
|
+
|
6
|
+
class IActivity
|
7
|
+
|
8
|
+
attr_accessor
|
9
|
+
|
10
|
+
attr_accessor :title, :url, :categories, :address, :start_date, :start_time, :end_time, :end_date, :category, :desc,
|
11
|
+
:asset_id, :asset_type_id, :data
|
12
|
+
|
13
|
+
attr_reader :asset_type_id
|
14
|
+
|
15
|
+
def source
|
16
|
+
raise StandardError, "You must override this method"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/services/activity.rb
CHANGED
@@ -1,19 +1,31 @@
|
|
1
1
|
module Active
|
2
2
|
module Services
|
3
|
-
class Activity
|
4
|
-
attr_accessor :title, :url, :categories, :address, :start_date, :start_time, :end_time, :end_date, :category, :desc,
|
5
|
-
:asset_id, :asset_type_id, :data
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
class ActivityFindError < StandardError; end
|
5
|
+
|
6
|
+
class Activity < IActivity
|
7
|
+
|
8
|
+
# data is a GSA object
|
9
|
+
def initialize(data)
|
10
|
+
if data.respond_to?(:source)
|
11
|
+
@ats = data if data.source == :ats
|
12
|
+
@gsa = data if data.source == :gsa
|
13
|
+
@primary = data if data.source == :primary
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
@data = HashWithIndifferentAccess.new(data)
|
18
|
+
self.title = @data[:title]
|
19
|
+
@url = @data[:url]
|
20
|
+
# @asset_id = @data[:asset_id]
|
21
|
+
# @asset_type_id = @data[:asset_type_id]
|
22
|
+
|
12
23
|
unless @data[:meta].nil?
|
13
|
-
@url = @data[:meta][:seourl]
|
24
|
+
@url = @data[:meta][:seourl] if @data[:meta][:seourl]
|
25
|
+
@url = @data[:meta][:trackbackurl] if @data[:meta][:trackbackurl]
|
14
26
|
self.asset_id = @data[:meta][:assetId]
|
15
|
-
|
16
|
-
@start_date = Date.parse(@data[:meta][:startDate])
|
27
|
+
@asset_type_id = @data[:meta][:assetTypeId] if @asset_type_id.nil?
|
28
|
+
@start_date = Date.parse(@data[:meta][:startDate]) if @data[:meta][:startDate]
|
17
29
|
@end_date = Date.parse(@data[:meta][:endDate]) if @data[:meta][:endDate]
|
18
30
|
self.categories = @data[:meta][:channel]
|
19
31
|
|
@@ -30,28 +42,71 @@ module Active
|
|
30
42
|
:lng => @data[:meta][:longitude],
|
31
43
|
:country => @data[:meta][:country]
|
32
44
|
}
|
45
|
+
@onlineDonationAvailable = @data[:meta][:onlineDonationAvailable]
|
46
|
+
@onlineRegistrationAvailable = @data[:meta][:onlineRegistrationAvailable]
|
47
|
+
@onlineMembershipAvailable = @data[:meta][:onlineMembershipAvailable]
|
33
48
|
end
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@onlineMembershipAvailable = @data[:meta][:onlineMembershipAvailable]
|
37
|
-
|
49
|
+
@ats_data = {}
|
50
|
+
@full_data = {}
|
38
51
|
end
|
39
52
|
|
53
|
+
# def asset_type_id
|
54
|
+
# if @asset_type_id.nil?
|
55
|
+
# ATS.find_by_id @asset_id
|
56
|
+
# end
|
57
|
+
# @asset_type_id
|
58
|
+
# end
|
59
|
+
|
40
60
|
def title=(value)
|
61
|
+
return unless value
|
41
62
|
@title = value.gsub(/<\/?[^>]*>/, "")
|
42
63
|
if value.include?("|")
|
43
64
|
@title = @title.split("|")[0].strip!
|
44
65
|
end
|
45
66
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
67
|
+
def title
|
68
|
+
return @primary.title unless @primary.nil?
|
69
|
+
return @ats.title unless @ats.nil?
|
70
|
+
return @gsa.title unless @gsa.nil?
|
71
|
+
return @title if @title
|
72
|
+
return ""
|
73
|
+
end
|
51
74
|
|
52
75
|
def asset_id=(value)
|
53
76
|
@asset_id = (value.class==Array) ? value[0] : value
|
54
77
|
end
|
78
|
+
def asset_id
|
79
|
+
return @primary.asset_id unless @primary.nil?
|
80
|
+
return @ats.asset_id unless @ats.nil?
|
81
|
+
return @gsa.asset_id unless @gsa.nil?
|
82
|
+
return @asset_id if @asset_id
|
83
|
+
return nil
|
84
|
+
end
|
85
|
+
|
86
|
+
# Examples
|
87
|
+
# Adding the asset type id will improve performance
|
88
|
+
# Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5", :asset_type_id => "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65")
|
89
|
+
# Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5")
|
90
|
+
#
|
91
|
+
def self.find_by_asset_id(data)
|
92
|
+
if data.has_key?(:asset_id) and data.has_key?(:asset_type_id) == false
|
93
|
+
@asset_id = data[:asset_id]
|
94
|
+
begin
|
95
|
+
return Activity.new(ATS.find_by_id(@asset_id))
|
96
|
+
rescue ATSError => e
|
97
|
+
raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}"
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
elsif data.has_key?(:asset_id) and data.has_key?(:asset_type_id)
|
104
|
+
puts "look up data form the original source"
|
105
|
+
# TODO look up data form the original source"
|
106
|
+
return Activity.new(ATS.find_by_id(@asset_id))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
55
110
|
|
56
111
|
end
|
57
112
|
end
|
data/lib/services/ats.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
module Active
|
2
|
+
module Services
|
3
|
+
|
4
|
+
class ATSError < StandardError; end
|
5
|
+
|
6
|
+
class ATS < IActivity
|
7
|
+
|
8
|
+
attr_reader :metadata_loaded
|
9
|
+
# EXAMPLE Data hash
|
10
|
+
# {"destinationID"=>"", "assetId"=>"A9EF9D79-F859-4443-A9BB-91E1833DF2D5", "substitutionUrl"=>"1878023", "city"=>"Antioch", "contactName"=>"City of Antioch", "trackbackurl"=>"http://www.active.com/page/Event_Details.htm?event_id=1878023&assetId=A9EF9D79-F859-4443-A9BB-91E1833DF2D5", "category"=>"Activities", "zip"=>"94531", "userCommentText"=>nil, "location"=>"Multi-use Room (prewett) - Prewett Family Park & Center", "latitude"=>"37.95761", :asset_id=>"A9EF9D79-F859-4443-A9BB-91E1833DF2D5", "searchWeight"=>"1", "country"=>"United States", "participationCriteria"=>"All", "dma"=>"San Francisco - Oakland - San Jose", "isSearchable"=>"true", :asset_name=>"Fitness, Pilates Mat Class (16 Yrs. & Up)", :substitution_url=>"1878023", :asset_type_id=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "row"=>"1", "image1"=>"http://www.active.com/images/events/hotrace.gif", "startDate"=>"2010-09-13", "contactPhone"=>"925-779-7070", :asset_type_name=>"Active.com Event Registration", "onlineDonationAvailable"=>"0", "avgUserRating"=>nil, "market"=>"San Francisco - Oakland - San Jose", "assetTypeId"=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "assetName"=>"Fitness, Pilates Mat Class (16 Yrs. & Up)", "channel"=>"Not Specified", "seourl"=>"http://www.active.com/not-specified-recware-activities/antioch-ca/fitness-pilates-mat-class-16-yrs-and-up-2010", :xmlns=>"http://api.asset.services.active.com", :url=>"http://www.active.com/page/Event_Details.htm?event_id=1878023", "mediaType"=>"Recware Activities", "startTime"=>"18:15:00", "endTime"=>"18:15:00", "contactEmail"=>"dadams@ci.antioch.ca.us", "eventResults"=>nil, "longitude"=>"-121.7936", "endDate"=>"2010-09-13", "onlineRegistrationAvailable"=>"true", "onlineMembershipAvailable"=>"0", "state"=>"California"}
|
11
|
+
# {"destinationID"=>"", "assetId"=>"D9A22F33-8A14-4175-8D5B-D11578212A98", "substitutionUrl"=>"1847738", "city"=>"Encino", "contactName"=>"Lilliane Ballesteros", "trackbackurl"=>"http://www.active.com/page/Event_Details.htm?event_id=1847738&assetId=D9A22F33-8A14-4175-8D5B-D11578212A98", "category"=>"Activities", "zip"=>"91406", "userCommentText"=>nil, "location"=>"Balboa Park/Lake Balboa", "latitude"=>"34.19933", :asset_id=>"D9A22F33-8A14-4175-8D5B-D11578212A98", "searchWeight"=>"1", "country"=>"United States", "participationCriteria"=>"All", "dma"=>"Los Angeles", "isSearchable"=>"1", :asset_name=>"2nd Annual weSPARK 10K Run & 5K Run Walk", :substitution_url=>"1847738", :asset_type_id=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "row"=>"1", "image1"=>"http://www.active.com/images/events/hotrace.gif", "startDate"=>"2010-11-14", "contactPhone"=>"818-906-3022", :asset_type_name=>"Active.com Event Registration", "onlineDonationAvailable"=>"0", "avgUserRating"=>nil, "market"=>"Los Angeles", "assetTypeId"=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "assetName"=>"2nd Annual weSPARK 10K Run & 5K Run Walk", "channel"=>["Running", "Walking"], "seourl"=>"http://www.active.com/running/encino-ca/2nd-annual-wespark-10k-run-and-5k-run-walk-2010", :xmlns=>"http://api.asset.services.active.com", :url=>"http://www.active.com/page/Event_Details.htm?event_id=1847738", "mediaType"=>["Event", "Event\\10K", "Event\\5K"], "startTime"=>"8:00:00", "endTime"=>"8:00:00", "contactEmail"=>"lilliane@wespark.org", "eventResults"=>nil, "longitude"=>"-118.4924", "endDate"=>"2010-11-14", "onlineRegistrationAvailable"=>"1", "onlineMembershipAvailable"=>"0", "state"=>"California", "estParticipants"=>"1400", "eventURL"=>"http://www.wespark.org"}
|
12
|
+
|
13
|
+
def initialize(data={})
|
14
|
+
# need to hold on to original data
|
15
|
+
@data = data || {}
|
16
|
+
@asset_id = data[:asset_id]
|
17
|
+
@url = data[:url]
|
18
|
+
@asset_id_type = data[:asset_type_id]
|
19
|
+
@title = data[:asset_name] if data[:asset_name]
|
20
|
+
@substitution_url = data[:substitution_url]
|
21
|
+
@metadata_loaded = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def source
|
25
|
+
:ats
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def title
|
30
|
+
load_metadata unless @metadata_loaded
|
31
|
+
if @data.has_key?("assetName")
|
32
|
+
@data["assetName"]
|
33
|
+
else
|
34
|
+
@title
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def url
|
40
|
+
load_metadata unless @metadata_loaded
|
41
|
+
if @data.has_key?("seourl")
|
42
|
+
@data["seourl"]
|
43
|
+
elsif @data.has_key?("trackbackurl")
|
44
|
+
@data["trackbackurl"]
|
45
|
+
else
|
46
|
+
@url
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def categories
|
51
|
+
load_metadata unless @metadata_loaded
|
52
|
+
@data["channel"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def address
|
56
|
+
load_metadata unless @metadata_loaded
|
57
|
+
@address = {
|
58
|
+
:name => @data["location"],
|
59
|
+
:address => @data["address"],
|
60
|
+
:city => @data["city"],
|
61
|
+
:state => @data["state"],
|
62
|
+
:zip => @data["zip"],
|
63
|
+
:lat => @data["latitude"],
|
64
|
+
:lng => @data["longitude"],
|
65
|
+
:country => @data["country"]
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def start_date
|
70
|
+
load_metadata unless @metadata_loaded
|
71
|
+
if @data.has_key? ("startDate")
|
72
|
+
(DateTime.parse @data["startDate"]).to_date
|
73
|
+
else
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def start_time
|
79
|
+
load_metadata unless @metadata_loaded
|
80
|
+
@data["startTime"]
|
81
|
+
end
|
82
|
+
|
83
|
+
def end_time
|
84
|
+
load_metadata unless @metadata_loaded
|
85
|
+
@data["endTime"]
|
86
|
+
end
|
87
|
+
|
88
|
+
def end_date
|
89
|
+
load_metadata unless @metadata_loaded
|
90
|
+
DateTime.parse @data["endDate"] if @data.has_key? ("endDate")
|
91
|
+
end
|
92
|
+
|
93
|
+
def category
|
94
|
+
load_metadata unless @metadata_loaded
|
95
|
+
@data["channel"]
|
96
|
+
end
|
97
|
+
|
98
|
+
def desc
|
99
|
+
load_metadata unless @metadata_loaded
|
100
|
+
if @data.has_key? ("allText")
|
101
|
+
@data["allText"]
|
102
|
+
elsif @data.has_key? ("summary")
|
103
|
+
@data["summary"]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
# EXAMPLE
|
109
|
+
# lazy load the data for some_crazy_method
|
110
|
+
# def some_crazy
|
111
|
+
# return @some_crazy unless @some_crazy.nil?
|
112
|
+
# @some_crazy = @data[:some_crazy_method_from_ats].split replace twist bla bla bla
|
113
|
+
# end
|
114
|
+
|
115
|
+
def self.find_by_id(id)
|
116
|
+
begin
|
117
|
+
r = self.get_asset_by_id(id)
|
118
|
+
return ATS.new(r.to_hash[:get_asset_by_id_response][:out])
|
119
|
+
rescue Savon::SOAPFault => e
|
120
|
+
raise ATSError, "Couldn't find activity with the id of #{id}"
|
121
|
+
return
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
def self.get_asset_metadata(id)
|
127
|
+
c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService?wsdl")
|
128
|
+
c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
|
129
|
+
r = c.get_asset_metadata do |soap|
|
130
|
+
soap.namespace = "http://api.asset.services.active.com"
|
131
|
+
soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
|
132
|
+
end
|
133
|
+
puts "==========="
|
134
|
+
puts r.to_hash[:get_asset_metadata_response][:out].inspect
|
135
|
+
return r
|
136
|
+
end
|
137
|
+
|
138
|
+
def self.get_asset_by_id(id)
|
139
|
+
c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
|
140
|
+
c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
|
141
|
+
r = c.get_asset_by_id! do |soap|
|
142
|
+
soap.namespace = "http://api.asset.services.active.com"
|
143
|
+
soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
|
144
|
+
end
|
145
|
+
return r
|
146
|
+
end
|
147
|
+
|
148
|
+
def load_metadata
|
149
|
+
metadata = ATS.get_asset_metadata(@asset_id)
|
150
|
+
@data.merge! Hash.from_xml(metadata.to_hash[:get_asset_metadata_response][:out])["importSource"]["asset"]
|
151
|
+
@metadata_loaded=true
|
152
|
+
end
|
153
|
+
|
154
|
+
end # end ats
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
module Active
|
2
|
+
module Services
|
3
|
+
|
4
|
+
class RegCenterError < StandardError; end
|
5
|
+
|
6
|
+
class RegCenter < IActivity
|
7
|
+
require 'nokogiri'
|
8
|
+
require 'open-uri'
|
9
|
+
|
10
|
+
attr_reader :metadata_loaded
|
11
|
+
# EXAMPLE Data hash
|
12
|
+
# {:asset_id=>"A9EF9D79-F859-4443-A9BB-91E1833DF2D5", :substitution_url=>"1878023", :asset_type_name=>"Active.com Event Registration",
|
13
|
+
# :asset_name=>"Fitness, Pilates Mat Class (16 Yrs. & Up)", :url=>"http://www.active.com/page/Event_Details.htm?event_id=1878023",
|
14
|
+
# :asset_type_id=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", :xmlns=>"http://api.asset.services.active.com"}
|
15
|
+
|
16
|
+
def initialize(data={})
|
17
|
+
# need to hold on to original data
|
18
|
+
@data = data || {}
|
19
|
+
@asset_id = data[:asset_id]
|
20
|
+
@url = data[:url]
|
21
|
+
@asset_id_type = data[:asset_type_id]
|
22
|
+
@title = data[:asset_name] if data[:asset_name]
|
23
|
+
@substitution_url = data[:substitution_url]
|
24
|
+
@metadata_loaded = false
|
25
|
+
@api_data_loaded = false
|
26
|
+
get_app_api
|
27
|
+
end
|
28
|
+
|
29
|
+
def source
|
30
|
+
:reg_center
|
31
|
+
end
|
32
|
+
|
33
|
+
def title
|
34
|
+
get_app_api unless @api_data_loaded
|
35
|
+
if @data.has_key?("event") && @data["event"].has_key?("eventName")
|
36
|
+
cleanup_reg_string(@data["event"]["eventName"])
|
37
|
+
else
|
38
|
+
load_metadata unless @metadata_loaded
|
39
|
+
if @data.has_key?("assetName")
|
40
|
+
@data["assetName"]
|
41
|
+
else
|
42
|
+
@title
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def event_image_url
|
48
|
+
get_app_api unless @api_data_loaded
|
49
|
+
if @data.has_key?("event") && @data["event"].has_key?("eventImageUrl")
|
50
|
+
@data["event"]["eventImageUrl"]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def url
|
55
|
+
# best info is not in API call
|
56
|
+
load_metadata unless @metadata_loaded
|
57
|
+
if @data.has_key?("seourl")
|
58
|
+
@data["seourl"]
|
59
|
+
elsif @data.has_key?("trackbackurl")
|
60
|
+
@data["trackbackurl"]
|
61
|
+
else
|
62
|
+
@url
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def categories
|
67
|
+
get_app_api unless @api_data_loaded
|
68
|
+
if @data["event"]["channels"]["channel"]!=nil
|
69
|
+
@data["event"]["channels"]["channel"].collect {|e| e["channelName"]}
|
70
|
+
else
|
71
|
+
load_metadata unless @metadata_loaded
|
72
|
+
@data["channel"]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def primary_category
|
77
|
+
get_app_api unless @api_data_loaded
|
78
|
+
if @data["event"]["channels"]["channel"]!=nil
|
79
|
+
@data["event"]["channels"]["channel"].each do |c|
|
80
|
+
return c["channelName"] if c.has_key?("primaryChannel")
|
81
|
+
end
|
82
|
+
else
|
83
|
+
categories.first
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def address
|
88
|
+
get_app_api unless @api_data_loaded
|
89
|
+
if @data.has_key?("event") && @data["event"].has_key?("eventAddress") && !@data["event"]["eventAddress"].blank?
|
90
|
+
@address = {
|
91
|
+
:name => @data["event"]["eventLocation"],
|
92
|
+
:address => @data["event"]["eventAddress"],
|
93
|
+
:city => @data["event"]["eventCity"],
|
94
|
+
:state => @data["event"]["eventState"],
|
95
|
+
:zip => @data["event"]["eventZip"],
|
96
|
+
:lat => @data["event"]["latitude"],
|
97
|
+
:lng => @data["event"]["longitude"],
|
98
|
+
:country => @data["event"]["eventCountry"]
|
99
|
+
}
|
100
|
+
else
|
101
|
+
load_metadata unless @metadata_loaded
|
102
|
+
@address = {
|
103
|
+
:name => @data["location"],
|
104
|
+
:address => @data["address"],
|
105
|
+
:city => @data["city"],
|
106
|
+
:state => @data["state"],
|
107
|
+
:zip => @data["zip"],
|
108
|
+
:lat => @data["latitude"],
|
109
|
+
:lng => @data["longitude"],
|
110
|
+
:country => @data["country"]
|
111
|
+
}
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def start_date
|
116
|
+
load_metadata unless @metadata_loaded
|
117
|
+
DateTime.parse @data["startDate"] if @data.has_key? ("startDate")
|
118
|
+
end
|
119
|
+
|
120
|
+
def start_time
|
121
|
+
load_metadata unless @metadata_loaded
|
122
|
+
@data["startTime"]
|
123
|
+
end
|
124
|
+
|
125
|
+
def end_time
|
126
|
+
load_metadata unless @metadata_loaded
|
127
|
+
@data["endTime"]
|
128
|
+
end
|
129
|
+
|
130
|
+
def end_date
|
131
|
+
load_metadata unless @metadata_loaded
|
132
|
+
DateTime.parse @data["endDate"] if @data.has_key? ("endDate")
|
133
|
+
end
|
134
|
+
|
135
|
+
def category
|
136
|
+
primary_category
|
137
|
+
end
|
138
|
+
|
139
|
+
def desc
|
140
|
+
get_app_api unless @api_data_loaded
|
141
|
+
if @data.has_key?("event") && @data["event"].has_key?("briefDescription")
|
142
|
+
ret=@data["event"]["briefDescription"]
|
143
|
+
if data["event"].has_key?("eventDetails")
|
144
|
+
data["event"]["eventDetails"]["eventDetail"].each do |detail|
|
145
|
+
ret +="<div><b>" + detail["eventDetailsName"] + ":</b> " + cleanup_reg_string(detail["eventDetailsValue"]) + "</div>"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
ret
|
149
|
+
else
|
150
|
+
load_metadata unless @metadata_loaded
|
151
|
+
if @data.has_key? ("allText")
|
152
|
+
@data["allText"]
|
153
|
+
elsif @data.has_key? ("summary")
|
154
|
+
@data["summary"]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def cleanup_reg_string(input)
|
160
|
+
input.gsub("\r","").gsub("\n","").gsub("\"","""").gsub("\342\200\234","""").gsub("\342\200\235","""")
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
# EXAMPLE
|
165
|
+
# lazy load the data for some_crazy_method
|
166
|
+
# def some_crazy
|
167
|
+
# return @some_crazy unless @some_crazy.nil?
|
168
|
+
# @some_crazy = @data[:some_crazy_method_from_ats].split replace twist bla bla bla
|
169
|
+
# end
|
170
|
+
|
171
|
+
def self.find_by_id(id)
|
172
|
+
begin
|
173
|
+
r = self.get_asset_by_id(id)
|
174
|
+
return RegCenter.new(r.to_hash[:get_asset_by_id_response][:out])
|
175
|
+
rescue Savon::SOAPFault => e
|
176
|
+
raise RegCenterError, "Couldn't find activity with the id of #{id}"
|
177
|
+
return
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
182
|
+
def self.get_asset_metadata(id)
|
183
|
+
c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService?wsdl")
|
184
|
+
c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
|
185
|
+
r = c.get_asset_metadata do |soap|
|
186
|
+
soap.namespace = "http://api.asset.services.active.com"
|
187
|
+
soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
|
188
|
+
end
|
189
|
+
puts "==========="
|
190
|
+
puts r.to_hash[:get_asset_metadata_response][:out].inspect
|
191
|
+
return r
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.get_asset_by_id(id)
|
195
|
+
puts "loading ATS"
|
196
|
+
c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
|
197
|
+
c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
|
198
|
+
r = c.get_asset_by_id! do |soap|
|
199
|
+
soap.namespace = "http://api.asset.services.active.com"
|
200
|
+
soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
|
201
|
+
end
|
202
|
+
return r
|
203
|
+
end
|
204
|
+
|
205
|
+
def load_metadata
|
206
|
+
puts "loading ATS metadata"
|
207
|
+
metadata = ATS.get_asset_metadata(@asset_id)
|
208
|
+
@data.merge! Hash.from_xml(metadata.to_hash[:get_asset_metadata_response][:out])["importSource"]["asset"]
|
209
|
+
@metadata_loaded=true
|
210
|
+
end
|
211
|
+
|
212
|
+
def get_app_api
|
213
|
+
puts "loading reg center api"
|
214
|
+
doc = Nokogiri::XML(open("http://apij.active.com/regcenter/event/#{@substitution_url}"))
|
215
|
+
@data.merge! Hash.from_xml doc.to_s
|
216
|
+
@api_data_loaded=true
|
217
|
+
end
|
218
|
+
|
219
|
+
end # end ats
|
220
|
+
end
|
221
|
+
end
|