Class: JPush::Push::Notification

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

Constant Summary collapse

MAX_IOS_NOTIFICATION_SIZE =
2000

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_platform, 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

Instance Method Details

#buildObject



51
52
53
54
55
56
57
58
59
# File 'lib/jpush/push/notification.rb', line 51

def build
  @notification = {
    alert: @alert,
    android: @android,
    ios: @ios
  }.compact
  raise Utils::Exceptions::JPushError, 'Notification can not be empty.' if @notification.empty?
  self
end

#set_alert(alert) ⇒ Object



11
12
13
14
15
# File 'lib/jpush/push/notification.rb', line 11

def set_alert(alert)
  Notification.ensure_argument_not_blank('alert': alert)
  @alert = alert
  self
end

#set_android(alert:, title: nil, builder_id: nil, extras: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jpush/push/notification.rb', line 22

def set_android(alert: , title: nil, builder_id: nil, extras: nil)
  extras = Notification.build_extras(extras)
  check_argument(alert: alert, title: title, builder_id: builder_id)
  @android = {
    alert: alert,
    title: title,
    builder_id: builder_id,
    extras: extras
  }.compact
  self
end

#set_ios(alert:, sound: nil, badge: nil, available: nil, category: nil, extras: nil) ⇒ Object



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

def set_ios(alert: , sound: nil, badge: nil, available: nil, category:nil, extras: nil)
  extras = Notification.build_extras(extras)
  badge = 0 == badge.to_i ? '0' : badge unless badge.nil?
  available = nil unless available.is_a? TrueClass
  check_argument(alert: alert, sound: sound, badge: badge, category: category)
  @ios = {
    alert: alert,
    sound: sound,
    badge: badge,
    'content-available': available,
    category: category,
    extras: extras
  }.compact
  Notification.ensure_not_over_bytesize('ios', {'ios': @ios}, MAX_IOS_NOTIFICATION_SIZE)
  self
end

#set_not_alertObject



17
18
19
20
# File 'lib/jpush/push/notification.rb', line 17

def set_not_alert
  @alert = ''
  self
end

#to_hashObject



61
62
63
# File 'lib/jpush/push/notification.rb', line 61

def to_hash
  @notification
end