Sha256: 043495d2fd89ef3773a155f5783111f90fa6c4f5dd14c6060a8ad927e7ca83a2

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class Panthoot::Translator
  DATA_CLASSES = {
    'subscribe'   => Panthoot::Data::Subscription,
    'unsubscribe' => Panthoot::Data::Unsubscription,
    'profile'     => Panthoot::Data::Profile,
    'upemail'     => Panthoot::Data::EmailAddressChange,
    'cleaned'     => Panthoot::Data::CleanedEmail,
    'campaign'    => Panthoot::Data::CampaignSendingStatus
  }

  LISTENER_METHODS = {
    'subscribe' => 'subscribe',    'unsubscribe' => 'unsubscribe',
    'profile' => 'profile_update', 'upemail' => 'email_address_change',
    'cleaned' => 'email_cleaned',  'campaign' => 'campaign_sending_status'
  }

  def self.translate!(params)
    new(params).translate!
  end

  def initialize(params)
    @params = params
  end

  def translate!
    Panthoot.listener.send LISTENER_METHODS[type], translated_object, fired_at
  end

  private

  attr_reader :params

  def translated_object
    DATA_CLASSES[type].new data
  end

  def data
    params['data']
  end

  def fired_at
    Time.zone.parse params['fired_at']
  end

  def type
    params['type']
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
panthoot-0.1.0 lib/panthoot/translator.rb