Class: Moromi::Aws::Sns::Message::Apns

Inherits:
Base
  • Object
show all
Defined in:
lib/moromi/aws/sns/message/apns.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, build_from_hash

Constructor Details

#initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil, priority: 10, type: nil, custom_data: {}) ⇒ Apns

Returns a new instance of Apns.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moromi/aws/sns/message/apns.rb', line 16

def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil,
               priority: 10, type: nil, custom_data: {})
  @alert = alert
  @badge = badge
  @sound = sound
  @content_available = content_available
  @mutable_content = mutable_content
  @category = category
  @priority = priority
  @type = type || self.class.name
  @custom_data = setup_initial_custom_data({type: @type}.merge(custom_data))
end

Instance Attribute Details

#alertObject (readonly)

Returns the value of attribute alert.



6
7
8
# File 'lib/moromi/aws/sns/message/apns.rb', line 6

def alert
  @alert
end

#badgeObject (readonly)

Returns the value of attribute badge.



7
8
9
# File 'lib/moromi/aws/sns/message/apns.rb', line 7

def badge
  @badge
end

#categoryObject (readonly)

Returns the value of attribute category.



11
12
13
# File 'lib/moromi/aws/sns/message/apns.rb', line 11

def category
  @category
end

#content_availableObject (readonly)

Returns the value of attribute content_available.



9
10
11
# File 'lib/moromi/aws/sns/message/apns.rb', line 9

def content_available
  @content_available
end

#custom_dataObject (readonly)

Returns the value of attribute custom_data.



14
15
16
# File 'lib/moromi/aws/sns/message/apns.rb', line 14

def custom_data
  @custom_data
end

#mutable_contentObject (readonly)

Returns the value of attribute mutable_content.



10
11
12
# File 'lib/moromi/aws/sns/message/apns.rb', line 10

def mutable_content
  @mutable_content
end

#priorityObject (readonly)

Returns the value of attribute priority.



12
13
14
# File 'lib/moromi/aws/sns/message/apns.rb', line 12

def priority
  @priority
end

#soundObject (readonly)

Returns the value of attribute sound.



8
9
10
# File 'lib/moromi/aws/sns/message/apns.rb', line 8

def sound
  @sound
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/moromi/aws/sns/message/apns.rb', line 13

def type
  @type
end

Class Method Details

.build_silent_push_message(priority: 10, custom_data: {}) ⇒ Object



58
59
60
# File 'lib/moromi/aws/sns/message/apns.rb', line 58

def build_silent_push_message(priority: 10, custom_data: {})
  new('', nil, sound: nil, content_available: 1, priority: priority, custom_data: custom_data)
end

Instance Method Details

#to_hashObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/moromi/aws/sns/message/apns.rb', line 29

def to_hash
  {
    alert: @alert,
    badge: @badge,
    sound: @sound,
    content_available: @content_available,
    mutable_content: @mutable_content,
    category: @category,
    priority: @priority,
    type: @type,
    custom_data: @custom_data
  }
end

#to_message_jsonObject



43
44
45
46
47
48
49
# File 'lib/moromi/aws/sns/message/apns.rb', line 43

def to_message_json
  aps = to_hash
  %i[custom_data type content_available mutable_content].each { |k| aps.delete(k) }
  aps['content-available'] = @content_available
  aps['mutable-content'] = @mutable_content
  @custom_data.merge({aps: aps}).to_json
end