Class: TwilioRubyWrapper::CallCondition

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

Constant Summary collapse

@@account_sid =
nil
@@auth_token =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition: nil, filter: {}, page_number: 0, page_size: nil) ⇒ CallCondition

Returns a new instance of CallCondition.



13
14
15
16
17
18
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 13

def initialize(condition: nil, filter: {}, page_number: 0, page_size: nil)
  @condition = condition
  @filter = filter
  @page_number = page_number
  @page_size = page_size
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

Class Method Details

.set_twilio_params(account_sid:, auth_token:) ⇒ Object



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

def self.set_twilio_params(account_sid:, auth_token:)
  @@account_sid = 
  @@auth_token = auth_token
  true
end

Instance Method Details

#condition(value) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 65

def condition(value)
  if !(Symbol === value)
    raise
  end

  condition = nil
  case value
  when :eq
    condition  = -> (x) { -> (y) { y == x }}
  when :lt
    condition  = -> (x) { -> (y) { y < x }}
  when :lteq
    condition  = -> (x) { -> (y) { y <= x }}
  when :gt
    condition  = -> (x) { -> (y) { y > x }}
  when :gteq
    condition  = -> (x) { -> (y) { y >= x }}
  else
    raise
  end

  @condition = condition

  self
end

#filter(*args) ⇒ Object



59
60
61
62
63
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 59

def filter(*args)
  hash = args.first
  @filter = hash
  self
end

#find_by(*args) ⇒ Object



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 39

def find_by(*args)
  ()
  condition(:eq)
  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_size: @page_size}
  params.merge!(@filter) unless @filter.empty?
  twilio_calls = @twilio_call_list.list(params)
  call = twilio_calls.select {|twilio_call| @condition[value][build_value(twilio_call.send(key), key)] }.map{|twilio_call| Call.new(twilio_call) }.first

  call
end

#where(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/twilio_ruby_wrapper/call_condition.rb', line 20

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)

  params = {page_size: @page_size}
  params.merge!(@filter) unless @filter.empty?
  twilio_calls = @twilio_call_list.list(params)
  calls = twilio_calls.select{|twilio_call| @condition[value][build_value(twilio_call.send(key), key)] }.map{|twilio_call| Call.new(twilio_call) }

  calls
end