Class: ActionPusher::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_pusher/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(method_name, *args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/action_pusher/base.rb', line 6

def self.method_missing(method_name, *args)
  if method_defined?(method_name)
    new(method_name, *args).send(method_name, *args)
  else
    super
  end
end

Instance Method Details

#action_nameObject

Returns the name of the method used to generate the push notification



43
44
45
# File 'lib/action_pusher/base.rb', line 43

def action_name
  @_action_name
end

#deliverObject

Send out the push notifications



48
49
50
51
52
53
54
55
56
57
# File 'lib/action_pusher/base.rb', line 48

def deliver
  return self if @_push_was_called

  @_push_was_called = true

  apn = APNCertificate.instance
  @_notifications.each do |notification|
    apn.push(notification)
  end
end

#push(opts) ⇒ Object

Create apple push notifications to be sent out

  • Args

    • tokens -> User’s being sent to

    • message -> Message sent to tokens

    • data -> Custom data passed through the push notification

    • badge_count -> Number to place in badge (default is 0)



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/action_pusher/base.rb', line 21

def push(opts)
  tokens = [opts[:tokens] || opts[:token] || opts[:to]].flatten
  message = opts[:message] || ''
  data = opts[:data] || {}
  badge_count = opts[:badge_count] || 0

  return self if message.blank?

  @_notifications = Array.new.tap do |notifications|
    tokens.each do |token|
      notifications << Houston::Notification.new(device: token).tap do |notification|
        notification.alert = message
        notification.badge = badge_count
        notification.custom_data = data
      end
    end
  end

  self
end