Class: ApnsKit::Notification
- Inherits:
-
Object
- Object
- ApnsKit::Notification
- Defined in:
- lib/apns_kit/notification.rb
Constant Summary collapse
- MAXIMUM_PAYLOAD_SIZE =
4096
Instance Attribute Summary collapse
-
#alert ⇒ Object
Returns the value of attribute alert.
-
#custom_data ⇒ Object
Returns the value of attribute custom_data.
-
#id ⇒ Object
Returns the value of attribute id.
-
#token ⇒ Object
Returns the value of attribute token.
-
#topic ⇒ Object
Returns the value of attribute topic.
Instance Method Summary collapse
- #header ⇒ Object
-
#initialize(options) ⇒ Notification
constructor
A new instance of Notification.
- #payload ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Notification
Returns a new instance of Notification.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apns_kit/notification.rb', line 18 def initialize() @token = .delete(:token) || .delete(:device) @alert = .delete(:alert) @badge = .delete(:badge) @sound = .delete(:sound) @category = .delete(:category) @expiry = .delete(:expiry) @id = .delete(:id) @priority = .delete(:priority) @content_available = .delete(:content_available) @topic = .delete(:topic) @custom_data = end |
Instance Attribute Details
#alert ⇒ Object
Returns the value of attribute alert.
12 13 14 |
# File 'lib/apns_kit/notification.rb', line 12 def alert @alert end |
#custom_data ⇒ Object
Returns the value of attribute custom_data.
16 17 18 |
# File 'lib/apns_kit/notification.rb', line 16 def custom_data @custom_data end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/apns_kit/notification.rb', line 10 def id @id end |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/apns_kit/notification.rb', line 8 def token @token end |
#topic ⇒ Object
Returns the value of attribute topic.
14 15 16 |
# File 'lib/apns_kit/notification.rb', line 14 def topic @topic end |
Instance Method Details
#header ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/apns_kit/notification.rb', line 41 def header json = { ':scheme' => 'https', ':method' => 'POST', ':path' => "/3/device/#{token}", 'apns-id' => id, 'content-length' => payload.bytesize.to_s, 'apns-topic' => topic } json.merge!({ "apns-expiry" => @expiry }) if @expiry json.merge!({ "apns-priority" => @priority }) if @priority return json end |
#payload ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/apns_kit/notification.rb', line 56 def payload json = {}.merge(@custom_data || {}).inject({}){|h,(k,v)| h[k.to_s] = v; h} 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']['category'] = @category if @category json['aps']['content-available'] = 1 if @content_available JSON.dump(json) end |
#valid? ⇒ Boolean
37 38 39 |
# File 'lib/apns_kit/notification.rb', line 37 def valid? payload.bytesize <= MAXIMUM_PAYLOAD_SIZE end |