Class: FlowcommerceSpree::ImportExperiences

Inherits:
Object
  • Object
show all
Defined in:
app/services/flowcommerce_spree/import_experiences.rb

Overview

A service object to import the data for of flow.io Experience into Spree::Zones::Product

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(client: FlowcommerceSpree.client, organization: ORGANIZATION, with_items: nil, refresher: nil) ⇒ Object



6
7
8
# File 'app/services/flowcommerce_spree/import_experiences.rb', line 6

def self.run(client: FlowcommerceSpree.client, organization: ORGANIZATION, with_items: nil, refresher: nil)
  new(client: client, organization: organization, with_items: with_items, refresher: refresher).run
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/flowcommerce_spree/import_experiences.rb', line 10

def run
  # we have to log start, so that another process does not start while this one is running
  @refresher.log_refresh!

  @client.experiences.get(@organization, status: 'active').each do |experience|
    experience_key = experience.key
    zone = Spree::Zones::Product.find_or_initialize_by(name: experience_key.titleize)
    zone.store_flow_io_data(experience, logger: @refresher.logger)

    next @refresher.logger.info "Error: storing flow.io experience #{experience_key}" if zone.errors.any?

    ImportExperienceItems.run(zone, client: @client) if @with_items
  end

  # Log sync end time
  @refresher.log_refresh!(has_ended: true)
end