Class: TwilioRubyWrapper::CallCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio_ruby_wrapper/call_condition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calls:, condition:, filter: {}) ⇒ CallCondition



5
6
7
8
9
10
11
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 5

def initialize(calls:, condition:, filter: {})
  @calls = calls
  @condition = condition
  @filter = filter
  @page_number = 0
  @page_size = 50
end

Instance Attribute Details

#callsObject

Returns the value of attribute calls.



3
4
5
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 3

def calls
  @calls
end

#page_numberObject

Returns the value of attribute page_number.



3
4
5
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 3

def page_number
  @page_number
end

#page_sizeObject

Returns the value of attribute page_size.



3
4
5
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 3

def page_size
  @page_size
end

Instance Method Details

#find_by(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 36

def find_by(*args)
  hash = args.first

  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
    raise
  end

  key = hash.keys.first
  value = build_value(hash[key], key)

  params = {page: @page_number, page_size: @page_size}
  params.merge!(@filter) unless @filter.empty?
  queue_set = @calls.list(params)
  t = nil
  until queue_set.empty? do
    t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }.first
    break unless t.nil?
    queue_set = queue_set.next_page
  end
  
  t
end

#where(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 13

def where(*args)
  hash = args.first

  if !(Hash === hash) || hash.values.any? {|v| v.nil? || Array === v || Hash === v } || hash.size >= 2
    raise
  end

  key = hash.keys.first
  value = build_value(hash[key], key)

  calls = []
  params = {page: @page_number, page_size: @page_size}
  params.merge!(@filter) unless @filter.empty?
  queue_set = @calls.list(params)
  until queue_set.empty? do
    t = queue_set.select {|queue| @condition[value][build_value(queue.send(key), key)] }
    calls.concat(t) unless t.empty?
    queue_set = queue_set.next_page
  end
  
  calls
end