Class: Push0r::ApnsPushMessage
- Inherits:
-
PushMessage
- Object
- PushMessage
- Push0r::ApnsPushMessage
- Defined in:
- lib/push0r/APNS/ApnsPushMessage.rb
Overview
ApnsPushMessage is a PushMessage implementation that encapsulates a single push notification to be sent to a single user.
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Attributes inherited from PushMessage
#identifier, #payload, #receiver_token, #time_to_live
Instance Method Summary collapse
-
#initialize(receiver_token, environment = ApnsEnvironment::PRODUCTION, identifier = nil, time_to_live = nil) ⇒ ApnsPushMessage
constructor
Returns a new ApnsPushMessage instance that encapsulates a single push notification to be sent to a single user.
-
#simple(alert_text = nil, sound = nil, badge = nil, category = nil) ⇒ Object
Convenience method to attach common data (that is an alert, a sound or a badge value) to this message’s payload.
Methods inherited from PushMessage
Constructor Details
#initialize(receiver_token, environment = ApnsEnvironment::PRODUCTION, identifier = nil, time_to_live = nil) ⇒ ApnsPushMessage
Returns a new ApnsPushMessage instance that encapsulates a single push notification to be sent to a single user.
11 12 13 14 15 16 17 |
# File 'lib/push0r/APNS/ApnsPushMessage.rb', line 11 def initialize(receiver_token, environment = ApnsEnvironment::PRODUCTION, identifier = nil, time_to_live = nil) if identifier.nil? ## make sure the message has an identifier (required for apns error handling) identifier = Random.rand(2**32) end super(receiver_token, identifier, time_to_live) @environment = environment end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
4 5 6 |
# File 'lib/push0r/APNS/ApnsPushMessage.rb', line 4 def environment @environment end |
Instance Method Details
#simple(alert_text = nil, sound = nil, badge = nil, category = nil) ⇒ Object
Convenience method to attach common data (that is an alert, a sound or a badge value) to this message’s payload.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/push0r/APNS/ApnsPushMessage.rb', line 24 def simple(alert_text = nil, sound = nil, badge = nil, category = nil) new_payload = {aps: {}} if alert_text new_payload[:aps][:alert] = alert_text end if sound new_payload[:aps][:sound] = sound end if badge new_payload[:aps][:badge] = badge end if category new_payload[:aps][:category] = category end @payload.merge!(new_payload) return self end |