Class: JPush::Options

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Options

Returns a new instance of Options.


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

def initialize(opts = {})
  if opts[:apns_production] != nil
    @apns_production = opts[:apns_production]
  else
    @apns_production = false
  end

  @sendno = opts[:sendno]

  if opts[:time_to_live] != nil
  @time_to_live = opts[:time_to_live]
  else
  @time_to_live = 86400
  end
  @overrride_msg_id = opts[:override_msg_id]
  @big_push_duration = opts[:big_push_duration]
end

Instance Attribute Details

#apns_productionObject

Returns the value of attribute apns_production


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

def apns_production
  @apns_production
end

#big_push_durationObject

Returns the value of attribute big_push_duration


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

def big_push_duration
  @big_push_duration
end

#override_msg_idObject

Returns the value of attribute override_msg_id


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

def override_msg_id
  @override_msg_id
end

#sendnoObject

Returns the value of attribute sendno


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

def sendno
  @sendno
end

#time_to_liveObject

Returns the value of attribute time_to_live


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

def time_to_live
  @time_to_live
end

Class Method Details

.build(opts = {}) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jpush/model/options.rb', line 42

def self.build(opts = {})
  options = JPush::Options.new(opts)
  if options.sendno != nil && options.sendno < 0
    raise ArgumentError.new('sendno should be greater than 0.')
  end
  if options.override_msg_id != nil && options.override_msg_id < 0
    raise ArgumentError.new(' override_msg_id should be greater than 0.')
  end
  if options.time_to_live != nil && options.time_to_live < 0
    raise ArgumentError.new('time_to_live should be greater than 0.')
  end
  if options.big_push_duration  != nil && options.big_push_duration > 1440
    raise ArgumentError.new('big_push_duration should be less than 1440.')
  end
  
  if options.big_push_duration  != nil && options.big_push_duration <= 0
    raise ArgumentError.new('big_push_duration should be greater than 0.')
  end
  return options
end

Instance Method Details

#toJSONObject


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

def toJSON
  array = {}
  if @sendno != nil then
    array['sendno'] = @sendno
  end
  if @time_to_live != nil then
    array['time_to_live'] = @time_to_live
  end
  if @override_msg_id != nil then
    array['override_msg_id'] = @override_msg_id
  end
  if @apns_production != nil then
    array['apns_production'] = @apns_production
  end
  if @big_push_duration != nil then
    array['big_push_duration'] = @big_push_duration
  end
  return array
end