Active 0.0.42 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +6 -0
  2. data/.irbrc +21 -0
  3. data/.rspec +1 -0
  4. data/.rvmrc +2 -0
  5. data/Active.gemspec +28 -29
  6. data/Gemfile +4 -0
  7. data/History.txt +5 -2
  8. data/{README.txt → README.md} +4 -20
  9. data/Rakefile +11 -17
  10. data/lib/Active.rb +11 -79
  11. data/lib/active/activity.rb +7 -0
  12. data/lib/active/article.rb +7 -0
  13. data/lib/active/asset.rb +205 -0
  14. data/lib/active/errors.rb +9 -0
  15. data/lib/active/query.rb +225 -0
  16. data/lib/active/result.rb +7 -0
  17. data/lib/active/results.rb +6 -0
  18. data/lib/active/training.rb +7 -0
  19. data/lib/active/version.rb +3 -0
  20. data/lib/ext/hash_extensions.rb +8 -0
  21. data/spec/asset_spec.rb +47 -0
  22. data/spec/search_spec.rb +383 -432
  23. data/spec/spec_helper.rb +23 -2
  24. metadata +113 -116
  25. data/bin/Active +0 -7
  26. data/lib/.DS_Store +0 -0
  27. data/lib/services/.DS_Store +0 -0
  28. data/lib/services/IActivity.rb +0 -39
  29. data/lib/services/_ats.rb +0 -215
  30. data/lib/services/active_works.rb +0 -167
  31. data/lib/services/activity.rb +0 -512
  32. data/lib/services/address.rb +0 -17
  33. data/lib/services/ats.rb +0 -229
  34. data/lib/services/dto/user.rb +0 -9
  35. data/lib/services/gsa.rb +0 -205
  36. data/lib/services/reg_center.rb +0 -270
  37. data/lib/services/sanitize.rb +0 -108
  38. data/lib/services/search.rb +0 -494
  39. data/lib/services/validators.rb +0 -124
  40. data/rspec-tm +0 -1
  41. data/rvmrc +0 -1
  42. data/spec/.DS_Store +0 -0
  43. data/spec/Active_spec.rb +0 -28
  44. data/spec/activeworks_spec.rb +0 -60
  45. data/spec/activity_spec.rb +0 -421
  46. data/spec/ats_spec.rb +0 -106
  47. data/spec/benchmark/search_bench.rb +0 -55
  48. data/spec/custom_matchers_spec.rb +0 -27
  49. data/spec/gsa_spec.rb +0 -210
  50. data/spec/reg_spec.rb +0 -173
  51. data/spec/search_memcached_spec.rb +0 -42
  52. data/spec/validators_spec.rb +0 -19
  53. data/test/test_Active.rb +0 -0
  54. data/version.txt +0 -1
@@ -1,17 +0,0 @@
1
- module Active
2
- module Services
3
- class AddressDeprecated
4
- attr_accessor :name, :state, :city, :state, :zip, :lat, :lng, :country
5
- def initialize(data={})
6
- @name = data[:name]
7
- @state = data[:state]
8
- @city = data[:city]
9
- @state = data[:state]
10
- @zip = data[:zip]
11
- @lat = data[:lat]
12
- @lng = data[:lng]
13
- @country = data[:country]
14
- end
15
- end
16
- end
17
- end
@@ -1,229 +0,0 @@
1
- require 'digest/sha1'
2
- module Active
3
- module Services
4
-
5
- class ATSError < StandardError; end
6
-
7
- class ATS < IActivity
8
-
9
- attr_reader :metadata_loaded
10
- # EXAMPLE Data hash
11
- # {"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. &amp; 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"}
12
- # {"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 &amp; 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"}
13
-
14
- def initialize(data={},preload_metadata=false)
15
- # need to hold on to original data
16
- @data = data
17
- @asset_id = data[:asset_id]
18
- @url = data[:url]
19
- @asset_type_id = data[:asset_type_id]
20
- @title = data[:asset_name] if data[:asset_name]
21
- @substitution_url = data[:substitution_url]
22
- # @metadata_loaded = false
23
- # load_metadata if preload_metadata
24
- end
25
-
26
- def source
27
- :ats
28
- end
29
-
30
-
31
- def title
32
- # load_metadata unless @metadata_loaded
33
- # if @data.has_key?("assetName")
34
- @data["assetName"]
35
- # else
36
- # @title
37
- # end
38
- end
39
-
40
- def url
41
- # load_metadata unless @metadata_loaded
42
- if @data.has_key?("seourl")
43
- @data["seourl"]
44
- elsif @data.has_key?("trackbackurl")
45
- @data["trackbackurl"]
46
- else
47
- @url
48
- end
49
- end
50
-
51
- def categories
52
- # load_metadata unless @metadata_loaded
53
- categories = @data["channel"]
54
- if categories.class==String
55
- [@data["channel"]]
56
- else
57
- @data["channel"]
58
- end
59
- end
60
-
61
- def address
62
- # load_metadata unless @metadata_loaded
63
- @address = validated_address({
64
- :name => @data["location"],
65
- :address => @data["address"],
66
- :city => @data["city"],
67
- :state => @data["state"],
68
- :zip => @data["zip"],
69
- :lat => @data["latitude"],
70
- :lng => @data["longitude"],
71
- :country => @data["country"]
72
- })
73
- end
74
-
75
- def start_date
76
- # load_metadata unless @metadata_loaded
77
- if @data.has_key?("startDate")
78
- if @data.has_key?("startTime")
79
- (DateTime.parse "#{@data["startDate"]} #{@data["startTime"]}")
80
- else
81
- (DateTime.parse @data["startDate"])
82
- end
83
- else
84
- nil
85
- end
86
- end
87
-
88
- def start_time
89
- start_date
90
- end
91
-
92
- def end_date
93
- # load_metadata unless @metadata_loaded
94
- if @data.has_key?("endDate")
95
- if @data.has_key?("endTime")
96
- (DateTime.parse "#{@data["endDate"]} #{@data["endTime"]}")
97
- else
98
- (DateTime.parse @data["endDate"])
99
- end
100
- else
101
- nil
102
- end
103
- end
104
-
105
- def end_time
106
- end_date
107
- end
108
-
109
-
110
- def category
111
- categories.first
112
- end
113
-
114
- def desc
115
- # load_metadata unless @metadata_loaded
116
- if @data.has_key?("allText")
117
- @data["allText"]
118
- elsif @data.has_key?("summary")
119
- @data["summary"]
120
- end
121
- end
122
-
123
- def contact_name
124
- # load_metadata unless @metadata_loaded
125
- @data["contactName"] if @data.has_key?("contactName")
126
- end
127
-
128
- def contact_email
129
- # load_metadata unless @metadata_loaded
130
- @data["contactEmail"] if @data.has_key?("contactEmail")
131
- end
132
- def contact_phone
133
- @data["contactPhone"] if @data.has_key?("contactPhone")
134
- end
135
-
136
- def substitutionUrl
137
- @data[:substitution_url]
138
- end
139
-
140
- def user
141
- email = contact_email
142
- u = User.new
143
- u.email = email if Validators.email(email)
144
- u.first_name = contact_name
145
- u.phone = contact_phone
146
- u
147
- end
148
-
149
-
150
- # EXAMPLE
151
- # lazy load the data for some_crazy_method
152
- # def some_crazy
153
- # return @some_crazy unless @some_crazy.nil?
154
- # @some_crazy = @data[:some_crazy_method_from_ats].split replace twist bla bla bla
155
- # end
156
-
157
- def self.find_by_id(id)
158
- begin
159
- c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
160
- c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
161
- r = c.get_asset_by_id! do |soap|
162
- soap.namespace = "http://api.asset.services.active.com"
163
- soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
164
- end
165
- ats = ATS.new(r.to_hash[:get_asset_by_id_response][:out])
166
- ats.load_metadata
167
-
168
- return ats
169
-
170
- rescue Savon::SOAPFault => e
171
- raise ATSError, "Couldn't find activity with the id of #{id} error #{e.inspect}"
172
- return
173
- end
174
- end
175
-
176
- def load_metadata
177
- metadata = ATS.get_asset_metadata(@asset_id)
178
- @data.merge! Hash.from_xml(metadata.to_hash[:get_asset_metadata_response][:out])["importSource"]["asset"]
179
- @metadata_loaded=true
180
- end
181
-
182
- private
183
-
184
- def self.get_asset_metadata(id)
185
- c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
186
- c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
187
- r = c.get_asset_metadata! do |soap|
188
- soap.namespace = "http://api.asset.services.active.com"
189
- soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
190
- end
191
- # puts "==========="
192
- # puts r.to_hash[:get_asset_metadata_response][:out].inspect
193
- return r
194
- end
195
-
196
- #
197
- # def self.get_asset_metadata(id)
198
- # search_hash = Digest::SHA1.hexdigest("ats_m_#{id}")
199
- # if Active.CACHE
200
- # cached_version = Active.CACHE.get(search_hash)
201
- # return cached_version if cached_version
202
- # end
203
- #
204
- # c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
205
- # c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
206
- # r = c.get_asset_metadata! do |soap|
207
- # soap.namespace = "http://api.asset.services.active.com"
208
- # soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
209
- # end
210
- # ats = ATS.new(r.to_hash[:get_asset_metadata_response][:out])
211
- # Active.CACHE.set(search_hash, ats) if Active.CACHE
212
- # return ats
213
- # end
214
-
215
- def self.get_asset_by_id(id)
216
- c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
217
- c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
218
- r = c.get_asset_by_id! do |soap|
219
- soap.namespace = "http://api.asset.services.active.com"
220
- soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
221
- end
222
- ats = ATS.new(r.to_hash[:get_asset_by_id_response][:out])
223
- return ats
224
- end
225
-
226
-
227
- end # end ats
228
- end
229
- end
@@ -1,9 +0,0 @@
1
- module Active
2
- module Services
3
-
4
- class User
5
- attr_accessor :first_name, :last_name, :email, :phone
6
- end
7
-
8
- end
9
- end
@@ -1,205 +0,0 @@
1
- module Active
2
- module Services
3
-
4
- class GSAError < StandardError; end
5
-
6
- class GSA < IActivity
7
- require 'nokogiri'
8
- require 'open-uri'
9
- # require 'active_support/core_ext/hash/'
10
-
11
- attr_accessor :asset_type_id
12
-
13
- # EXAMPLE Data hash
14
- # {"title"=>"Birds of a Feather Run | Ashland, Oregon 97520 | Thursday ...", "language"=>"en", "url"=>"http://www.active.com/running/ashland-or/birds-of-a-feather-run-2010", "escapedUrl"=>"http://www.active.com/running/ashland-or/birds-of-a-feather-run-2010", "meta"=>{"city"=>"Ashland", "assetId"=>["4365AF63-B2AE-4A98-A403-5E30EB6D2D69", "4365af63-b2ae-4a98-a403-5e30eb6d2d69"], "substitutionUrl"=>"1845585", "trackbackurl"=>"http://www.active.com/running/ashland-or/birds-of-a-feather-run-2010", "contactName"=>"Hal Koerner", "eventDate"=>"2010-09-23T00:00:00-07:00", "eventLongitude"=>"-122.5526", "eventId"=>"1845585", "zip"=>"97520", "category"=>"Activities", "latitude"=>"42.12607", "google-site-verification"=>"", "participationCriteria"=>"All", "dma"=>"Medford - Klamath Falls", "country"=>"United States", "sortDate"=>"2000-09-23", "tag"=>["event:10", "Running:10"], "lastModifiedDateTime"=>"2010-09-23 03:04:55.463", "lastModifiedDate"=>"2010-09-23", "startDate"=>"2010-09-23", "contactPhone"=>"541-201-0014", "eventState"=>"Oregon", "splitMediaType"=>"Event", "onlineDonationAvailable"=>"0", "market"=>"Medford - Klamath Falls", "assetName"=>["Birds of a Feather Run", "Birds of a Feather Run"], "seourl"=>"http://www.active.com/running/ashland-or/birds-of-a-feather-run-2010", "assetTypeId"=>"EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65", "channel"=>"Running", "endTime"=>"0:00:00", "mediaType"=>"Event", "startTime"=>"0:00:00", "description"=>"", "longitude"=>"-122.5526", "UpdateDateTime"=>"9/22/2010 11:46:24 AM", "endDate"=>"2010-09-23", "onlineMembershipAvailable"=>"0", "onlineRegistrationAvailable"=>"false", "eventZip"=>"97520", "state"=>"Oregon", "estParticipants"=>"2000", "eventURL"=>"http://sorunners.org/", "eventLatitude"=>"42.12607", "keywords"=>"Event"}, "summary"=>"... Similar Running Events. I Ran for Sudan - Maple Valley First Annual 10K/2Mile Kid's Run/Walk Maple Valley, Washington Sat, Oct 02, 2010; ... "}
15
-
16
- def initialize(json={})
17
- # need to hold on to original data
18
- @data = HashWithIndifferentAccess.new(json) || HashWithIndifferentAccess.new
19
- # self.title = @data['meta']['assetName'] || nil
20
- self.title = @data['title'] || nil
21
- end
22
-
23
- def source
24
- :gsa
25
- end
26
-
27
- def title=(value)
28
- @title = value
29
- if @title
30
- @title = @title.split("|")[0].strip if @title.include?("|")
31
- @title = @title.gsub(/<\/?[^>]*>/, "")
32
- @title = @title.gsub("...", "")
33
- end
34
- end
35
-
36
- def url
37
- if @data["meta"].has_key?("seourl")
38
- @data["meta"]["seourl"]
39
- else
40
- @data["url"]
41
- end
42
- end
43
-
44
- # def event_url
45
- # @data["meta"]["organizationWebsite"] rescue
46
- # end
47
-
48
- def categories
49
- arr = []
50
- if @data["meta"]["channel"].class==String
51
- if @data["meta"]["channel"].index(",")
52
- arr << @data["meta"]["channel"].split(",")
53
- else
54
- arr << @data["meta"]["channel"]
55
- end
56
- else
57
- arr << @data["meta"]["channel"]
58
- end
59
- arr.flatten!
60
- end
61
-
62
- def asset_id
63
- return nil unless @data["meta"] and @data["meta"]["assetId"]
64
- value = @data["meta"]["assetId"]
65
- @asset_id = (value.class==Array) ? value[0] : value
66
- end
67
-
68
- def asset_type_id
69
- return nil unless @data["meta"] and @data["meta"]["assetTypeId"]
70
- @data["meta"]["assetTypeId"]
71
- end
72
-
73
- def primary_category
74
- # do we have it in the seo url?
75
- if @data["meta"].has_key?("seourl")
76
- seo_channel = @data["meta"]["seourl"].split("/")
77
- if seo_channel.length > 2 and categories
78
- categories.each do |cat|
79
- return cat if cat.downcase==seo_channel[3].downcase
80
- end
81
- else
82
- return "unknown"
83
- end
84
- end
85
- if categories.nil?# && categories.empty?
86
- return "unknown"
87
- else
88
- return categories.first
89
- end
90
- end
91
-
92
- def address
93
- @address = HashWithIndifferentAccess.new({
94
- :name => @data["meta"]["location"],
95
- :city => @data["meta"]["city"],
96
- :lat => @data["meta"]["latitude"],
97
- :lng => @data["meta"]["longitude"],
98
- :country => @data["meta"]["country"]
99
- })
100
- @address[:address] = @data["meta"]["eventAddress"] || @data["meta"]["location"] || nil
101
- @address[:state] = @data["meta"]["eventState"] || @data["meta"]["state"]
102
- @address[:zip] = @data["meta"]["eventZip"] || @data["meta"]["zip"]
103
- @address
104
- end
105
-
106
- def start_date
107
- if @data.has_key?("meta") and @data["meta"].has_key?("eventDate")
108
- DateTime.parse( @data["meta"]["eventDate"] )
109
- elsif @data.has_key?("meta") and @data["meta"].has_key?("startDate")
110
- DateTime.parse( @data["meta"]["startDate"] )
111
- else
112
- nil
113
- end
114
- end
115
-
116
- def start_time
117
- start_date
118
- end
119
-
120
- def end_date
121
- if @data.has_key?("meta") and @data["meta"].has_key?("endDate")
122
- DateTime.parse @data["meta"]["endDate"]
123
- else
124
- nil
125
- end
126
- end
127
-
128
- def end_time
129
- end_date
130
- end
131
-
132
- def category
133
- primary_category
134
- end
135
-
136
- def last_modified
137
- @data["meta"]["lastModifiedDateTime"] if @data["meta"].has_key?("lastModifiedDateTime")
138
-
139
- end
140
-
141
- def online_registration
142
- if @data["meta"].has_key?("onlineRegistrationAvailable")
143
- (@data["meta"]["onlineRegistrationAvailable"].downcase == "true") ? true : false
144
- end
145
- end
146
-
147
- # def contact_email
148
- # if @data["meta"].has_key?("contactEmail") && !@data["meta"]["contactEmail"].blank?
149
- # @data["meta"]["contactEmail"]
150
- # end
151
- # end
152
-
153
- def desc
154
- if @data["meta"].has_key?("allText") && !@data["meta"]["allText"].blank?
155
- @data["meta"]["allText"]
156
- elsif @data["meta"].has_key?("summary") && !@data["meta"]["summary"].blank?
157
- @data["meta"]["summary"]
158
- elsif @data.has_key?("summary") && !@data["summary"].blank?
159
- @data["summary"]
160
- else
161
- ""
162
- end
163
- end
164
-
165
- def user
166
- email = @data["meta"]["contactEmail"] || nil
167
- u = User.new
168
- u.email = email if Validators.email(email)
169
- u.first_name, u.last_name = parse_contact_name(@data["meta"]["contactName"])
170
- u.phone = @data["meta"]["contactPhone"] || nil
171
- u
172
- end
173
-
174
- # substitutionUrl could be formatted like this
175
- # 1. "meta":{"substitutionUrl":"vistarecreation/registrationmain.sdi?source=showAsset.sdi&activity_id=4900"}
176
- # 2. "meta":{"substitutionUrl":"4900"}
177
- def substitutionUrl
178
- if @data["meta"].has_key?("substitutionUrl")
179
- if /activity_id=/ =~ @data["meta"]["substitutionUrl"]
180
- @data["meta"]["substitutionUrl"].split("activity_id=")[1]
181
- else
182
- @data["meta"]["substitutionUrl"]
183
- end
184
- end
185
- end
186
-
187
- private
188
- # parse_contact_name("Jonathan Spooner")
189
- # return ["Jonathan","Spooner"]
190
- # return ["Jonathan",nil]
191
- # return [nil,nil]
192
- def parse_contact_name(value)
193
- return nil,nil if value.nil?
194
- #first name is whats before the space, last name is everything else
195
- name = value.split(" ")
196
- fname= name[0]
197
- name.delete_at(0)
198
- lname = name.join(" ")
199
- return fname,lname
200
- end
201
-
202
-
203
- end
204
- end
205
- end