for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
require 'jsondoc'
require 'multi_json'
module RingCentralSdk::REST
class Event
attr_accessor :doc
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
def _hash_has_string_keys(hash={})
hash.each do |k,v|
return true if k.is_a? String
return false
def _symbolize_keys(hash={})
if _hash_has_string_keys hash
return MultiJson.decode(MultiJson.encode(hash), :symbolize_keys=>true)
return hash
def new_fax_count
new_type_count('fax')
def new_sms_count
new_type_count('sms')
def new_type_count(type)
count = 0
have_type = false
changes = @doc.getAttr('body.changes')
if changes.is_a?(Array) && changes.length > 0
changes.each do |change|
if change.key?(:type) && change[:type].to_s.downcase == type
have_type = true
if change.key?(:newCount)
count += change[:newCount]
return have_type ? count : -1
private :_hash_has_string_keys, :_symbolize_keys