Class: Lowdown::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/lowdown/notification.rb

Overview

Constant Summary collapse

APS_KEYS =
[:alert, :badge, :sound, :content_available, :category].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#expirationObject

Returns the value of attribute expiration.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def expiration
  @expiration
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def id
  @id
end

#payloadObject

Returns the value of attribute payload.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def payload
  @payload
end

#priorityObject

Returns the value of attribute priority.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def priority
  @priority
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def token
  @token
end

#topicObject

Returns the value of attribute topic.



7
8
9
# File 'lib/lowdown/notification.rb', line 7

def topic
  @topic
end

Instance Method Details

#formatted_idObject



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_payloadObject



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

Returns:

  • (Boolean)


13
14
15
# File 'lib/lowdown/notification.rb', line 13

def valid?
  !!(@token && @payload)
end