Class: Moromi::Apns::Parameter
- Inherits:
-
Object
- Object
- Moromi::Apns::Parameter
- Defined in:
- lib/moromi/apns/parameter.rb
Constant Summary collapse
- PUSH_TYPE_ALERT =
1
- PUSH_TYPE_BACKGROUND =
2
Instance Attribute Summary collapse
-
#alert ⇒ Object
readonly
Returns the value of attribute alert.
-
#badge ⇒ Object
readonly
Returns the value of attribute badge.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#custom_data ⇒ Object
readonly
Returns the value of attribute custom_data.
-
#mutable_content ⇒ Object
readonly
Returns the value of attribute mutable_content.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
-
#sound ⇒ Object
readonly
Returns the value of attribute sound.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #content_available ⇒ Object
-
#initialize(alert:, badge:, sound: 'default', push_type: PUSH_TYPE_ALERT, mutable_content: 0, category: nil, priority: 10, custom_data: {}, **options) ⇒ Parameter
constructor
A new instance of Parameter.
- #serialize ⇒ Object
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: {}, **) @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 = end |
Instance Attribute Details
#alert ⇒ Object (readonly)
Returns the value of attribute alert
10 11 12 |
# File 'lib/moromi/apns/parameter.rb', line 10 def alert @alert end |
#badge ⇒ Object (readonly)
Returns the value of attribute badge
11 12 13 |
# File 'lib/moromi/apns/parameter.rb', line 11 def badge @badge end |
#category ⇒ Object (readonly)
Returns the value of attribute category
14 15 16 |
# File 'lib/moromi/apns/parameter.rb', line 14 def category @category end |
#custom_data ⇒ Object (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_content ⇒ Object (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 |
#priority ⇒ Object (readonly)
Returns the value of attribute priority
15 16 17 |
# File 'lib/moromi/apns/parameter.rb', line 15 def priority @priority end |
#sound ⇒ Object (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_available ⇒ Object
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 |
#serialize ⇒ Object
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 |