Class: Twilio::TaskRouter::WorkflowConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/twilio-ruby/task_router/workflow_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules, default_target) ⇒ WorkflowConfiguration

Returns a new instance of WorkflowConfiguration.



7
8
9
10
# File 'lib/twilio-ruby/task_router/workflow_builder.rb', line 7

def initialize(rules, default_target)
  @rules = rules
  @default_target = default_target
end

Class Method Details

.parse_json(json_data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/twilio-ruby/task_router/workflow_builder.rb', line 31

def self.parse_json(json_data)
  task_routing = JSON.parse(json_data)['task_routing']

  filters = task_routing['filters']
  rules = Array.new
  filters.each do |rule|
    rules.push(Twilio::TaskRouter::WorkflowRule.parse_json(rule))
  end

  default_filter = Twilio::TaskRouter::WorkflowRuleTarget.parse_json(task_routing['default_filter'])
  Twilio::TaskRouter::WorkflowConfiguration.new rules, default_filter
end

Instance Method Details

#default_targetObject



16
17
18
# File 'lib/twilio-ruby/task_router/workflow_builder.rb', line 16

def default_target
  @default_target
end

#rulesObject



12
13
14
# File 'lib/twilio-ruby/task_router/workflow_builder.rb', line 12

def rules
  @rules
end

#to_jsonObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/twilio-ruby/task_router/workflow_builder.rb', line 20

def to_json
  filters = Array.new
  @rules.each do |rule|
    filters.push(rule.to_json)
  end
  
  task_routing = {filters: filters, default_filter: @default_target.to_json}
  config = {task_routing: task_routing}
  config.to_json
end