Class: Moromi::Apns::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/moromi/apns/parameter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Parameter.



16
17
18
19
20
21
22
23
24
25
# File 'lib/moromi/apns/parameter.rb', line 16

def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil, priority: 10, custom_data: {})
  @alert = alert
  @badge = badge
  @sound = sound
  @content_available = content_available
  @mutable_content = mutable_content
  @category = category
  @priority = priority
  @custom_data = custom_data
end

Instance Attribute Details

#alertObject (readonly)

Returns the value of attribute alert.



7
8
9
# File 'lib/moromi/apns/parameter.rb', line 7

def alert
  @alert
end

#badgeObject (readonly)

Returns the value of attribute badge.



8
9
10
# File 'lib/moromi/apns/parameter.rb', line 8

def badge
  @badge
end

#categoryObject (readonly)

Returns the value of attribute category.



12
13
14
# File 'lib/moromi/apns/parameter.rb', line 12

def category
  @category
end

#content_availableObject (readonly)

Returns the value of attribute content_available.



10
11
12
# File 'lib/moromi/apns/parameter.rb', line 10

def content_available
  @content_available
end

#custom_dataObject (readonly)

Returns the value of attribute custom_data.



14
15
16
# File 'lib/moromi/apns/parameter.rb', line 14

def custom_data
  @custom_data
end

#mutable_contentObject (readonly)

Returns the value of attribute mutable_content.



11
12
13
# File 'lib/moromi/apns/parameter.rb', line 11

def mutable_content
  @mutable_content
end

#priorityObject (readonly)

Returns the value of attribute priority.



13
14
15
# File 'lib/moromi/apns/parameter.rb', line 13

def priority
  @priority
end

#soundObject (readonly)

Returns the value of attribute sound.



9
10
11
# File 'lib/moromi/apns/parameter.rb', line 9

def sound
  @sound
end

Class Method Details

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



27
28
29
# File 'lib/moromi/apns/parameter.rb', line 27

def self.make_silent_push_parameter(priority: 10, custom_data: {})
  new(alert: '', badge: nil, sound: nil, content_available: 1, priority: priority, custom_data: custom_data)
end

.unserialize(json) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/moromi/apns/parameter.rb', line 48

def self.unserialize(json)
  hash = JSON.parse(json).with_indifferent_access
  new(
    alert: hash[:alert],
    badge: hash[:badge],
    sound: hash[:sound],
    content_available: hash[:content_available],
    mutable_content: hash[:mutable_content],
    category: hash[:category],
    priority: hash[:priority],
    custom_data: hash[:custom_data]
  )
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/moromi/apns/parameter.rb', line 31

def ==(other)
  serialize == other.serialize
end

#serializeObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/moromi/apns/parameter.rb', line 35

def serialize
  {
    alert: @alert,
    badge: @badge,
    sound: @sound,
    content_available: @content_available,
    mutable_content: @mutable_content,
    category: @category,
    priority: @priority,
    custom_data: @custom_data
  }.to_json
end