Class: JPush::IOSNotification

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ IOSNotification

Returns a new instance of IOSNotification.


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jpush/model/notification/ios_notification.rb', line 4

def initialize(opts = {})
  if opts[:badge] != nil
    @badge = opts[:badge]
  else
    @badge = 1
  end
  if opts[:sound] != nil
    @sound = opts[:sound]
  else
    @sound = ''
  end
  @alert = opts[:alert]
  @extras = opts[:extras]
  @content_available = opts[:content_available]
  @category = opts[:category]
end

Instance Attribute Details

#alertObject

Returns the value of attribute alert


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def alert
  @alert
end

#badgeObject

Returns the value of attribute badge


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def badge
  @badge
end

#categoryObject

Returns the value of attribute category


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def category
  @category
end

#content_availableObject

Returns the value of attribute content_available


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def content_available
  @content_available
end

#extrasObject

Returns the value of attribute extras


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def extras
  @extras
end

#soundObject

Returns the value of attribute sound


3
4
5
# File 'lib/jpush/model/notification/ios_notification.rb', line 3

def sound
  @sound
end

Class Method Details

.build(opts = {}) ⇒ Object


52
53
54
55
56
57
58
59
60
61
# File 'lib/jpush/model/notification/ios_notification.rb', line 52

def self.build(opts = {})
  ios = JPush::IOSNotification.new(opts)
  if ios.alert == nil
    raise ArgumentError.new('the alert should be setted')
  end
  if ios.to_s.bytesize > 220
    raise ArgumentError.new('ios notfication size is longer than 220 ')
  end
  return ios
end

Instance Method Details

#disableBadgeObject


48
49
50
# File 'lib/jpush/model/notification/ios_notification.rb', line 48

def disableBadge
  @badge = false
end

#disableSoundObject


44
45
46
# File 'lib/jpush/model/notification/ios_notification.rb', line 44

def disableSound
  @sound = false
end

#toJSONObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jpush/model/notification/ios_notification.rb', line 21

def toJSON
  array = {}
  if @alert != nil then
    array['alert'] = @alert
  end
  if @sound != nil && @sound != false then
    array['sound'] = @sound
  end
  if @badge != nil && @badge != false then
    array['badge'] = @badge
  end
  if @extras != nil then
    array['extras'] = @extras
  end
  if @content_available != nil then
    array['content-available'] = @content_available
  end
  if @category != nil then
    array['category'] = @category
  end
  return array
end