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 Attribute Summary collapse

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.



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

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 Attribute Details

#audienceObject (readonly)

Returns the value of attribute audience.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def audience
  @audience
end

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def message
  @message
end

#notificationObject (readonly)

Returns the value of attribute notification.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def notification
  @notification
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def options
  @options
end

#platformObject (readonly)

Returns the value of attribute platform.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def platform
  @platform
end

#sms_messageObject (readonly)

Returns the value of attribute sms_message.



11
12
13
# File 'lib/jpush/push/push_payload.rb', line 11

def sms_message
  @sms_message
end

Instance Method Details

#buildObject



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

def build
  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: @options
  }.compact
  self
end

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



24
25
26
27
# File 'lib/jpush/push/push_payload.rb', line 24

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



34
35
36
37
# File 'lib/jpush/push/push_payload.rb', line 34

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

#set_sms_message(content, delay_time = 0) ⇒ Object



29
30
31
32
# File 'lib/jpush/push/push_payload.rb', line 29

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

#to_hashObject



54
55
56
# File 'lib/jpush/push/push_payload.rb', line 54

def to_hash
  @push_payload
end