Sha256: 5674906a931497aef584b7f1ed19934e2eb63324723444406f992440440b9835

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

require 'workarea'
require 'workarea/storefront'
require 'workarea/admin'

require 'workarea/emarsys/engine'
require 'workarea/emarsys/version'
require 'workarea/google_product_feed'

module Workarea
  module Emarsys
    def self.credentials
      (Rails.application.secrets.emarsys || {}).deep_symbolize_keys
    end

    def self.sales_data_credentials
      (Rails.application.secrets.emarsys_sales || {}).deep_symbolize_keys
    end

    def self.secret_key
      credentials[:secret_key]
    end

    def self.user_name
      credentials[:user_name]
    end

    def self.merchant_id
      Workarea.config.merchant_id
    end

    def self.api_token
      sales_data_credentials[:api_token]
    end

    def self.config
      Workarea.config.emarsys
    end

    # Conditionally use the real gateway when secrets are present.
    # Otherwise, use the bogus gateway.
    #
    # @return [Emarsys::Gateway]
    def self.gateway
      if credentials.present?
        Emarsys::Gateway.new(secret_key, user_name, { test: !Workarea.config.emarsys_production_api })
      else
        Emarsys::BogusGateway.new
      end
    end

    def self.sales_data_gateway
      if credentials.present?
        Emarsys::SalesDataGateway.new(api_token, { merchant_id: Emarsys.merchant_id })
      else
        Emarsys::SalesDataBogusGateway.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-emarsys-2.0.1 lib/workarea/emarsys.rb
workarea-emarsys-2.0.0 lib/workarea/emarsys.rb