Class: Lowdown::Notification
- Inherits:
-
Object
- Object
- Lowdown::Notification
- Defined in:
- lib/lowdown/notification.rb
Overview
Constant Summary collapse
- APS_KEYS =
[:alert, :badge, :sound, :content_available, :category].freeze
Instance Attribute Summary collapse
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#id ⇒ Object
Returns the value of attribute id.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#priority ⇒ Object
Returns the value of attribute priority.
-
#token ⇒ Object
Returns the value of attribute token.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
- #formatted_id ⇒ Object
- #formatted_payload ⇒ Object
-
#initialize(params) ⇒ Notification
constructor
A new instance of Notification.
- #valid? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ Notification
Returns a new instance of Notification.
9 10 11 |
# File 'lib/lowdown/notification.rb', line 9 def initialize(params) params.each { |key, value| send("#{key}=", value) } end |
Instance Attribute Details
#expiration ⇒ Object
Returns the value of attribute expiration.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def expiration @expiration end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def id @id end |
#payload ⇒ Object
Returns the value of attribute payload.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def payload @payload end |
#priority ⇒ Object
Returns the value of attribute priority.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def priority @priority end |
#token ⇒ Object
Returns the value of attribute token.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def token @token end |
#topic ⇒ Object
Returns the value of attribute topic.
7 8 9 |
# File 'lib/lowdown/notification.rb', line 7 def topic @topic end |
Instance Method Details
#formatted_id ⇒ Object
17 18 19 20 21 22 |
# File 'lib/lowdown/notification.rb', line 17 def formatted_id if @id padded = @id.to_s.rjust(32, "0") [padded[0,8], padded[8,4], padded[12,4], padded[16,4], padded[20,12]].join("-") end end |
#formatted_payload ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lowdown/notification.rb', line 24 def formatted_payload if @payload.has_key?(:aps) @payload else payload = {} payload[:aps] = aps = {} @payload.each do |key, value| key = key.to_sym if APS_KEYS.include?(key) aps[key] = value else payload[key] = value end end payload end end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/lowdown/notification.rb', line 13 def valid? !!(@token && @payload) end |