Class: ActionPush::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/action_push/envelope.rb

Overview

envelope = ActionPush::Envelope.new(title: ‘Alert’, body: ‘You ave 2 messages’) envelope.add(:ios, ActionPush::Ios::Message.new)

envelope.for(:ios) do |ios|

ios.sound = 'wow.mp3'

end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ Envelope

Returns a new instance of Envelope.

Yields:

  • (_self)

Yield Parameters:



15
16
17
18
19
# File 'lib/action_push/envelope.rb', line 15

def initialize(params = {})
  params.each { |name, value| public_send("#{name}=", value) }

  yield(self) if block_given?
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



12
13
14
# File 'lib/action_push/envelope.rb', line 12

def body
  @body
end

#payloadObject

Returns the value of attribute payload.



13
14
15
# File 'lib/action_push/envelope.rb', line 13

def payload
  @payload
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/action_push/envelope.rb', line 11

def title
  @title
end

Instance Method Details

#add(provider, push) ⇒ Object



21
22
23
# File 'lib/action_push/envelope.rb', line 21

def add(provider, push)
  pushes[provider] = push
end

#for(provider) ⇒ Object Also known as: []



25
26
27
28
29
30
31
# File 'lib/action_push/envelope.rb', line 25

def for(provider)
  push = pushes.fetch(provider) do
    raise ArgumentError, "provider with name <#{provider}> was not registered"
  end

  block_given? ? yield(push) : push
end

#pushesObject



35
36
37
# File 'lib/action_push/envelope.rb', line 35

def pushes
  @pushes ||= {}
end