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,167 +0,0 @@
1
- require 'nokogiri'
2
- require 'open-uri'
3
-
4
- module Active
5
- module Services
6
-
7
- class ActiveWorksError < StandardError; end
8
-
9
- class ActiveWorks < IActivity
10
-
11
- attr_accessor :asset_type_id
12
-
13
- def initialize(data={})
14
- # need to hold on to original data
15
- @data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new
16
- @api_data_loaded = false
17
- @asset_type_id = Activity::ACTIVE_WORKS_ASSET_TYPE_ID
18
- end
19
-
20
- def source
21
- :active_works
22
- end
23
-
24
- def asset_id
25
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("id")
26
- @data["eventDetailDto"]["id"]
27
- end
28
- end
29
-
30
-
31
- def title
32
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("name")
33
- @data["eventDetailDto"]["name"]
34
- end
35
- end
36
-
37
- def event_image_url
38
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("logoUrl")
39
- @data["eventDetailDto"]["logoUrl"]
40
- end
41
- end
42
-
43
- def url
44
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("registrationUrl")
45
- @data["eventDetailDto"]["registrationUrl"]
46
- end
47
- end
48
-
49
- def categories
50
- [@data["eventDetailDto"]["channels"]]
51
- end
52
-
53
- def primary_category
54
- categories.first
55
- end
56
-
57
- def address
58
- @address = validated_address({
59
- :address => @data["eventDetailDto"]["addressLine1"],
60
- :city => @data["eventDetailDto"]["addressCity"],
61
- :state => @data["eventDetailDto"]["state"],
62
- :zip => @data["eventDetailDto"]["addressPostalCode"],
63
- :country => @data["eventDetailDto"]["countryName"]
64
- })
65
- end
66
-
67
- def start_date
68
- DateTime.parse @data["eventDetailDto"]["startDateTimeWithTZ"] if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("startDateTimeWithTZ")
69
- end
70
-
71
- def start_time
72
- start_date
73
- end
74
-
75
- def end_date
76
- DateTime.parse @data["eventDetailDto"]["endDateTime"] if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("endDateTime")
77
- end
78
-
79
- def end_time
80
- end_date
81
- end
82
-
83
- def contact_name
84
- nil
85
- end
86
-
87
- def contact_email
88
- nil
89
- end
90
-
91
- def user
92
- User.new
93
- end
94
-
95
- def category
96
- primary_category
97
- end
98
-
99
- def desc
100
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("description")
101
- sanitize( @data["eventDetailDto"]["description"] )
102
- end
103
- end
104
-
105
- def registration_url
106
- if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("registrationUrl")
107
- @data["eventDetailDto"]["registrationUrl"]
108
- end
109
- end
110
-
111
- # Finds an active works event by substitution url or returns nil
112
- def self.find_by_id(id)
113
- begin
114
- doc = Nokogiri::XML(open("http://apij.active.com/activeworks/event/#{id}"))
115
- ActiveWorks.new( Hash.from_xml(doc.to_s) )
116
- rescue
117
- # raise ActiveWorksError, "Couldn't find ActiveWorks activity with the id of #{id}"
118
- return nil
119
- end
120
- end
121
-
122
- private
123
- # def self.get_asset_metadata(id)
124
- # c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService?wsdl")
125
- # c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
126
- # r = c.get_asset_metadata do |soap|
127
- # soap.namespace = "http://api.asset.services.active.com"
128
- # soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
129
- # end
130
- # puts "==========="
131
- # puts r.to_hash[:get_asset_metadata_response][:out].inspect
132
- # return r
133
- # end
134
- #
135
- # def self.get_asset_by_id(id)
136
- # puts "loading ATS"
137
- # c = Savon::Client.new("http://api.amp.active.com/asset-service/services/AssetService")
138
- # c.request.headers["Api-Key"] = "6npky9t57235vps5cetm3s7k"
139
- # r = c.get_asset_by_id! do |soap|
140
- # soap.namespace = "http://api.asset.services.active.com"
141
- # soap.body = "<context><userId></userId><applicationId></applicationId></context><assetId>#{id}</assetId>"
142
- # end
143
- # return r
144
- # end
145
- #
146
- # def load_metadata
147
- # puts "loading ATS metadata"
148
- # metadata = ATS.get_asset_metadata(@asset_id)
149
- # @data.merge! Hash.from_xml(metadata.to_hash[:get_asset_metadata_response][:out])["importSource"]["asset"]
150
- # @metadata_loaded=true
151
- # end
152
-
153
- def get_app_api
154
- # puts "loading active works api"
155
- begin
156
- doc = Nokogiri::XML(open("http://apij.active.com/activeworks/event/#{@data[:id]}"))
157
- @data.merge! Hash.from_xml doc.to_s
158
- @api_data_loaded=true
159
- rescue
160
- raise ActiveWorksError, "Couldn't find ActiveWorks activity with the id of #{id}"
161
- return
162
- end
163
- end
164
-
165
- end # end ats
166
- end
167
- end
@@ -1,512 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- module Active
4
- module Services
5
-
6
- class ActivityFindError < StandardError; end
7
-
8
- class Activity < IActivity
9
-
10
- # EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65 reg
11
- # 3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6 reg2
12
- # FB27C928-54DB-4ECD-B42F-482FC3C8681F ActiveNet US or Canada
13
- # 732A256E-2A25-4A02-81B3-769615CAA7A4 Active Net US or Canada
14
- # EC6E96A5-6900-4A0E-8B83-9AA935F45A73 Local
15
- # DFAA997A-D591-44CA-9FB7-BF4A4C8984F1 ActiveWorks
16
-
17
- # ecffc8b6-51ed-43af-82d3-540e607e5af5 Search Assets (This is a generic page (currently hosts Class Assets, Tournaments, and Swim Schools). This data comes from ATS.)
18
- # 71D917DE-FA90-448A-90DA-C8852F7E03E2 tennislink.usta.com Tournaments (Tennis Tournaments, don’t know much about this one.)
19
- # 2b22b4e6-5aa4-44d7-bf06-f7a71f9fa8a6 AW Camps (These are Foundations Camps pages. They have a SOAP service.)
20
- # 2ba50aba-080e-4e3d-a01c-1b4f56648a2e Asset Quality DB - Thriva (These are Thriva Camps. This data come from ATS.)
21
-
22
- REG_CENTER_ASSET_TYPE_ID = "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
23
- REG_CENTER_ASSET_TYPE_ID2 = "3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6"
24
- ACTIVE_WORKS_ASSET_TYPE_ID = "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
25
- LOCAL_ASSET_TYPE_ID = "EC6E96A5-6900-4A0E-8B83-9AA935F45A73"
26
- THRIVA = "2ba50aba-080e-4e3d-a01c-1b4f56648a2e"
27
- AW_CAMPS = "2b22b4e6-5aa4-44d7-bf06-f7a71f9fa8a6"
28
- TENNIS_TOURNAMENTS = "71D917DE-FA90-448A-90DA-C8852F7E03E2"
29
- GENERIC_SEARCH = "ecffc8b6-51ed-43af-82d3-540e607e5af5"
30
-
31
- attr_accessor :primary, :gsa, :ats
32
- attr_reader :datasources_loaded
33
-
34
- # data is a GSA object
35
- def initialize(iactivity,preload_data=false)
36
- @datasources_loaded=false
37
-
38
- if iactivity.source==:gsa
39
- @gsa = iactivity
40
- elsif iactivity.source==:ats
41
- @ats = iactivity
42
- else
43
- @primary_source = iactivity
44
- end
45
-
46
- # if data.respond_to?('source')
47
- # @ats = gsa if data.source == :ats
48
- # @gsa = gsa if data['source'] == :gsa
49
- # @primary = gsa if data.source == :primary
50
- #
51
- # @asset_id = @ats.asset_id if @ats!=nil
52
- # @asset_id = @gsa.asset_id if @gsa!=nil
53
- # @asset_id = @primary.asset_id if @primary!=nil
54
- #
55
- # load_datasources if preload_data
56
- # end
57
- end
58
-
59
- def source
60
- :active
61
- end
62
- # todo remove
63
- def origin
64
- if @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID || @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID2
65
- return "RegCenter id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
66
- elsif @gsa.asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID
67
- return "ActiveWorks id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
68
- elsif @gsa.asset_type_id == LOCAL_ASSET_TYPE_ID
69
- return "Local id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
70
- else
71
- return "Undefined id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
72
- end
73
- end
74
-
75
- def ats
76
- return @ats if @ats
77
- return @ats = ATS.find_by_id(asset_id)
78
- end
79
-
80
- def gsa
81
- return @gsa if @gsa
82
- s = Search.search({:asset_id=>asset_id, :start_date=>"01/01/2000"})
83
- if s.results.length > 0
84
- @gsa = s.results.first
85
- else
86
- nil
87
- end
88
-
89
- end
90
-
91
- def primary_source
92
- return @primary_source if @primary_source
93
- if asset_type_id == REG_CENTER_ASSET_TYPE_ID || asset_type_id == REG_CENTER_ASSET_TYPE_ID2
94
- return @primary_source = RegCenter.find_by_id(substitutionUrl)
95
- elsif asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID
96
- return @primary_source = ActiveWorks.find_by_id(substitutionUrl)
97
- end
98
- end
99
- # activity.rb:80: warning: else without rescue is useless
100
- # return true if @primary_source else false
101
- def primary_loaded?
102
- return true if @primary_source
103
- false
104
- end
105
-
106
- def ats_loaded?
107
- return true if @ats
108
- false
109
- end
110
-
111
- def gsa_loaded?
112
- return true if @gsa
113
- false
114
- end
115
-
116
- # def load_datasources
117
- # return if @datasources_loaded==true
118
- #
119
- # @ats = ATS.find_by_id(@asset_id,true) if @ats==nil
120
- # @ats.load_metadata
121
- # @gsa = Search.search({:asset_id=>@asset_id, :start_date=>"01/01/2000"}).results.first if @gsa==nil
122
- #
123
- # if @primary==nil
124
- # if @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID || @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID2
125
- # @primary= RegCenter.find_by_id(@ats.substitutionUrl)
126
- # elsif @ats.asset_type_id==ACTIVE_WORKS_ASSET_TYPE_ID
127
- # @primary= ActiveWorks.find_by_id(@ats.substitutionUrl)
128
- # end
129
- # end
130
- # @datasources_loaded=true
131
- # end
132
-
133
- def title
134
- return @primary_source.title if primary_loaded?
135
- return @ats.title if ats_loaded?
136
- return @gsa.title if gsa_loaded?
137
- return nil
138
- end
139
-
140
- def _title
141
- primary_source.title || ats.title || gsa.title || nil
142
- end
143
-
144
- def url
145
- return @primary_source.url if primary_loaded?
146
- return @ats.url if ats_loaded?
147
- return @gsa.url if gsa_loaded?
148
- return nil
149
- end
150
-
151
- def _url
152
- #prefer seo a2 url first, then non seo a2 url, then primary url
153
- sources = [ats,primary_source,gsa]
154
- sources.each do |source|
155
- return source.url if source.url.downcase.index("www.active.com") && !source.url.downcase.index("detail")
156
- end
157
- sources.each do |source|
158
- return source.url if source.url.downcase.index("www.active.com")
159
- end
160
-
161
- return primary_source.url unless primary_source.nil?
162
- return ats.url unless ats.nil?
163
- return gsa.url unless gsa.nil?
164
- return nil
165
- end
166
-
167
- def categories
168
- return primary_source.categories if primary_loaded?
169
- return ats.categories if ats_loaded?
170
- return gsa.categories if gsa_loaded?
171
- return []
172
- end
173
-
174
- def _categories
175
- return primary_source.categories unless primary_source.nil? || primary_source.categories.length==0
176
- return ats.categories unless ats.nil? || ats.categories.length==0
177
- return gsa.categories unless gsa.nil? || gsa.categories.length==0
178
- return []
179
- end
180
-
181
- def address
182
- return @primary_source.address if primary_loaded?
183
- return @ats.address if ats_loaded?
184
- return @gsa.address if gsa_loaded?
185
- return nil
186
- end
187
-
188
- def _address
189
- return primary_source.address unless primary_source.nil? || primary_source.address["address"].nil?
190
- return ats.address unless ats.nil? || ats.address["address"].nil?
191
- return gsa.address unless gsa.nil? || gsa.address["address"].nil?
192
- return nil
193
- end
194
-
195
- def start_date
196
- return @primary_source.start_date if primary_loaded?
197
- return @ats.start_date if ats_loaded?
198
- return @gsa.start_date if gsa_loaded?
199
- return nil
200
- end
201
-
202
- def _start_date
203
- return primary_source.start_date unless primary_source.nil? || primary_source.start_date.nil?
204
- return ats.start_date unless ats.nil? || ats.start_date.nil?
205
- return gsa.start_date unless gsa.nil? || gsa.start_date.nil?
206
- return nil
207
- end
208
-
209
- def start_time
210
- return @primary_source.start_time if primary_loaded?
211
- return @ats.start_time if ats_loaded?
212
- return @gsa.start_time if gsa_loaded?
213
- return nil
214
- end
215
-
216
- def _start_time
217
- return primary_source.start_time unless primary_source.nil? || primary_source.start_time.nil?
218
- return ats.start_time unless ats.nil? || ats.start_time.nil?
219
- return gsa.start_time unless gsa.nil? || gsa.start_time.nil?
220
- return nil
221
- end
222
-
223
-
224
- def end_date
225
- return @primary_source.end_date if primary_loaded?
226
- return @ats.end_date if ats_loaded?
227
- return @gsa.end_date if gsa_loaded?
228
- return nil
229
- end
230
-
231
- def _end_date
232
- return primary_source.end_date unless primary_source.nil? || primary_source.end_date.nil?
233
- return ats.end_date unless ats.nil? || ats.end_date.nil?
234
- return gsa.end_date unless gsa.nil? || gsa.end_date.nil?
235
- return nil
236
- end
237
-
238
- def end_time
239
- return @primary_source.end_time if primary_loaded?
240
- return @ats.end_time if ats_loaded?
241
- return @gsa.end_time if gsa_loaded?
242
- return nil
243
- end
244
-
245
- def _end_time
246
- return primary_source.end_time unless primary_source.nil? || primary_source.end_time.nil?
247
- return ats.end_time unless ats.nil? || ats.end_time.nil?
248
- return gsa.end_time unless gsa.nil? || gsa.end_time.nil?
249
- return nil
250
- end
251
-
252
- def category
253
- return @primary_source.category if primary_loaded?
254
- return @ats.category if ats_loaded?
255
- return @gsa.category if gsa_loaded?
256
- return nil
257
- end
258
-
259
- def _category
260
- return primary_source.category unless primary_source.nil? || primary_source.category.nil?
261
- return ats.category unless ats.nil? || ats.category.nil?
262
- return gsa.category unless gsa.nil? || gsa.category.nil?
263
- return nil
264
- end
265
-
266
- def desc
267
- return @primary_source.desc if primary_loaded?
268
- return @ats.desc if ats_loaded?
269
- return @gsa.desc if gsa_loaded?
270
- return nil
271
- end
272
-
273
- def _desc
274
- return primary_source.desc unless primary_source.nil? || primary_source.desc.nil?
275
- return ats.desc unless ats.nil? || ats.desc.nil?
276
- return gsa.desc unless gsa.nil? || gsa.desc.nil?
277
- return nil
278
- end
279
-
280
- def asset_id
281
- return @primary_source.asset_id if primary_loaded?
282
- return @ats.asset_id if ats_loaded?
283
- return @gsa.asset_id if gsa_loaded?
284
- return nil
285
- end
286
-
287
- def _asset_id
288
- return primary_source.asset_id unless primary_source.nil? || primary_source.asset_id.nil?
289
- return ats.asset_id unless ats.nil? || ats.asset_id.nil?
290
- return gsa.asset_id unless gsa.nil? || gsa.asset_id.nil?
291
- return nil
292
- end
293
-
294
- def asset_type_id
295
- return @primary_source.asset_type_id if primary_loaded?
296
- return @ats.asset_type_id if ats_loaded?
297
- return @gsa.asset_type_id if gsa_loaded?
298
- return nil
299
- end
300
-
301
- def _asset_type_id
302
- return primary_source.asset_type_id unless primary_source.nil? || primary_source.asset_type_id.nil?
303
- return ats.asset_type_id unless ats.nil? || ats.asset_type_id.nil?
304
- return gsa.asset_type_id unless gsa.nil? || gsa.asset_type_id.nil?
305
- return nil
306
- end
307
-
308
- # id within a system
309
- def asset_id=(value)
310
- @gsa.asset_id
311
- # @asset_id = (value.class==Array) ? value[0] : value
312
- end
313
- # The asset type id lets us know what system is came from
314
-
315
- def online_registration
316
- if @gsa
317
- return @gsa.online_registration
318
- else
319
- return false
320
- end
321
- end
322
-
323
- def primary_category
324
- return @primary.primary_category unless @primary.nil?
325
- load_datasources
326
- return @ats.primary_category unless @ats.nil?
327
- return @gsa.primary_category unless @gsa.nil?
328
- return @primary_category if @primary_category
329
- return categories.first
330
- end
331
-
332
- def event_image_url
333
-
334
- end
335
- # def load_master
336
- # # @ats = ATS.find_by_id(@gsa.asset_id)
337
- # # throw StandardError.new "ATS type=#{@gsa.asset_type_id} id=#{@gsa.substitutionUrl}"
338
- # # if @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID || @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID2
339
- # # throw StandardError.new "REG"
340
- # # elsif @gsa.asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID
341
- # # throw StandardError.new "WORKS"
342
- # # else
343
- # # throw StandardError.new @gsa.asset_type_id
344
- # # return false
345
- # # end
346
- # # if @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID || @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID2
347
- # # @primary= RegCenter.find_by_id(@ats.substitutionUrl)
348
- # # elsif @ats.asset_type_id==ACTIVE_WORKS_ASSET_TYPE_ID
349
- # # @primary= ActiveWorks.find_by_id(@ats.substitutionUrl)
350
- # # end
351
- #
352
- # end
353
-
354
- # returns the best address possible from the data returned by the GSA
355
- #def address
356
- # @gsa.address
357
- # returned_address = validated_address({})
358
- # returned_address = @primary.address unless (@primary.nil? || @primary.address.nil?)
359
- # load_datasources
360
- # returned_address = @ats.address unless @ats.nil?
361
- # returned_address = @gsa.address
362
- # if @gsa.address[:address] != nil #and returned_address.city and returned_address.state and returned_address.country
363
- # return returned_address
364
- # else
365
- # return nil
366
- # end
367
- # returned_address = @address if @address
368
- #
369
- # #ensure lat/lng
370
- # if (returned_address["lat"]=="")
371
- # load_datasources
372
- # if @primary.address["lat"]!=""
373
- # returned_address["lat"] = @primary.address["lat"]
374
- # returned_address["lng"] = @primary.address["lng"]
375
- # elsif @ats.address["lat"]!=""
376
- # returned_address["lat"] = @ats.address["lat"]
377
- # returned_address["lng"] = @ats.address["lng"]
378
- # elsif @gsa.address["lat"]!=""
379
- # returned_address["lat"] = @gsa.address["lat"]
380
- # returned_address["lng"] = @gsa.address["lng"]
381
- # end
382
- # end
383
- #
384
- # return returned_address
385
- #end
386
- # returns the best address possible by loading other data sources
387
- # 2. if the primary data source is unknow (ex asset_type_id is unknow ) we will return the GSA address.
388
- # 3. if no address but we have lat/lng we'll do a reverse look up
389
- def full_address
390
- @primary.address
391
- # 3. MOVE TO A PRIVATE METHOD OR A NEW CLASS
392
- # if (returned_address["lat"]=="")
393
- # #geocode
394
- # geocode_url=""
395
- # if returned_address["zip"]!="" && returned_address["zip"]!="00000"
396
- # geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?z=#{returned_address["zip"]}"
397
- # elsif returned_address["city"]!="" && returned_address["state"]!=""
398
- # geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?c=#{returned_address["city"]}&s=#{returned_address["state"]}"
399
- # end
400
- # puts "geocode_url: #{geocode_url}"
401
- # if geocode_url!=""
402
- # require 'open-uri'
403
- # begin
404
- # Nokogiri::XML(open(geocode_url)).root.children.each do |node|
405
- # returned_address["lat"]=node.content if node.name=="Latitude"
406
- # returned_address["lng"]=node.content if node.name=="Longitude"
407
- # returned_address["city"]=Validators.valid_state(node.content) if node.name=="City" && returned_address["city"]==""
408
- # returned_address["zip"]=node.content if node.name=="ZipCode" && returned_address["zip"]==""
409
- # returned_address["state"]=node.content if node.name=="StateCode" && returned_address["state"]==""
410
- # end
411
- # rescue
412
- # puts { "[GEO ERROR] #{geocode_url}" }
413
- # end
414
- #
415
- # end
416
- # end
417
- end
418
-
419
- def user
420
- return @gsa.user if !@gsa.nil?
421
- return @ats.user if !@ats.nil?
422
- return @primary.user if !@primary.nil?
423
- end
424
-
425
- def _user
426
- u = User.new
427
- # If GSA doesn't have the email ATS should
428
- u.email = @gsa.user.email || ats.user.email || primary_source.user.email || nil
429
- # First name is only in ATS but GSA has a username that is kept in first_name
430
- u.first_name = ats.user.first_name || @gsa.user.first_name || nil
431
- # Last name is only found in ATS
432
- u.last_name = ats.user.last_name || nil
433
- u
434
- end
435
-
436
-
437
-
438
-
439
- def contact_name
440
- return @primary.contact_name unless @primary.nil?
441
- load_datasources
442
- return @ats.contact_name unless @ats.nil?
443
- return @gsa.contact_name unless @gsa.nil?
444
- return @contact_name if @contact_name
445
- return nil
446
- end
447
-
448
- def contact_email
449
- return @primary.contact_email unless @primary.nil?
450
- load_datasources
451
- return @ats.contact_email unless @ats.nil?
452
- return @gsa.contact_email unless @gsa.nil?
453
- return @contact_email if @contact_email
454
- return nil
455
- end
456
-
457
-
458
- def substitutionUrl
459
- return @gsa.substitutionUrl if !@gsa.nil?
460
- return @ats.substitutionUrl if !@ats.nil?
461
- return @primary.substitutionUrl if !@primary.nil?
462
-
463
- return nil
464
- end
465
-
466
- # reg-unavailable – No online registration
467
- # reg-not-open – Online registration is available, but is not currently open
468
- # reg-closed – The registration deadline has passed
469
- # reg-open – Registration is currently open
470
- def regristration_status
471
- if @gsa.asset_type_id == "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
472
- Net::HTTP.get URI.parse("http://apij.active.com/regcenter/event/#{@gsa.substitutionUrl}/regstatus")
473
- elsif @gsa.asset_type_id == "DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
474
- Net::HTTP.get URI.parse("http://apij.active.com/activeworks/event/#{@gsa.asset_id}/regstatus")
475
- else
476
- 'reg-open'
477
- end
478
- end
479
-
480
-
481
- # Examples
482
- # Adding the asset type id will improve performance
483
- # Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5", :asset_type_id => "EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65")
484
- # Activity.find_by_asset_id(:asset_id => "A9EF9D79-F859-4443-A9BB-91E1833DF2D5")
485
- #
486
- def self.find(data)
487
- data = HashWithIndifferentAccess.new(data) || HashWithIndifferentAccess.new
488
- if data.has_key?(:substitutionUrl) and data.has_key?(:asset_type_id)
489
- puts "look up data form the original source"
490
-
491
- if data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID || data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID2
492
- return Activity.new(RegCenter.find_by_id(data[:substitutionUrl]))
493
- elsif data[:asset_type_id]==ACTIVE_WORKS_ASSET_TYPE_ID
494
- return Activity.new(ActiveWorks.find_by_id(data[:substitutionUrl]))
495
- else
496
- return Activity.new(ATS.find_by_id(@asset_id))
497
- end
498
- elsif data.has_key?(:asset_id)
499
- @asset_id = data[:asset_id]
500
- begin
501
- return Activity.new(ATS.find_by_id(@asset_id))
502
- rescue ATSError => e
503
- raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}"
504
- end
505
- end
506
- raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}"
507
-
508
- end
509
-
510
- end
511
- end
512
- end