Class: ActionPush::Envelope
- Inherits:
-
Object
- Object
- ActionPush::Envelope
- 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
-
#body ⇒ Object
Returns the value of attribute body.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add(provider, push) ⇒ Object
- #for(provider) ⇒ Object (also: #[])
-
#initialize(params = {}) {|_self| ... } ⇒ Envelope
constructor
A new instance of Envelope.
- #pushes ⇒ Object
Constructor Details
#initialize(params = {}) {|_self| ... } ⇒ Envelope
Returns a new instance of Envelope.
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
#body ⇒ Object
Returns the value of attribute body.
12 13 14 |
# File 'lib/action_push/envelope.rb', line 12 def body @body end |
#payload ⇒ Object
Returns the value of attribute payload.
13 14 15 |
# File 'lib/action_push/envelope.rb', line 13 def payload @payload end |
#title ⇒ Object
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 |
#pushes ⇒ Object
35 36 37 |
# File 'lib/action_push/envelope.rb', line 35 def pushes @pushes ||= {} end |