Sha256: e59432bd81470523bc93f199a38a372c1fedb2ee7a225d057a8d4d4f112ea15b

Contents?: true

Size: 913 Bytes

Versions: 6

Compression:

Stored size: 913 Bytes

Contents

module Workarea
  module Emarsys
    class SaveEmailSignup
      include Sidekiq::Worker
      include Sidekiq::CallbacksWorker

      sidekiq_options(
        enqueue_on: { Workarea::Email::Signup => :create },
        queue: 'low'
      )

      def perform(id)
        email_signup = Workarea::Email::Signup.find(id)
        email = email_signup.email

        # Emarasys Key values are
        # integer, value
        # where integer corresponds to a field in their
        # internal database
        attrs = { contacts: [
            "3" => email,
            "31" => 1
          ]
        }
        response = gateway.create_contact(attrs)

        email_signup.update_attributes!(
          emarsys_exported_at: Time.current,
          emarsys_external_id: response.body["data"]["ids"].first
        )
      end

      private

        def gateway
          Emarsys.gateway
        end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
workarea-emarsys-1.0.4 app/workers/workarea/emarsys/save_email_signup.rb
workarea-emarsys-2.0.1 app/workers/workarea/emarsys/save_email_signup.rb
workarea-emarsys-2.0.0 app/workers/workarea/emarsys/save_email_signup.rb
workarea-emarsys-1.1.0 app/workers/workarea/emarsys/save_email_signup.rb
workarea-emarsys-1.0.3 app/workers/workarea/emarsys/save_email_signup.rb
workarea-emarsys-1.0.2 app/workers/workarea/emarsys/save_email_signup.rb