Class: JPush::Push::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/jpush/push/notification.rb

Instance Method Summary collapse

Instance Method Details

#set_alert(alert) ⇒ Object



5
6
7
8
# File 'lib/jpush/push/notification.rb', line 5

def set_alert(alert)
  @alert = alert
  self
end

#set_android(alert:, title: nil, builder_id: nil, channel_id: nil, priority: nil, category: nil, style: nil, alert_type: nil, big_text: nil, inbox: nil, big_pic_path: nil, extras: nil, large_icon: nil, intent: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jpush/push/notification.rb', line 15

def set_android(alert: , title: nil, builder_id: nil, channel_id: nil,
  priority: nil, category: nil, style: nil, alert_type: nil, big_text: nil, inbox: nil, big_pic_path: nil, extras: nil,
  large_icon: nil, intent: nil)
  @android = {
    alert: alert,
    title: title,
    builder_id: builder_id,
    channel_id: channel_id,
    priority: priority,
    category: category,
    style: style,
    alert_type: alert_type,
    big_text: big_text,
    inbox: inbox,
    big_pic_path: big_pic_path,
    extras: extras,
    large_icon: large_icon,
    intent: intent
  }.select { |_, value| !value.nil? }
  self
end

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



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

def set_ios(alert: , sound: nil, badge: '+1', available: nil, category:nil, extras: nil, contentavailable: nil, mutablecontent: nil, thread: nil)
  contentavailable = available if contentavailable.nil?
  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,
    'thread-id': thread
  }.select { |_, value| !value.nil? }
  self
end

#set_not_alertObject



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

def set_not_alert
  @alert = ''
  self
end

#to_hashObject



54
55
56
57
58
59
60
61
62
# File 'lib/jpush/push/notification.rb', line 54

def to_hash
  @notification = {
    alert: @alert,
    android: @android,
    ios: @ios
  }.select { |_, value| !value.nil? }
  raise Utils::Exceptions::JPushError, 'Notification can not be empty.' if @notification.empty?
  @notification
end