Sha256: c9cbaba9356d5bca5858854d122113d509fc5bd903ecc2930f3ace2c6d616e96

Contents?: true

Size: 1.3 KB

Versions: 22

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module FlowcommerceSpree
  # A service object to import the data for of flow.io Experience into Spree::Zones::Product
  class ImportExperiences
    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

    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

    private

    def initialize(client:, organization:, with_items: nil, refresher: Refresher.new)
      @refresher = refresher
      @client = client
      @organization = organization
      @with_items = with_items
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
flowcommerce_spree-0.0.22 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.21 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.20 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.19 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.18 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.17 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.16 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.15 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.14 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.13 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.12 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.11 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.10 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.9 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.8 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.7 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.6 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.5 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.4 app/services/flowcommerce_spree/import_experiences.rb
flowcommerce_spree-0.0.3 app/services/flowcommerce_spree/import_experiences.rb