class Moromi::Apns::Parameter

Constants

PUSH_TYPE_ALERT
PUSH_TYPE_BACKGROUND

Attributes

alert[R]
badge[R]
category[R]
custom_data[R]
mutable_content[R]
priority[R]
sound[R]

Public Class Methods

make_silent_push_parameter(priority: 10, custom_data: {}) click to toggle source
# 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
new(alert:, badge:, sound: 'default', push_type: PUSH_TYPE_ALERT, mutable_content: 0, category: nil, priority: 10, custom_data: {}, **options) click to toggle source
# 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
unserialize(json) click to toggle source
# 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

Public Instance Methods

==(other) click to toggle source
# File lib/moromi/apns/parameter.rb, line 34
def ==(other)
  serialize == other.serialize
end
content_available() click to toggle source

docs.aws.amazon.com/ja_jp/sns/latest/dg/sns-send-custom-platform-specific-payloads-mobile-devices.html#mobile-push-send-message-apns-background-notification

# 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() click to toggle source
# 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

Private Instance Methods

normalize_push_type(value) click to toggle source
# File lib/moromi/apns/parameter.rb, line 79
def normalize_push_type(value)
  case value
  when PUSH_TYPE_ALERT
    PUSH_TYPE_ALERT
  when PUSH_TYPE_BACKGROUND
    PUSH_TYPE_BACKGROUND
  else
    PUSH_TYPE_ALERT
  end
end