Active 0.0.14 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/lib/Active.rb +15 -0
- data/lib/services/IActivity.rb +34 -17
- data/lib/services/active_works.rb +5 -4
- data/lib/services/activity.rb +253 -70
- data/lib/services/address.rb +17 -0
- data/lib/services/ats.rb +82 -35
- data/lib/services/gsa.rb +153 -0
- data/lib/services/reg_center.rb +43 -21
- data/lib/services/sanitize.rb +108 -0
- data/lib/services/search.rb +101 -18
- data/lib/services/search.txt +403 -0
- data/lib/services/validators.rb +91 -0
- data/spec/Active_spec.rb +24 -1
- data/spec/activeworks_spec.rb +1 -1
- data/spec/activity_spec.rb +101 -170
- data/spec/ats_spec.rb +9 -3
- data/spec/gsa_spec.rb +123 -0
- data/spec/reg_spec.rb +17 -8
- data/spec/search_memcached_spec.rb +49 -0
- data/spec/search_spec.rb +404 -356
- data/version.txt +1 -1
- metadata +30 -6
data/Rakefile
CHANGED
data/lib/Active.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Active
|
2
2
|
|
3
|
+
|
4
|
+
# attr_reader :CACHE
|
5
|
+
# attr_accessor :CACHE
|
6
|
+
|
3
7
|
# :stopdoc:
|
4
8
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
5
9
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
@@ -57,7 +61,18 @@ module Active
|
|
57
61
|
|
58
62
|
Dir.glob(search_me).sort.each {|rb| require rb}
|
59
63
|
end
|
64
|
+
|
65
|
+
# Active.memcache_host = "localhost:11211"
|
66
|
+
def self.memcache_host(url)
|
67
|
+
require 'dalli'
|
68
|
+
@CACHE = Dalli::Client.new(url)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.CACHE
|
72
|
+
@CACHE
|
73
|
+
end
|
60
74
|
|
75
|
+
|
61
76
|
end # module Active
|
62
77
|
|
63
78
|
Active.require_all_libs_relative_to(__FILE__)
|
data/lib/services/IActivity.rb
CHANGED
@@ -2,21 +2,38 @@
|
|
2
2
|
|
3
3
|
module Active
|
4
4
|
module Services
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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, :contact_name, :contact_email
|
12
|
+
|
13
|
+
attr_reader :asset_type_id
|
14
|
+
|
15
|
+
def validated_address(address)
|
16
|
+
#ensure a hash with the proper keys
|
17
|
+
returnAddress = HashWithIndifferentAccess.new({ :name =>"", :address => "", :city => "", :state => "",:zip => "", :lat => "", :lng => "", :country => ""})
|
18
|
+
returnAddress.merge!(address)
|
19
|
+
# validations
|
20
|
+
|
21
|
+
returnAddress["zip"] = Validators.valid_zip(returnAddress["zip"])
|
22
|
+
returnAddress["state"] = Validators.valid_state(returnAddress["state"])
|
23
|
+
|
24
|
+
# ensure no nil
|
25
|
+
returnAddress.keys.each do |key|
|
26
|
+
returnAddress[key] = "" if returnAddress[key].nil?
|
27
|
+
end
|
28
|
+
returnAddress
|
29
|
+
end
|
30
|
+
|
31
|
+
def source
|
32
|
+
raise StandardError, "You must override this method"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
21
37
|
end
|
22
|
-
|
38
|
+
|
39
|
+
end
|
@@ -6,6 +6,7 @@ module Active
|
|
6
6
|
class ActiveWorks < IActivity
|
7
7
|
require 'nokogiri'
|
8
8
|
require 'open-uri'
|
9
|
+
|
9
10
|
attr_accessor :asset_type_id
|
10
11
|
|
11
12
|
def initialize(data={})
|
@@ -17,7 +18,7 @@ module Active
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def source
|
20
|
-
:
|
21
|
+
:primary
|
21
22
|
end
|
22
23
|
|
23
24
|
def asset_id
|
@@ -54,13 +55,13 @@ module Active
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def address
|
57
|
-
@address = {
|
58
|
+
@address = validated_address({
|
58
59
|
:address => @data["eventDetailDto"]["addressLine1"],
|
59
60
|
:city => @data["eventDetailDto"]["addressCity"],
|
60
61
|
:state => @data["eventDetailDto"]["state"],
|
61
62
|
:zip => @data["eventDetailDto"]["addressPostalCode"],
|
62
63
|
:country => @data["eventDetailDto"]["countryName"]
|
63
|
-
}
|
64
|
+
})
|
64
65
|
end
|
65
66
|
|
66
67
|
def start_date
|
@@ -87,7 +88,7 @@ module Active
|
|
87
88
|
def desc
|
88
89
|
if @data.has_key?("eventDetailDto") && @data["eventDetailDto"].has_key?("description")
|
89
90
|
# @data["eventDetailDto"]["description"].gsub('\"','"')
|
90
|
-
@data["eventDetailDto"]["description"]
|
91
|
+
sanitize @data["eventDetailDto"]["description"]
|
91
92
|
end
|
92
93
|
end
|
93
94
|
|
data/lib/services/activity.rb
CHANGED
@@ -4,84 +4,265 @@ module Active
|
|
4
4
|
class ActivityFindError < StandardError; end
|
5
5
|
|
6
6
|
class Activity < IActivity
|
7
|
-
|
7
|
+
REG_CENTER_ASSET_TYPE_ID="EA4E860A-9DCD-4DAA-A7CA-4A77AD194F65"
|
8
|
+
REG_CENTER_ASSET_TYPE_ID2="3BF82BBE-CF88-4E8C-A56F-78F5CE87E4C6"
|
9
|
+
ACTIVE_WORKS_ASSET_TYPE_ID="DFAA997A-D591-44CA-9FB7-BF4A4C8984F1"
|
10
|
+
|
11
|
+
attr_accessor :primary, :gsa, :ats
|
12
|
+
attr_reader :datasources_loaded
|
13
|
+
|
8
14
|
# data is a GSA object
|
9
|
-
def initialize(
|
10
|
-
|
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
|
15
|
+
def initialize(gsa,preload_data=false)
|
16
|
+
@datasources_loaded=false
|
16
17
|
|
17
|
-
@
|
18
|
-
self.title = @data[:title]
|
19
|
-
@url = @data[:url]
|
20
|
-
# @asset_id = @data[:asset_id]
|
21
|
-
# @asset_type_id = @data[:asset_type_id]
|
18
|
+
@gsa = gsa
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@end_time = @data[:meta][:endTime] ||= ""
|
35
|
-
@address = {
|
36
|
-
:name => @data[:meta][:locationName],
|
37
|
-
:address => @data[:meta][:location],
|
38
|
-
:city => @data[:meta][:city],
|
39
|
-
:state => @data[:meta][:state],
|
40
|
-
:zip => @data[:meta][:zip],
|
41
|
-
:lat => @data[:meta][:latitude],
|
42
|
-
:lng => @data[:meta][:longitude],
|
43
|
-
:country => @data[:meta][:country]
|
44
|
-
}
|
45
|
-
@onlineDonationAvailable = @data[:meta][:onlineDonationAvailable]
|
46
|
-
@onlineRegistrationAvailable = @data[:meta][:onlineRegistrationAvailable]
|
47
|
-
@onlineMembershipAvailable = @data[:meta][:onlineMembershipAvailable]
|
48
|
-
end
|
49
|
-
@ats_data = {}
|
50
|
-
@full_data = {}
|
20
|
+
# if data.respond_to?('source')
|
21
|
+
# @ats = gsa if data.source == :ats
|
22
|
+
# @gsa = gsa if data['source'] == :gsa
|
23
|
+
# @primary = gsa if data.source == :primary
|
24
|
+
#
|
25
|
+
# @asset_id = @ats.asset_id if @ats!=nil
|
26
|
+
# @asset_id = @gsa.asset_id if @gsa!=nil
|
27
|
+
# @asset_id = @primary.asset_id if @primary!=nil
|
28
|
+
#
|
29
|
+
# load_datasources if preload_data
|
30
|
+
# end
|
51
31
|
end
|
52
32
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
33
|
+
def source
|
34
|
+
:active
|
35
|
+
end
|
36
|
+
|
37
|
+
def origin
|
38
|
+
if @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID || @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID2
|
39
|
+
return "RegCenter id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
|
40
|
+
elsif @gsa.asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID
|
41
|
+
return "ActiveWorks id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
|
42
|
+
else
|
43
|
+
return "Unknow id= #{@gsa.asset_id} type= #{@gsa.asset_type_id}"
|
44
|
+
end
|
45
|
+
end
|
59
46
|
|
60
|
-
def
|
61
|
-
return
|
62
|
-
|
63
|
-
|
64
|
-
|
47
|
+
def load_datasources
|
48
|
+
return if @datasources_loaded==true
|
49
|
+
|
50
|
+
@ats = ATS.find_by_id(@asset_id,true) if @ats==nil
|
51
|
+
@ats.load_metadata
|
52
|
+
@gsa = Search.search({:asset_id=>@asset_id, :start_date=>"01/01/2000"}).results.first if @gsa==nil
|
53
|
+
|
54
|
+
if @primary==nil
|
55
|
+
if @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID || @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID2
|
56
|
+
@primary= RegCenter.find_by_id(@ats.substitutionUrl)
|
57
|
+
elsif @ats.asset_type_id==ACTIVE_WORKS_ASSET_TYPE_ID
|
58
|
+
@primary= ActiveWorks.find_by_id(@ats.substitutionUrl)
|
59
|
+
end
|
65
60
|
end
|
61
|
+
@datasources_loaded=true
|
66
62
|
end
|
63
|
+
|
67
64
|
def title
|
68
|
-
return @
|
69
|
-
return
|
70
|
-
return @gsa.title unless @gsa.nil?
|
71
|
-
return @title if @title
|
72
|
-
return ""
|
65
|
+
return @gsa.title unless @gsa.nil?
|
66
|
+
return nil
|
73
67
|
end
|
74
|
-
|
68
|
+
|
69
|
+
# id within a system
|
75
70
|
def asset_id=(value)
|
76
|
-
@asset_id
|
71
|
+
@gsa.asset_id
|
72
|
+
# @asset_id = (value.class==Array) ? value[0] : value
|
73
|
+
end
|
74
|
+
# The asset type id lets us know what system is came from
|
75
|
+
def asset_type_id
|
76
|
+
return @gsa.asset_type_id unless @gsa.nil?
|
77
|
+
return nil
|
77
78
|
end
|
79
|
+
|
80
|
+
def url
|
81
|
+
#prefer seo a2 url first, then non seo a2 url, then primary url
|
82
|
+
load_datasources
|
83
|
+
sources = [@ats,@primary,@gsa]
|
84
|
+
sources.each do |source|
|
85
|
+
return source.url if source.url.downcase.index("www.active.com") && !source.url.downcase.index("detail")
|
86
|
+
end
|
87
|
+
sources.each do |source|
|
88
|
+
return source.url if source.url.downcase.index("www.active.com")
|
89
|
+
end
|
90
|
+
|
91
|
+
return @primary.url unless @primary.nil?
|
92
|
+
return @ats.url unless @ats.nil?
|
93
|
+
return @gsa.url unless @gsa.nil?
|
94
|
+
return @url if @url
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def categories
|
99
|
+
return @primary.categories unless @primary.nil?
|
100
|
+
load_datasources
|
101
|
+
return @ats.categories unless @ats.nil?
|
102
|
+
return @gsa.categories unless @gsa.nil?
|
103
|
+
return @categories if @categories
|
104
|
+
return []
|
105
|
+
end
|
106
|
+
|
78
107
|
def asset_id
|
79
|
-
return @primary.asset_id unless @primary.nil?
|
80
|
-
return @ats.asset_id unless @ats.nil?
|
81
108
|
return @gsa.asset_id unless @gsa.nil?
|
82
|
-
return @asset_id if @asset_id
|
83
109
|
return nil
|
84
110
|
end
|
111
|
+
|
112
|
+
def primary_category
|
113
|
+
return @primary.primary_category unless @primary.nil?
|
114
|
+
load_datasources
|
115
|
+
return @ats.primary_category unless @ats.nil?
|
116
|
+
return @gsa.primary_category unless @gsa.nil?
|
117
|
+
return @primary_category if @primary_category
|
118
|
+
return categories.first
|
119
|
+
end
|
120
|
+
|
121
|
+
def load_master
|
122
|
+
# @ats = ATS.find_by_id(@gsa.asset_id)
|
123
|
+
# throw StandardError.new "ATS type=#{@gsa.asset_type_id} id=#{@gsa.substitutionUrl}"
|
124
|
+
# if @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID || @gsa.asset_type_id == REG_CENTER_ASSET_TYPE_ID2
|
125
|
+
# throw StandardError.new "REG"
|
126
|
+
# elsif @gsa.asset_type_id == ACTIVE_WORKS_ASSET_TYPE_ID
|
127
|
+
# throw StandardError.new "WORKS"
|
128
|
+
# else
|
129
|
+
# throw StandardError.new @gsa.asset_type_id
|
130
|
+
# return false
|
131
|
+
# end
|
132
|
+
# if @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID || @ats.asset_type_id==REG_CENTER_ASSET_TYPE_ID2
|
133
|
+
# @primary= RegCenter.find_by_id(@ats.substitutionUrl)
|
134
|
+
# elsif @ats.asset_type_id==ACTIVE_WORKS_ASSET_TYPE_ID
|
135
|
+
# @primary= ActiveWorks.find_by_id(@ats.substitutionUrl)
|
136
|
+
# end
|
137
|
+
|
138
|
+
end
|
139
|
+
# if address is incomplete we will load data from the primary data source
|
140
|
+
# if the primary data source is unknow (ex asset_type_id is unknow ) we will return the GSA address.
|
141
|
+
# ?
|
142
|
+
def address
|
143
|
+
# returned_address = validated_address({})
|
144
|
+
# returned_address = @primary.address unless (@primary.nil? || @primary.address.nil?)
|
145
|
+
# load_datasources
|
146
|
+
# returned_address = @ats.address unless @ats.nil?
|
147
|
+
returned_address = @gsa.address
|
148
|
+
if @gsa.address[:address] != nil #and returned_address.city and returned_address.state and returned_address.country
|
149
|
+
return returned_address
|
150
|
+
else
|
151
|
+
if load_master
|
152
|
+
return @gsa.address
|
153
|
+
end
|
154
|
+
end
|
155
|
+
# returned_address = @address if @address
|
156
|
+
#
|
157
|
+
# #ensure lat/lng
|
158
|
+
# if (returned_address["lat"]=="")
|
159
|
+
# load_datasources
|
160
|
+
# if @primary.address["lat"]!=""
|
161
|
+
# returned_address["lat"] = @primary.address["lat"]
|
162
|
+
# returned_address["lng"] = @primary.address["lng"]
|
163
|
+
# elsif @ats.address["lat"]!=""
|
164
|
+
# returned_address["lat"] = @ats.address["lat"]
|
165
|
+
# returned_address["lng"] = @ats.address["lng"]
|
166
|
+
# elsif @gsa.address["lat"]!=""
|
167
|
+
# returned_address["lat"] = @gsa.address["lat"]
|
168
|
+
# returned_address["lng"] = @gsa.address["lng"]
|
169
|
+
# end
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# if (returned_address["lat"]=="")
|
173
|
+
# #geocode
|
174
|
+
# geocode_url=""
|
175
|
+
# if returned_address["zip"]!="" && returned_address["zip"]!="00000"
|
176
|
+
# geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?z=#{returned_address["zip"]}"
|
177
|
+
# elsif returned_address["city"]!="" && returned_address["state"]!=""
|
178
|
+
# geocode_url="http://api.active.com/Rest/addressvalidator/Handler.ashx?c=#{returned_address["city"]}&s=#{returned_address["state"]}"
|
179
|
+
# end
|
180
|
+
# puts "geocode_url: #{geocode_url}"
|
181
|
+
# if geocode_url!=""
|
182
|
+
# require 'open-uri'
|
183
|
+
# begin
|
184
|
+
# Nokogiri::XML(open(geocode_url)).root.children.each do |node|
|
185
|
+
# returned_address["lat"]=node.content if node.name=="Latitude"
|
186
|
+
# returned_address["lng"]=node.content if node.name=="Longitude"
|
187
|
+
# returned_address["city"]=Validators.valid_state(node.content) if node.name=="City" && returned_address["city"]==""
|
188
|
+
# returned_address["zip"]=node.content if node.name=="ZipCode" && returned_address["zip"]==""
|
189
|
+
# returned_address["state"]=node.content if node.name=="StateCode" && returned_address["state"]==""
|
190
|
+
# end
|
191
|
+
# rescue
|
192
|
+
# puts { "[GEO ERROR] #{geocode_url}" }
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# end
|
196
|
+
# end
|
197
|
+
|
198
|
+
return returned_address
|
199
|
+
end
|
200
|
+
|
201
|
+
def start_date
|
202
|
+
return @gsa.start_date unless @gsa.nil?
|
203
|
+
return nil
|
204
|
+
end
|
205
|
+
|
206
|
+
def start_time
|
207
|
+
return @gsa.start_time unless @gsa.nil?
|
208
|
+
return nil
|
209
|
+
end
|
210
|
+
|
211
|
+
def end_date
|
212
|
+
return @gsa.end_date unless @gsa.nil?
|
213
|
+
return nil
|
214
|
+
end
|
215
|
+
|
216
|
+
def end_time
|
217
|
+
return @gsa.end_time unless @gsa.nil?
|
218
|
+
return nil
|
219
|
+
end
|
220
|
+
|
221
|
+
def category
|
222
|
+
return @primary.category unless @primary.nil?
|
223
|
+
load_datasources
|
224
|
+
return @ats.category unless @ats.nil?
|
225
|
+
return @gsa.category unless @gsa.nil?
|
226
|
+
return @category if @category
|
227
|
+
primary_category
|
228
|
+
end
|
229
|
+
|
230
|
+
def contact_name
|
231
|
+
return @primary.contact_name unless @primary.nil?
|
232
|
+
load_datasources
|
233
|
+
return @ats.contact_name unless @ats.nil?
|
234
|
+
return @gsa.contact_name unless @gsa.nil?
|
235
|
+
return @contact_name if @contact_name
|
236
|
+
return nil
|
237
|
+
end
|
238
|
+
|
239
|
+
def contact_email
|
240
|
+
return @primary.contact_email unless @primary.nil?
|
241
|
+
load_datasources
|
242
|
+
return @ats.contact_email unless @ats.nil?
|
243
|
+
return @gsa.contact_email unless @gsa.nil?
|
244
|
+
return @contact_email if @contact_email
|
245
|
+
return nil
|
246
|
+
end
|
247
|
+
|
248
|
+
def desc
|
249
|
+
return @primary.desc unless @primary.nil?
|
250
|
+
load_datasources
|
251
|
+
return @ats.desc unless @ats.nil?
|
252
|
+
return @gsa.desc unless @gsa.nil?
|
253
|
+
return @desc if @desc
|
254
|
+
return nil
|
255
|
+
end
|
256
|
+
|
257
|
+
def substitutionUrl
|
258
|
+
return @primary.substitutionUrl unless @primary.nil?
|
259
|
+
load_datasources
|
260
|
+
return @ats.substitutionUrl unless @ats.nil?
|
261
|
+
return @gsa.substitutionUrl unless @gsa.nil?
|
262
|
+
return @substitutionUrl if @substitutionUrl
|
263
|
+
return nil
|
264
|
+
end
|
265
|
+
|
85
266
|
|
86
267
|
# Examples
|
87
268
|
# Adding the asset type id will improve performance
|
@@ -96,17 +277,19 @@ module Active
|
|
96
277
|
rescue ATSError => e
|
97
278
|
raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}"
|
98
279
|
end
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
elsif data.has_key?(:asset_id) and data.has_key?(:asset_type_id)
|
280
|
+
elsif data.has_key?(:substitutionUrl) and data.has_key?(:asset_type_id)
|
104
281
|
puts "look up data form the original source"
|
105
|
-
|
106
|
-
|
282
|
+
|
283
|
+
if data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID || data[:asset_type_id]==REG_CENTER_ASSET_TYPE_ID2
|
284
|
+
return Activity.new(RegCenter.find_by_id(data[:substitutionUrl]))
|
285
|
+
elsif data[:asset_type_id]==ACTIVE_WORKS_ASSET_TYPE_ID
|
286
|
+
return Activity.new(ActiveWorks.find_by_id(data[:substitutionUrl]))
|
287
|
+
end
|
288
|
+
|
107
289
|
end
|
108
|
-
|
290
|
+
raise ActivityFindError, "We could not find the activity with the asset_id of #{@asset_id}"
|
109
291
|
|
292
|
+
end
|
110
293
|
|
111
294
|
end
|
112
295
|
end
|
@@ -0,0 +1,17 @@
|
|
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
|