Class: RingCentralSdk::REST::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ringcentral_sdk/rest/event.rb

Overview

Event represents a Subscription API event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Event

Returns a new instance of Event.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ringcentral_sdk/rest/event.rb', line 9

def initialize(data = nil)
  if data.is_a? JsonDoc::Document
    @doc = data
  elsif data.is_a? Hash
    data = _symbolize_keys data
    @doc = JsonDoc::Document.new(data, false, false, false)
  elsif data.nil?
    @doc = JsonDoc::Document.new({}, false, false, false)
  else
    raise 'initialize needs JsonDoc::Document or Hash argument'
  end
end

Instance Attribute Details

#docObject

Returns the value of attribute doc.



8
9
10
# File 'lib/ringcentral_sdk/rest/event.rb', line 8

def doc
  @doc
end

Instance Method Details

#new_fax_countObject



36
37
38
# File 'lib/ringcentral_sdk/rest/event.rb', line 36

def new_fax_count
  new_type_count('fax')
end

#new_sms_countObject



40
41
42
# File 'lib/ringcentral_sdk/rest/event.rb', line 40

def new_sms_count
  new_type_count('sms')
end

#new_type_count(type) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ringcentral_sdk/rest/event.rb', line 44

def new_type_count(type)
  count = 0
  have_type = false
  changes = @doc.getAttr('body.changes')
  if changes.is_a?(Array) && !changes.empty?
    changes.each do |change|
      if change.key?(:type) && change[:type].to_s.downcase == type
        have_type = true
        count += change[:newCount] if change.key? :newCount
      end
    end
  end
  have_type ? count : -1
end