Class: Moromi::Apns::Parameter

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

Constant Summary collapse

PUSH_TYPE_ALERT =
1
PUSH_TYPE_BACKGROUND =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alert:, badge:, sound: 'default', push_type: PUSH_TYPE_ALERT, mutable_content: 0, category: nil, priority: 10, custom_data: {}, **options) ⇒ Parameter

Returns a new instance of Parameter.


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

def initialize(alert:, badge:, sound: 'default', push_type: PUSH_TYPE_ALERT, mutable_content: 0, category: nil, priority: 10, custom_data: {}, **options)
  @alert = alert
  @badge = badge
  @sound = sound
  @push_type = normalize_push_type(push_type)
  @mutable_content = mutable_content
  @category = category
  @priority = priority
  @custom_data = custom_data
  @options = options
end

Instance Attribute Details

#alertObject (readonly)

Returns the value of attribute alert


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

def alert
  @alert
end

#badgeObject (readonly)

Returns the value of attribute badge


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

def badge
  @badge
end

#categoryObject (readonly)

Returns the value of attribute category


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

def category
  @category
end

#custom_dataObject (readonly)

Returns the value of attribute custom_data


16
17
18
# File 'lib/moromi/apns/parameter.rb', line 16

def custom_data
  @custom_data
end

#mutable_contentObject (readonly)

Returns the value of attribute mutable_content


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

def mutable_content
  @mutable_content
end

#priorityObject (readonly)

Returns the value of attribute priority


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

def priority
  @priority
end

#soundObject (readonly)

Returns the value of attribute sound


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

def sound
  @sound
end

Class Method Details

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


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

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

.unserialize(json) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/moromi/apns/parameter.rb', line 63

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

Instance Method Details

#==(other) ⇒ Object


34
35
36
# File 'lib/moromi/apns/parameter.rb', line 34

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

#content_availableObject


39
40
41
42
43
44
45
46
47
48
# File 'lib/moromi/apns/parameter.rb', line 39

def content_available
  case @push_type
  when PUSH_TYPE_ALERT
    'alert'
  when PUSH_TYPE_BACKGROUND
    1
  else
    'alert'
  end
end

#serializeObject


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

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