Sha256: d418f4c5f41f91c6b4f160d6dbbffa671d97457b3b7f914e918f87752c43e84c

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Notifiable

	class NotifierBase
    
    attr_accessor :env
    
		def send_notification(notification, device_token)
      # todo - add before hook
      enqueue(notification, device_token, custom_params(notification))
      # todo - add after hook       				
    end
    
    def close
      flush
      save_receipts
    end
    
    protected    
    def flush
      
    end
    
    def processed(notification, device_token, status)
      receipts << {notification_id: notification.id, device_token_id: device_token.id, status: status, created_at: DateTime.now}
      
      if receipts.count > 10000
        save_receipts
      end
    end
    
    def custom_params(notification)
      params = notification.params || {}
      params[:notification_id] = notification.id
      params
    end
    
    def test_env?
      self.env == "test"
    end
    
    private
    def receipts
      @receipts ||= []
    end
    
    def save_receipts
      Notifiable::NotificationStatus.bulk_insert! receipts
      @receipts = []
    end
	end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
notifiable-rails-0.14.0 lib/notifiable/notifier_base.rb