Class: Moromi::Apns::Message::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/moromi/apns/message/base.rb

Direct Known Subclasses

Announce

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameter:, type: nil) ⇒ Base

Returns a new instance of Base.

Parameters:


12
13
14
15
# File 'lib/moromi/apns/message/base.rb', line 12

def initialize(parameter:, type: nil)
  @parameter = parameter
  @type = type
end

Instance Attribute Details

#parameterObject (readonly)

Returns the value of attribute parameter


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

def parameter
  @parameter
end

Class Method Details

.unserialize(params) ⇒ Object

Parameters:

  • params (Hash)

47
48
49
50
# File 'lib/moromi/apns/message/base.rb', line 47

def self.unserialize(params)
  parameter = ::Moromi::Apns::Parameter.unserialize(params[:parameter])
  new(parameter: parameter, type: params[:type])
end

Instance Method Details

#custom_dataObject


21
22
23
# File 'lib/moromi/apns/message/base.rb', line 21

def custom_data
  {type: type}.merge(@parameter.custom_data)
end

#serializeObject


25
26
27
28
29
30
# File 'lib/moromi/apns/message/base.rb', line 25

def serialize
  {
    type: type,
    parameter: @parameter.serialize
  }
end

#to_hashObject


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/moromi/apns/message/base.rb', line 32

def to_hash
  base = {
    aps: {
      badge: badge,
      alert: alert,
      sound: sound,
      'content-available' => content_available,
      'mutable-content' => mutable_content,
      priority: priority
    }
  }
  custom_data.merge(base)
end

#typeObject


17
18
19
# File 'lib/moromi/apns/message/base.rb', line 17

def type
  @type || self.class.name
end