reso 0.1.0.0 → 0.1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/queued_listing.rb +8 -3
- data/lib/class_extensions.rb +2 -4
- data/lib/generators/reso/templates/create_addresses.rb +2 -2
- data/lib/generators/reso/templates/create_businesses.rb +0 -1
- data/lib/generators/reso/templates/create_enumerations.rb +4 -2
- data/lib/generators/reso/templates/create_listing_media.rb +2 -3
- data/lib/generators/reso/templates/create_listing_providers.rb +2 -1
- data/lib/generators/reso/templates/create_listings.rb +0 -43
- data/lib/generators/reso/templates/create_participants.rb +3 -3
- data/lib/mapper.rb +117 -0
- data/lib/mapper/reso.rb +83 -86
- data/lib/reso/railties/reso.rake +11 -13
- data/lib/reso/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff149e91987ac675f1b345183c70e9a1e887cac9
|
4
|
+
data.tar.gz: e01f8ebe524c4f0a61cb25ea7f0a87e8d6856ba4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fc1601255520d7219d6fa70c278a16f33d61ba1a1da68c645fe44456854b42790dceb863a26caa48d5f124288b0729b9ac4d856053533fa40e60873cc4b3d49
|
7
|
+
data.tar.gz: 2241c34f18b659df0c4f6184d91289332c72986121efd511208c3cea2d31c6bedde8923fd505b95c6f5c046c3cbce7d78ef4e0d580490a84116bf61d40b07fc6
|
@@ -8,9 +8,14 @@ class QueuedListing < ActiveRecord::Base
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def create_or_update_listing
|
11
|
-
listing = self.import.listings.
|
12
|
-
|
13
|
-
|
11
|
+
listing = self.import.listings.
|
12
|
+
eager_load(:address).
|
13
|
+
eager_load(:appliances).
|
14
|
+
eager_load(:participants).
|
15
|
+
eager_load(:photos).
|
16
|
+
find_or_initialize_by(
|
17
|
+
listing_key: mapper.unique_identifier(self)
|
18
|
+
)
|
14
19
|
if (listing.modification_timestamp != mapper.modification_timestamp(self, listing))
|
15
20
|
Mapper::RESO_LISTING_ATTRIBUTES.each do |attribute|
|
16
21
|
listing.send("#{attribute}=", mapper.send(attribute, self, listing))
|
data/lib/class_extensions.rb
CHANGED
@@ -21,16 +21,14 @@ end
|
|
21
21
|
Hash.class_eval do
|
22
22
|
def drilldown drillees
|
23
23
|
if (result = drillees.split(' ').inject(self){|res, el| res[el] ? res[el] : Hash.new })
|
24
|
-
result.present? ?
|
24
|
+
result.present? ? result.unwrap_attribute : nil
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
Array.class_eval do
|
30
30
|
def drilldown drillee
|
31
|
-
|
32
|
-
result.present? ? (result.unwrap_attribute) : nil
|
33
|
-
end
|
31
|
+
drillee.last.unwrap_attribute
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
@@ -2,7 +2,7 @@ class CreateAddresses < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
create_table :addresses, options: 'DEFAULT CHARSET=utf8' do |t|
|
4
4
|
t.string :addressable_type
|
5
|
-
t.references :addressable
|
5
|
+
t.references :addressable, index: true
|
6
6
|
|
7
7
|
t.integer :preference_order, default: 1
|
8
8
|
t.integer :address_preference_order, default: 1
|
@@ -28,6 +28,6 @@ class CreateAddresses < ActiveRecord::Migration
|
|
28
28
|
add_index :addresses, :state_or_province
|
29
29
|
add_index :addresses, :postal_code
|
30
30
|
add_index :addresses, :country
|
31
|
-
add_index :addresses,
|
31
|
+
add_index :addresses, :addressable_type
|
32
32
|
end
|
33
33
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
class CreateEnumerations < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :enumerations, options: 'DEFAULT CHARSET=utf8' do |t|
|
4
|
-
t.string :name, null: false,
|
5
|
-
t.string :type, null: false
|
4
|
+
t.string :name, null: false, limit: 128
|
5
|
+
t.string :type, null: false
|
6
6
|
|
7
7
|
t.timestamps
|
8
8
|
end
|
9
|
+
add_index :enumerations, :name
|
10
|
+
add_index :enumerations, :type
|
9
11
|
add_index :enumerations, [:name, :type]
|
10
12
|
end
|
11
13
|
end
|
@@ -4,7 +4,7 @@ class CreateListingMedia < ActiveRecord::Migration
|
|
4
4
|
t.integer :media_order_number
|
5
5
|
t.string :media_url, null: false, limit: 512
|
6
6
|
t.string :media_caption
|
7
|
-
t.
|
7
|
+
t.string :media_description
|
8
8
|
t.string :media_modification_timestamp
|
9
9
|
t.string :type, null: false
|
10
10
|
t.references :listing, index: true, null: false, foreign_key: true
|
@@ -13,7 +13,6 @@ class CreateListingMedia < ActiveRecord::Migration
|
|
13
13
|
end
|
14
14
|
add_index :listing_media, :media_order_number
|
15
15
|
add_index :listing_media, :type
|
16
|
-
add_index :listing_media, [:
|
17
|
-
add_index :listing_media, [:media_url, :media_modification_timestamp], name: "on_url_and_timestamp"
|
16
|
+
add_index :listing_media, [:media_url, :media_modification_timestamp, :media_order_number, :media_caption, :media_description], name: "on_url_and_timestamp"
|
18
17
|
end
|
19
18
|
end
|
@@ -7,6 +7,7 @@ class CreateListingProviders < ActiveRecord::Migration
|
|
7
7
|
|
8
8
|
t.timestamps
|
9
9
|
end
|
10
|
-
add_index :listing_providers,
|
10
|
+
add_index :listing_providers, :name
|
11
|
+
add_index :listing_providers, :url
|
11
12
|
end
|
12
13
|
end
|
@@ -106,49 +106,6 @@ class CreateListings < ActiveRecord::Migration
|
|
106
106
|
add_index :listings, :list_price
|
107
107
|
add_index :listings, :listing_key
|
108
108
|
add_index :listings, :mls_number
|
109
|
-
add_index :listings, :bedrooms
|
110
|
-
add_index :listings, :bathrooms
|
111
|
-
add_index :listings, :has_attic
|
112
|
-
add_index :listings, :has_barbecue_area
|
113
|
-
add_index :listings, :has_basement
|
114
|
-
add_index :listings, :has_ceiling_fan
|
115
|
-
add_index :listings, :has_deck
|
116
|
-
add_index :listings, :has_disabled_access
|
117
|
-
add_index :listings, :has_dock
|
118
|
-
add_index :listings, :has_doorman
|
119
|
-
add_index :listings, :has_double_pane_windows
|
120
|
-
add_index :listings, :has_elevator
|
121
|
-
add_index :listings, :has_fireplace
|
122
|
-
add_index :listings, :has_garden
|
123
|
-
add_index :listings, :has_gated_entry
|
124
|
-
add_index :listings, :has_greenhouse
|
125
|
-
add_index :listings, :has_hot_tub_spa
|
126
|
-
add_index :listings, :has_intercom
|
127
|
-
add_index :listings, :has_jetted_bath_tub
|
128
|
-
add_index :listings, :has_lawn
|
129
|
-
add_index :listings, :has_mother_in_law
|
130
|
-
add_index :listings, :has_patio
|
131
|
-
add_index :listings, :has_pond
|
132
|
-
add_index :listings, :has_pool
|
133
|
-
add_index :listings, :has_porch
|
134
|
-
add_index :listings, :has_rv_parking
|
135
|
-
add_index :listings, :has_sauna
|
136
|
-
add_index :listings, :has_security_system
|
137
|
-
add_index :listings, :has_skylight
|
138
|
-
add_index :listings, :has_sports_court
|
139
|
-
add_index :listings, :has_sprinkler_system
|
140
|
-
add_index :listings, :has_vaulted_ceiling
|
141
|
-
add_index :listings, :has_wet_bar
|
142
|
-
add_index :listings, :is_cable_ready
|
143
|
-
add_index :listings, :is_new_construction
|
144
|
-
add_index :listings, :is_waterfront
|
145
|
-
add_index :listings, :is_wired
|
146
|
-
add_index :listings, :living_area
|
147
|
-
add_index :listings, :lot_size
|
148
|
-
add_index :listings, :listing_date
|
149
|
-
add_index :listings, :latitude
|
150
|
-
add_index :listings, :longitude
|
151
109
|
add_index :listings, :originating_system_key
|
152
|
-
add_index :listings, :year_built
|
153
110
|
end
|
154
111
|
end
|
@@ -6,7 +6,7 @@ class CreateParticipants < ActiveRecord::Migration
|
|
6
6
|
t.string :participant_code
|
7
7
|
t.string :first_name
|
8
8
|
t.string :last_name
|
9
|
-
t.references :person,
|
9
|
+
t.references :person, index:true, foreign_key: true
|
10
10
|
t.references :participant_role, index: true
|
11
11
|
t.string :primary_contact_phone
|
12
12
|
t.string :office_phone
|
@@ -18,9 +18,9 @@ class CreateParticipants < ActiveRecord::Migration
|
|
18
18
|
|
19
19
|
t.timestamps
|
20
20
|
end
|
21
|
-
add_index :participants, :
|
21
|
+
add_index :participants, :email
|
22
22
|
add_index :participants, :participant_identifier
|
23
|
-
add_index :participants, :
|
23
|
+
add_index :participants, :participant_key
|
24
24
|
add_index :participants, [:first_name, :last_name, :email]
|
25
25
|
end
|
26
26
|
end
|
data/lib/mapper.rb
CHANGED
@@ -111,4 +111,121 @@ module Mapper
|
|
111
111
|
year_built
|
112
112
|
year_updated
|
113
113
|
)
|
114
|
+
|
115
|
+
def self.fetch_enumerations class_name
|
116
|
+
Rails.cache.fetch(class_name, expires_in: 1.hours) do
|
117
|
+
enums = {}
|
118
|
+
class_name.constantize.all.map{|item| enums[item.name] = item}
|
119
|
+
enums
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.address_types
|
124
|
+
fetch_enumerations 'AddressType'
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.appliances
|
128
|
+
fetch_enumerations 'Appliance'
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.architecture_styles
|
132
|
+
fetch_enumerations 'ArchitectureStyle'
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.area_units
|
136
|
+
fetch_enumerations 'AreaUnit'
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.cooling_systems
|
140
|
+
fetch_enumerations 'CoolingSystem'
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.currency_periods
|
144
|
+
fetch_enumerations 'CurrencyPeriod'
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.expense_categories
|
148
|
+
fetch_enumerations 'ExpenseCategory'
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.exterior_types
|
152
|
+
fetch_enumerations 'ExteriorType'
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.floor_coverings
|
156
|
+
fetch_enumerations 'FloorCovering'
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.foreclosure_statuses
|
160
|
+
fetch_enumerations 'ForeclosureStatus'
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.gender
|
164
|
+
fetch_enumerations 'Gender'
|
165
|
+
end
|
166
|
+
|
167
|
+
def self.heating_fuels
|
168
|
+
fetch_enumerations 'HeatingFuel'
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.heating_systems
|
172
|
+
fetch_enumerations 'HeatingSystem'
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.home_features
|
176
|
+
fetch_enumerations 'HomeFeature'
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.import_formats
|
180
|
+
fetch_enumerations 'ImportFormat'
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.license_categories
|
184
|
+
fetch_enumerations 'LicenseCategory'
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.listing_categories
|
188
|
+
fetch_enumerations 'ListingCategory'
|
189
|
+
end
|
190
|
+
|
191
|
+
def self.listing_statuses
|
192
|
+
fetch_enumerations 'ListingStatus'
|
193
|
+
end
|
194
|
+
|
195
|
+
def self.parkings
|
196
|
+
fetch_enumerations 'Parking'
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.participant_roles
|
200
|
+
fetch_enumerations 'ParticipantRole'
|
201
|
+
end
|
202
|
+
|
203
|
+
def self.property_sub_types
|
204
|
+
fetch_enumerations 'PropertySubType'
|
205
|
+
end
|
206
|
+
|
207
|
+
def self.property_types
|
208
|
+
fetch_enumerations 'PropertyType'
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.roof_types
|
212
|
+
fetch_enumerations 'RoofType'
|
213
|
+
end
|
214
|
+
|
215
|
+
def self.room_categories
|
216
|
+
fetch_enumerations 'RoomCategory'
|
217
|
+
end
|
218
|
+
|
219
|
+
def self.school_categories
|
220
|
+
fetch_enumerations 'SchoolCategory'
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.source_provider_categories
|
224
|
+
fetch_enumerations 'SourceProviderCategory'
|
225
|
+
end
|
226
|
+
|
227
|
+
def self.view_types
|
228
|
+
fetch_enumerations 'ViewType'
|
229
|
+
end
|
230
|
+
|
114
231
|
end
|
data/lib/mapper/reso.rb
CHANGED
@@ -34,23 +34,23 @@ module Mapper
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.appliances queued_listing, listing
|
37
|
-
|
37
|
+
get_enums(queued_listing, %w(DetailedCharacteristics Appliances Appliance))
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.architecture_style queued_listing, listing
|
41
|
-
(result =
|
41
|
+
(result = get_value(queued_listing, %w(DetailedCharacteristics ArchitectureStyle))) ? Mapper::architecture_styles[result] : nil
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.architecture_style_description queued_listing, listing
|
45
|
-
|
45
|
+
get_value(queued_listing, %w(DetailedCharacteristics ArchitectureStyle otherDescription))
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.bathrooms queued_listing, listing
|
49
|
-
|
49
|
+
get_value(queued_listing, %w(Bathrooms))
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.bedrooms queued_listing, listing
|
53
|
-
|
53
|
+
get_value(queued_listing, %w(Bedrooms))
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.brokerage queued_listing, listing
|
@@ -62,20 +62,20 @@ module Mapper
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.building_unit_count queued_listing, listing
|
65
|
-
|
65
|
+
get_value(queued_listing, %w(DetailedCharacteristics BuildingUnitCount))
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.condo_floor_num queued_listing, listing
|
69
|
-
|
69
|
+
get_value(queued_listing, %w(DetailedCharacteristics CondoFloorNum))
|
70
70
|
end
|
71
71
|
|
72
72
|
def self.cooling_systems queued_listing, listing
|
73
|
-
|
73
|
+
get_enums(queued_listing, %w(DetailedCharacteristics CoolingSystems CoolingSystem))
|
74
74
|
end
|
75
75
|
|
76
76
|
def self.county queued_listing, listing
|
77
77
|
if (get_value(queued_listing, %w(Location County)))
|
78
|
-
County.find_or_initialize_by(
|
78
|
+
county = County.find_or_initialize_by(
|
79
79
|
name: get_value(queued_listing, %w(Location County)),
|
80
80
|
state_or_province: get_value(queued_listing, %w(Address StateOrProvince)),
|
81
81
|
country: get_value(queued_listing, %w(Address Country))
|
@@ -86,45 +86,45 @@ module Mapper
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def self.currency_code queued_listing, listing
|
89
|
-
|
89
|
+
get_value(queued_listing, %w(ListPrice currencyCode))
|
90
90
|
end
|
91
91
|
|
92
92
|
def self.directions queued_listing, listing
|
93
|
-
|
93
|
+
get_value(queued_listing, %w(Location Directions))
|
94
94
|
end
|
95
95
|
|
96
96
|
def self.disclaimer queued_listing, listing
|
97
|
-
|
97
|
+
get_value(queued_listing, %w(Disclaimer))
|
98
98
|
end
|
99
99
|
|
100
100
|
def self.disclose_address queued_listing, listing
|
101
|
-
(
|
101
|
+
get_boolean_value(queued_listing, %w(DiscloseAddress))
|
102
102
|
end
|
103
103
|
|
104
104
|
def self.elevation queued_listing, listing
|
105
|
-
|
105
|
+
get_value(queued_listing, %w(Location Elevation))
|
106
106
|
end
|
107
107
|
|
108
108
|
def self.expenses queued_listing, listing
|
109
109
|
if (result = get_repeaters(queued_listing, %w(Expenses Expense)))
|
110
110
|
result.map{|item| listing.expenses.find_or_initialize_by(
|
111
|
-
expense_category:
|
112
|
-
currency_period:
|
113
|
-
expense_value:
|
111
|
+
expense_category: Mapper::expense_categories[item['ExpenseCategory']],
|
112
|
+
currency_period: Mapper::expense_categories[item['ExpenseValue']['currencyPeriod']],
|
113
|
+
expense_value: item['ExpenseValue'].unwrap_attribute
|
114
114
|
)}
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
def self.exterior_types queued_listing, listing
|
119
|
-
|
119
|
+
get_enums(queued_listing, %w(DetailedCharacteristics ExteriorTypes ExteriorType))
|
120
120
|
end
|
121
121
|
|
122
122
|
def self.floor_coverings queued_listing, listing
|
123
|
-
|
123
|
+
get_enums(queued_listing, %w(DetailedCharacteristics FloorCoverings FloorCovering))
|
124
124
|
end
|
125
125
|
|
126
126
|
def self.foreclosure_status queued_listing, listing
|
127
|
-
(result = get_value(queued_listing, %w(ForeclosureStatus))) ?
|
127
|
+
(result = get_value(queued_listing, %w(ForeclosureStatus))) ? Mapper::foreclosure_statuses[result] : nil
|
128
128
|
end
|
129
129
|
|
130
130
|
def self.franchise queued_listing, listing
|
@@ -132,15 +132,15 @@ module Mapper
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def self.full_bathrooms queued_listing, listing
|
135
|
-
|
135
|
+
get_value(queued_listing, %w(FullBathrooms))
|
136
136
|
end
|
137
137
|
|
138
138
|
def self.geocode_options queued_listing, listing
|
139
|
-
|
139
|
+
get_value(queued_listing, %w(Location GeocodeOptions))
|
140
140
|
end
|
141
141
|
|
142
142
|
def self.half_bathrooms queued_listing, listing
|
143
|
-
|
143
|
+
get_value(queued_listing, %w(HalfBathrooms))
|
144
144
|
end
|
145
145
|
|
146
146
|
def self.has_attic queued_listing, listing
|
@@ -268,11 +268,11 @@ module Mapper
|
|
268
268
|
end
|
269
269
|
|
270
270
|
def self.heating_fuels queued_listing, listing
|
271
|
-
|
271
|
+
get_enums(queued_listing, %w(DetailedCharacteristics HeatingFuels HeatingFuel)).uniq
|
272
272
|
end
|
273
273
|
|
274
274
|
def self.heating_systems queued_listing, listing
|
275
|
-
|
275
|
+
get_enums(queued_listing, %w(DetailedCharacteristics HeatingSystems HeatingSystem)).uniq
|
276
276
|
end
|
277
277
|
|
278
278
|
def self.is_cable_ready queued_listing, listing
|
@@ -292,27 +292,27 @@ module Mapper
|
|
292
292
|
end
|
293
293
|
|
294
294
|
def self.latitude queued_listing, listing
|
295
|
-
|
295
|
+
get_value(queued_listing, %w(Location Latitude))
|
296
296
|
end
|
297
297
|
|
298
298
|
def self.lead_routing_email queued_listing, listing
|
299
|
-
|
299
|
+
get_value(queued_listing, %w(LeadRoutingEmail))
|
300
300
|
end
|
301
301
|
|
302
302
|
def self.legal_description queued_listing, listing
|
303
|
-
|
303
|
+
get_value(queued_listing, %w(DetailedCharacteristics LegalDescription))
|
304
304
|
end
|
305
305
|
|
306
306
|
def self.list_price queued_listing, listing
|
307
|
-
|
307
|
+
get_value(queued_listing, %w(ListPrice))
|
308
308
|
end
|
309
309
|
|
310
310
|
def self.list_price_low queued_listing, listing
|
311
|
-
|
311
|
+
get_value(queued_listing, %w(ListPriceLow))
|
312
312
|
end
|
313
313
|
|
314
314
|
def self.listing_category queued_listing, listing
|
315
|
-
(result = get_value(queued_listing, %w(ListingCategory))) ?
|
315
|
+
(result = get_value(queued_listing, %w(ListingCategory))) ? Mapper::listing_categories[result] : nil
|
316
316
|
end
|
317
317
|
|
318
318
|
def self.listing_date queued_listing, listing
|
@@ -320,70 +320,69 @@ module Mapper
|
|
320
320
|
end
|
321
321
|
|
322
322
|
def self.listing_description queued_listing, listing
|
323
|
-
|
323
|
+
get_value(queued_listing, %w(ListingDescription))
|
324
324
|
end
|
325
325
|
|
326
326
|
def self.listing_media queued_listing, listing, elements
|
327
327
|
if (result = get_repeaters(queued_listing, elements))
|
328
328
|
result.map do |item|
|
329
|
-
|
329
|
+
listing.send(elements.last.tableize).find_or_initialize_by(
|
330
330
|
media_url: item.drilldown('MediaURL'),
|
331
|
-
media_modification_timestamp: item.drilldown('MediaModificationTimestamp')
|
332
|
-
)
|
333
|
-
media.assign_attributes({
|
331
|
+
media_modification_timestamp: item.drilldown('MediaModificationTimestamp'),
|
334
332
|
media_order_number: item.drilldown('MediaOrderNumber'),
|
335
333
|
media_caption: item.drilldown('MediaCaption'),
|
336
334
|
media_description: item.drilldown('MediaDescription')
|
337
|
-
|
338
|
-
media
|
335
|
+
)
|
339
336
|
end
|
340
337
|
end
|
341
338
|
end
|
342
339
|
|
343
340
|
# TODO: Make ListingProvider and SourceProviderCategory Provider and ProviderCategory
|
344
341
|
def self.listing_provider queued_listing, listing
|
345
|
-
(
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
342
|
+
if get_value(queued_listing, %w(ProviderName)).present?
|
343
|
+
result = ListingProvider.find_or_initialize_by(
|
344
|
+
name: get_value(queued_listing, %w(ProviderName)),
|
345
|
+
url: get_value(queued_listing, %w(ProviderURL)),
|
346
|
+
source_provider_category: Mapper::source_provider_categories[get_value(queued_listing, %w(ProviderCategory))]
|
347
|
+
)
|
348
|
+
end
|
350
349
|
end
|
351
350
|
|
352
351
|
def self.listing_status queued_listing, listing
|
353
|
-
(result = get_value(queued_listing, %w(ListingStatus))) ?
|
352
|
+
(result = get_value(queued_listing, %w(ListingStatus))) ? Mapper::listing_statuses[result] : nil
|
354
353
|
end
|
355
354
|
|
356
355
|
def self.listing_title queued_listing, listing
|
357
|
-
|
356
|
+
get_value(queued_listing, %w(ListingTitle))
|
358
357
|
end
|
359
358
|
|
360
359
|
def self.listing_url queued_listing, listing
|
361
|
-
|
360
|
+
get_value(queued_listing, %w(ListingURL))
|
362
361
|
end
|
363
362
|
|
364
363
|
def self.living_area queued_listing, listing
|
365
|
-
|
364
|
+
get_value(queued_listing, %w(LivingArea))
|
366
365
|
end
|
367
366
|
|
368
367
|
def self.living_area_unit queued_listing, listing
|
369
|
-
|
368
|
+
get_value(queued_listing, %w(LivingArea areaUnits))
|
370
369
|
end
|
371
370
|
|
372
371
|
def self.longitude queued_listing, listing
|
373
|
-
|
372
|
+
get_value(queued_listing, %w(Location Longitude))
|
374
373
|
end
|
375
374
|
|
376
375
|
def self.lot_size queued_listing, listing
|
377
|
-
|
376
|
+
get_value(queued_listing, %w(LotSize))
|
378
377
|
end
|
379
378
|
|
380
379
|
def self.mls_number queued_listing, listing
|
381
|
-
|
380
|
+
get_value(queued_listing, %w(MlsNumber))
|
382
381
|
end
|
383
382
|
|
384
383
|
def self.modification_timestamp queued_listing, listing
|
385
384
|
# TODO: Change from string to datetime
|
386
|
-
|
385
|
+
get_value(queued_listing, %w(ModificationTimestamp))
|
387
386
|
end
|
388
387
|
|
389
388
|
def self.multiple_listing_service queued_listing, listing
|
@@ -407,15 +406,15 @@ module Mapper
|
|
407
406
|
place
|
408
407
|
end
|
409
408
|
end
|
410
|
-
places ? places : []
|
409
|
+
places.present? ? places : []
|
411
410
|
end
|
412
411
|
|
413
412
|
def self.num_floors queued_listing, listing
|
414
|
-
|
413
|
+
get_value(queued_listing, %w(DetailedCharacteristics NumFloors))
|
415
414
|
end
|
416
415
|
|
417
416
|
def self.num_parking_spaces queued_listing, listing
|
418
|
-
|
417
|
+
get_value(queued_listing, %w(DetailedCharacteristics NumParkingSpaces))
|
419
418
|
end
|
420
419
|
|
421
420
|
def self.office queued_listing, listing
|
@@ -449,23 +448,26 @@ module Mapper
|
|
449
448
|
end
|
450
449
|
|
451
450
|
def self.one_quarter_bathrooms queued_listing, listing
|
452
|
-
|
451
|
+
get_value(queued_listing, %w(OneQuarterBathrooms))
|
453
452
|
end
|
454
453
|
|
455
454
|
# TODO: Figure out how to provide time zone for StartTime and EndTime
|
456
455
|
def self.open_houses queued_listing, listing
|
457
456
|
if (result = get_repeaters(queued_listing, %w(OpenHouses OpenHouse)))
|
458
|
-
result.map
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
457
|
+
result.map do |open_house|
|
458
|
+
oh = listing.open_houses.find_or_initialize_by(
|
459
|
+
showing_date: Chronic::parse(open_house['Date']).to_date,
|
460
|
+
start_time: open_house['StartTime'],
|
461
|
+
end_time: open_house['EndTime']
|
462
|
+
)
|
463
|
+
oh.description = open_house['Description']
|
464
|
+
oh
|
465
|
+
end
|
464
466
|
end
|
465
467
|
end
|
466
468
|
|
467
469
|
def self.parcel_id queued_listing, listing
|
468
|
-
|
470
|
+
get_value(queued_listing, %w(Location ParcelId))
|
469
471
|
end
|
470
472
|
|
471
473
|
# TODO: Change participant_identifier to participant_id
|
@@ -480,7 +482,7 @@ module Mapper
|
|
480
482
|
participant.assign_attributes({
|
481
483
|
participant_key: item['ParticipantKey'],
|
482
484
|
participant_identifier: item['ParticipantId'],
|
483
|
-
participant_role:
|
485
|
+
participant_role: Mapper::participant_roles[item['Role']],
|
484
486
|
primary_contact_phone: item['PrimaryContactPhone'],
|
485
487
|
office_phone: item['OfficePhone'],
|
486
488
|
fax: item['Fax'],
|
@@ -492,40 +494,40 @@ module Mapper
|
|
492
494
|
end
|
493
495
|
|
494
496
|
def self.permit_address_on_internet queued_listing, listing
|
495
|
-
(
|
497
|
+
get_boolean_value(queued_listing, %w(MarketingInformation PermitAddressOnInternet'))
|
496
498
|
end
|
497
499
|
|
498
500
|
def self.photos queued_listing, listing
|
499
|
-
|
501
|
+
listing_media(queued_listing, listing, %w(Photos Photo))
|
500
502
|
end
|
501
503
|
|
502
504
|
def self.property_sub_type queued_listing, listing
|
503
|
-
(result =
|
505
|
+
(result = get_value(queued_listing, %w(PropertySubType))) ? Mapper::property_sub_types[result] : nil
|
504
506
|
end
|
505
507
|
|
506
508
|
def self.property_sub_type_description queued_listing, listing
|
507
|
-
|
509
|
+
get_value(queued_listing, %w(PropertySubType otherDescription))
|
508
510
|
end
|
509
511
|
|
510
512
|
def self.property_type queued_listing, listing
|
511
|
-
(result =
|
513
|
+
(result = get_value(queued_listing, %w(PropertyType))) ? Mapper::property_types[result] : nil
|
512
514
|
end
|
513
515
|
|
514
516
|
def self.property_type_description queued_listing, listing
|
515
|
-
|
517
|
+
get_value(queued_listing, %w(PropertyType otherDescription))
|
516
518
|
end
|
517
519
|
|
518
520
|
def self.roof_types queued_listing, listing
|
519
|
-
|
521
|
+
get_enums(queued_listing, %w(DetailedCharacteristics RoofTypes RoofType))
|
520
522
|
end
|
521
523
|
|
522
524
|
def self.room_count queued_listing, listing
|
523
|
-
|
525
|
+
get_value(queued_listing, %w(DetailedCharacteristics RoomCount))
|
524
526
|
end
|
525
527
|
|
526
528
|
def self.rooms queued_listing, listing
|
527
529
|
if (result = get_value(queued_listing, %w(DetailedCharacteristics Rooms Room)))
|
528
|
-
rooms = Array(result).map{|room_category| Room.new(listing: listing, room_category:
|
530
|
+
rooms = Array(result).map{|room_category| Room.new(listing: listing, room_category: Mapper::room_categories[room_category])}
|
529
531
|
end
|
530
532
|
rooms ? rooms : []
|
531
533
|
end
|
@@ -541,19 +543,19 @@ module Mapper
|
|
541
543
|
end
|
542
544
|
|
543
545
|
def self.three_quarter_bathrooms queued_listing, listing
|
544
|
-
|
546
|
+
get_value(queued_listing, %w(ThreeQuarterBathrooms))
|
545
547
|
end
|
546
548
|
|
547
549
|
def self.videos queued_listing, listing
|
548
|
-
|
550
|
+
listing_media(queued_listing, listing, %w(Videos Video))
|
549
551
|
end
|
550
552
|
|
551
553
|
def self.view_types queued_listing, listing
|
552
|
-
|
554
|
+
get_enums(queued_listing, %w(DetailedCharacteristics ViewTypes ViewType))
|
553
555
|
end
|
554
556
|
|
555
557
|
def self.virtual_tours queued_listing, listing
|
556
|
-
|
558
|
+
listing_media(queued_listing, listing, %w(VirtualTours VirtualTour))
|
557
559
|
end
|
558
560
|
|
559
561
|
def self.vow_address_display queued_listing, listing
|
@@ -569,11 +571,11 @@ module Mapper
|
|
569
571
|
end
|
570
572
|
|
571
573
|
def self.year_built queued_listing, listing
|
572
|
-
|
574
|
+
get_value(queued_listing, %w(YearBuilt))
|
573
575
|
end
|
574
576
|
|
575
577
|
def self.year_updated queued_listing, listing
|
576
|
-
|
578
|
+
get_value(queued_listing, %w(DetailedCharacteristics YearUpdated))
|
577
579
|
end
|
578
580
|
|
579
581
|
# Utilities
|
@@ -612,10 +614,6 @@ module Mapper
|
|
612
614
|
(result = get_value(queued_listing, elements)) ? result.to_s.to_bool : nil
|
613
615
|
end
|
614
616
|
|
615
|
-
def self.unwrap_attribute value
|
616
|
-
value.is_a?(Hash) ? (value['__content__'] ? value['__content__'] : value) : value
|
617
|
-
end
|
618
|
-
|
619
617
|
def self.get_repeaters queued_listing, elements
|
620
618
|
if (value = get_value(queued_listing, elements[0..-2]))
|
621
619
|
(result = value.drilldown(elements.last)) ? (result.is_a?(Array) ? result : [result]) : nil
|
@@ -624,12 +622,11 @@ module Mapper
|
|
624
622
|
end
|
625
623
|
end
|
626
624
|
|
627
|
-
# TODO: Should be find_by_name not find_or_create_by_name. Remove after before_save validation.
|
628
625
|
def self.get_enums queued_listing, elements
|
629
626
|
if (result = get_repeaters(queued_listing, elements))
|
630
|
-
enums = result.map{|name| elements.last.
|
627
|
+
enums = result.map{|name| Mapper.send(elements.last.tableize)[name]}
|
631
628
|
end
|
632
|
-
enums ? enums : nil
|
629
|
+
enums ? enums.compact : nil
|
633
630
|
end
|
634
631
|
|
635
632
|
def self.get_value queued_listing, elements
|
data/lib/reso/railties/reso.rake
CHANGED
@@ -31,17 +31,13 @@ namespace :reso do
|
|
31
31
|
end
|
32
32
|
nil # Just in cases
|
33
33
|
end
|
34
|
-
|
35
|
-
def
|
34
|
+
|
35
|
+
def create_queued_listing doc, import
|
36
36
|
begin
|
37
|
-
doc = Nokogiri::XML([xml_header, xml].join).remove_namespaces!
|
38
37
|
doc.css(import.repeating_element).each do |o|
|
39
|
-
listing_data =
|
40
|
-
|
41
|
-
|
42
|
-
listing[import.repeating_element].each_pair{|key, value| listing_data[key] = value }
|
43
|
-
object.listing_data = listing_data
|
44
|
-
object.save
|
38
|
+
listing_data = {}
|
39
|
+
Hash.from_xml(o.to_xml)[import.repeating_element].each_pair{|key, value| listing_data[key] = value }
|
40
|
+
QueuedListing.create(import: import, listing_data: listing_data)
|
45
41
|
end
|
46
42
|
rescue Exception => e
|
47
43
|
puts e.inspect
|
@@ -107,17 +103,19 @@ namespace :reso do
|
|
107
103
|
# Grab the XML header to avoid namespace errors later
|
108
104
|
xml_header = get_xml_header filepath, import.repeating_element
|
109
105
|
|
110
|
-
start = Time.now
|
106
|
+
puts (start = Time.now)
|
111
107
|
puts "Starting..." if Rails.env.development?
|
112
108
|
File.foreach(filepath) do |line|
|
113
109
|
stream += line
|
114
110
|
while (from_here = stream.index(open_tag)) && (to_there = stream.index(close_tag))
|
115
111
|
xml = stream[from_here..to_there + (close_tag.length-1)]
|
116
|
-
|
112
|
+
doc = Nokogiri::XML([xml_header, xml].join).remove_namespaces!
|
113
|
+
create_queued_listing doc, import
|
117
114
|
stream.gsub!(xml, '')
|
118
|
-
if (l += 1) % 1000
|
119
|
-
puts "#{l}
|
115
|
+
if ((l += 1) % 1000).zero?
|
116
|
+
puts "#{l}\t#{l/(Time.now - start)}" if Rails.env.development?
|
120
117
|
end
|
118
|
+
GC.start if (l % 100).zero?
|
121
119
|
end
|
122
120
|
end
|
123
121
|
puts "#{l} - #{l/(Time.now - start)} listings/s" if Rails.env.development?
|
data/lib/reso/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Edlund
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|