7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/workers/workarea/orderbot/pricing_importer.rb', line 7
def perform(options = {})
return unless Orderbot.api_configured?
Orderbot::ImportLog.log('pricing') do |last_imported_at|
last_import = options[:from_updated_on] || last_imported_at
pricing_filters = {
response_model: "OrderGuideProduct",
active: true
}
pricing_response = gateway.get_pricing(pricing_filters)
raise 'get pricing error' unless pricing_response.success?
pricing_records = pricing_response.body
write_prices(pricing_records, last_import)
if pricing_response.total_pages.to_i > 1
count = 2
while count <= pricing_response.total_pages.to_i
page_filters = pricing_filters.merge(page: count)
response = gateway.get_products(page_filters)
write_prices(response.body, last_import)
count = count + 1
end
end
Workarea::Orderbot::Pricing::ImportPricing.new.perform
end
end
|