Class: JPush::Audience

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Audience

Returns a new instance of Audience.


4
5
6
7
8
9
10
11
# File 'lib/jpush/model/audience.rb', line 4

def initialize(opts = {})
  @all = false
  @tag = opts[:tag]
  @tag_and = opts[:tag_and]
  @_alias = opts[:_alias]
  @registration_id = opts[:registration_id]
  @segment = opts[:segment]
end

Instance Attribute Details

#_aliasObject

Returns the value of attribute _alias


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

def _alias
  @_alias
end

#allObject

Returns the value of attribute all


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

def all
  @all
end

#registration_idObject

Returns the value of attribute registration_id


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

def registration_id
  @registration_id
end

#segmentObject

Returns the value of attribute segment


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

def segment
  @segment
end

#tagObject

Returns the value of attribute tag


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

def tag
  @tag
end

#tag_andObject

Returns the value of attribute tag_and


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

def tag_and
  @tag_and
end

Class Method Details

.allObject


45
46
47
48
49
# File 'lib/jpush/model/audience.rb', line 45

def self.all
  au = JPush::Audience.new
  au.all = true
  return au
end

.build(opts = {}) ⇒ Object


51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jpush/model/audience.rb', line 51

def self.build(opts = {})
  audience = JPush::Audience.new(opts)
  if audience.all == true
    if audience.tag != nil || audience._alias != nil || audience.tag_and != nil || audience.registration_id != nil
      raise ArgumentError.new('If audience is all, no any other audience may be set.')
    end
  end
  if audience.all == false
    if audience.tag == nil && audience._alias == nil && audience.tag_and == nil && audience.registration_id == nil
      raise ArgumentError.new('No any audience target is set.')
    end
  end
  return audience
end

Instance Method Details

#toJSONObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jpush/model/audience.rb', line 13

def toJSON
  if @all == true then
    return 'all'
  end
  array = {}
  if @tag != nil then
    if @tag.class != Array
      raise ArgumentError.new('tag is not Array')
    end
    array['tag'] = @tag
  end
  if @_alias != nil then
    if @_alias.class != Array
      raise ArgumentError.new('alias is not Array')
    end
    array['alias'] = @_alias
  end
  if @tag_and != nil  then
    if @tag_and.class != Array
      raise ArgumentError.new('tag_end is not Array')
    end
    array['tag_and'] = @tag_and
  end
  if @registration_id != nil then
    if @registration_id.class != Array
      raise ArgumentError.new('registration_id is not Array')
    end
    array['registration_id'] = @registration_id
  end
  return array
end