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

#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, priority: nil, category: nil, style: nil, big_text: nil, inbox: nil, big_pic_path: nil, extras: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jpush/push/notification.rb', line 22

def set_android(alert: , title: nil, builder_id: nil,
  priority: nil, category: nil, style: nil, big_text: nil, inbox: nil, big_pic_path: nil, extras: nil)
  extras = Notification.build_extras(extras)
  @android = {
    alert: alert,
    title: title,
    builder_id: builder_id,
    priority: priority,
    category: category,
    style: style,
    big_text: big_text,
    inbox: inbox,
    big_pic_path: big_pic_path,
    extras: extras
  }.compact
  self
end

#set_ios(alert:, sound: nil, badge: '+1', available: nil, category: nil, extras: nil, contentavailable: nil, mutablecontent: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jpush/push/notification.rb', line 40

def set_ios(alert: , sound: nil, badge: '+1', available: nil, category:nil, extras: nil, contentavailable: nil, mutablecontent: nil)
  contentavailable = available if contentavailable.nil?
  extras = Notification.build_extras(extras)
  contentavailable = nil unless contentavailable.is_a? TrueClass
  mutablecontent = nil unless mutablecontent.is_a? TrueClass
  @ios = {
    alert: alert,
    sound: sound,
    badge: badge,
    'content-available': contentavailable,
    'mutable-content': mutablecontent,
    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



58
59
60
61
62
63
64
65
66
# File 'lib/jpush/push/notification.rb', line 58

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