Class: JPush::Push::PushPayload

Inherits:
Object
  • Object
show all
Extended by:
Helper::ArgumentHelper
Defined in:
lib/jpush/push/push_payload.rb

Constant Summary collapse

VALID_OPTION_KEY =
[:sendno, :time_to_live, :override_msg_id, :apns_production, :big_push_duration]
MAX_SMS_CONTENT_SIZE =
480
MAX_SMS_DELAY_TIME =

24 * 60 * 60 (second)

86400

Constants included from Helper::ArgumentHelper

Helper::ArgumentHelper::MAX_ALIAS_ARRAY_SIZE, Helper::ArgumentHelper::MAX_MSG_IDS_ARRAY_SIZE, Helper::ArgumentHelper::MAX_REGISTRATION_ID_ARRAY_SIZE, Helper::ArgumentHelper::MAX_TAG_ARRAY_MAX_BYTESIZE, Helper::ArgumentHelper::MAX_TAG_ARRAY_SZIE

Constants included from Helper::Argument

Helper::Argument::MAX_ALIAS_BYTESIZE, Helper::Argument::MAX_TAG_BYTESIZE, Helper::Argument::MOBILE_RE

Instance Method Summary collapse

Methods included from Helper::ArgumentHelper

build_alias, build_extras, build_msg_ids, build_registration_ids, build_tags, extended

Methods included from Helper::Argument

#check_alias, #check_mobile, #check_platform, #check_registration_id, #check_tag, #ensure_argument_not_blank, #ensure_argument_required, #ensure_not_over_bytesize, #ensure_not_over_size, #ensure_word_valid

Constructor Details

#initialize(platform:, audience:, notification: nil, message: nil) ⇒ PushPayload

Returns a new instance of PushPayload.



15
16
17
18
19
20
# File 'lib/jpush/push/push_payload.rb', line 15

def initialize(platform: , audience: , notification: nil, message: nil)
  @platform = 'all' == platform ? JPush::Config.settings[:valid_platform] : build_platform(platform)
  @audience = 'all' == audience ? 'all' : build_audience(audience)
  @notification = build_notification(notification) unless notification.nil?
  @message = build_message(message) unless message.nil?
end

Instance Method Details

#set_message(msg_content, title: nil, content_type: nil, extras: nil) ⇒ Object



22
23
24
25
# File 'lib/jpush/push/push_payload.rb', line 22

def set_message(msg_content, title: nil, content_type: nil, extras: nil)
  @message = build_message(msg_content, title, content_type, extras)
  self
end

#set_options(opts) ⇒ Object



32
33
34
35
# File 'lib/jpush/push/push_payload.rb', line 32

def set_options(opts)
  @options = build_options(opts)
  self
end

#set_sms_message(content, delay_time = 0) ⇒ Object



27
28
29
30
# File 'lib/jpush/push/push_payload.rb', line 27

def set_sms_message(content, delay_time = 0)
  @sms_message = build_sms_message(content, delay_time)
  self
end

#to_hashObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/jpush/push/push_payload.rb', line 37

def to_hash
  raise Utils::Exceptions::MissingArgumentError.new(['audience']) unless @audience
  err_msg = 'missing notification or message'
  raise Utils::Exceptions::JPushError, err_msg unless @notification || @message
  @push_payload =  {
    platform: @platform,
    audience: @audience,
    notification: @notification,
    message: @message,
    sms_message: @sms_message,
    options: { apns_production: false }.merge(@options.nil? ? {} : @options)
  }.compact
end