Class: TwilioRubyWrapper::QueueCondition
- Inherits:
-
Object
- Object
- TwilioRubyWrapper::QueueCondition
- Defined in:
- lib/twilio_ruby_wrapper/queue_condition.rb
Constant Summary collapse
- @@account_sid =
nil
- @@auth_token =
nil
Instance Attribute Summary collapse
-
#page_number ⇒ Object
Returns the value of attribute page_number.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#queues ⇒ Object
Returns the value of attribute queues.
Class Method Summary collapse
Instance Method Summary collapse
- #condition(value) ⇒ Object
- #find_by(*args) ⇒ Object
-
#initialize(condition: nil, page_number: 0, page_size: 50) ⇒ QueueCondition
constructor
A new instance of QueueCondition.
- #where(*args) ⇒ Object
Constructor Details
#initialize(condition: nil, page_number: 0, page_size: 50) ⇒ QueueCondition
Returns a new instance of QueueCondition.
13 14 15 16 17 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 13 def initialize(condition: nil, page_number: 0, page_size: 50) @condition = condition @page_number = page_number @page_size = page_size end |
Instance Attribute Details
#page_number ⇒ Object
Returns the value of attribute page_number.
3 4 5 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3 def page_number @page_number end |
#page_size ⇒ Object
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3 def page_size @page_size end |
#queues ⇒ Object
Returns the value of attribute queues.
3 4 5 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 3 def queues @queues end |
Class Method Details
.set_twilio_params(account_sid:, auth_token:) ⇒ Object
7 8 9 10 11 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 7 def self.set_twilio_params(account_sid:, auth_token:) @@account_sid = account_sid @@auth_token = auth_token true end |
Instance Method Details
#condition(value) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 56 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 |
#find_by(*args) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 37 def find_by(*args) set_twilio_account() 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} twilio_queues = @twilio_queue_list.list(params) queue = twilio_queues.select{|twilio_queue| @condition[value][build_value(twilio_queue.send(key), key)] }.map{|twilio_queue| Queue.new(twilio_queue) }.first queue end |
#where(*args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/twilio_ruby_wrapper/queue_condition.rb', line 19 def where(*args) set_twilio_account() 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} twilio_queues = @twilio_queue_list.list(params) queues = twilio_queues.select{|twilio_queue| @condition[value][build_value(twilio_queue.send(key), key)] }.map{|twilio_queue| Queue.new(twilio_queue) } queues end |