Sha256: 79c1ce2c563794c17033cd8ab119cdceca47e5babe2e2d155e9bcbcdf9a3f09f

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 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}
      
      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

3 entries across 3 versions & 1 rubygems

Version Path
notifiable-rails-0.13.0 lib/notifiable/notifier_base.rb
notifiable-rails-0.12.1 lib/notifiable/notifier_base.rb
notifiable-rails-0.12.0 lib/notifiable/notifier_base.rb