Class: Houston::Notification
- Inherits:
-
Object
- Object
- Houston::Notification
- Defined in:
- lib/houston/notification.rb
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#content_available ⇒ Object
Returns the value of attribute content_available.
-
#custom_data ⇒ Object
Returns the value of attribute custom_data.
-
#sent_at ⇒ Object
readonly
Returns the value of attribute sent_at.
-
#sound ⇒ Object
Returns the value of attribute sound.
-
#token ⇒ Object
(also: #device)
Returns the value of attribute token.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Notification
constructor
A new instance of Notification.
- #mark_as_sent! ⇒ Object
- #message ⇒ Object
- #payload ⇒ Object
- #sent? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Notification
Returns a new instance of Notification.
11 12 13 14 15 16 17 18 19 |
# File 'lib/houston/notification.rb', line 11 def initialize( = {}) @token = .delete(:token) || .delete(:device) @alert = .delete(:alert) @badge = .delete(:badge) @sound = .delete(:sound) @content_available = .delete(:content_available) @custom_data = end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def alert @alert end |
#badge ⇒ Object
Returns the value of attribute badge.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def badge @badge end |
#content_available ⇒ Object
Returns the value of attribute content_available.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def content_available @content_available end |
#custom_data ⇒ Object
Returns the value of attribute custom_data.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def custom_data @custom_data end |
#sent_at ⇒ Object (readonly)
Returns the value of attribute sent_at.
6 7 8 |
# File 'lib/houston/notification.rb', line 6 def sent_at @sent_at end |
#sound ⇒ Object
Returns the value of attribute sound.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def sound @sound end |
#token ⇒ Object Also known as: device
Returns the value of attribute token.
5 6 7 |
# File 'lib/houston/notification.rb', line 5 def token @token end |
Instance Method Details
#mark_as_sent! ⇒ Object
39 40 41 |
# File 'lib/houston/notification.rb', line 39 def mark_as_sent! @sent_at = Time.now end |
#message ⇒ Object
32 33 34 35 36 37 |
# File 'lib/houston/notification.rb', line 32 def json = payload.to_json hex_token = [@token.gsub(/[<\s>]/, '')].pack('H*') [0, 0, 32, hex_token, 0, json.bytes.count, json].pack('ccca*cca*') end |
#payload ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/houston/notification.rb', line 21 def payload json = {}.merge(@custom_data || {}) json['aps'] = {} json['aps']['alert'] = @alert if @alert json['aps']['badge'] = @badge.to_i rescue 0 if @badge json['aps']['sound'] = @sound if @sound json['aps']['content-available'] = 1 if @content_available json end |
#sent? ⇒ Boolean
43 44 45 |
# File 'lib/houston/notification.rb', line 43 def sent? !!@sent_at end |