# frozen_string_literal: true module TwilioBase module TaskRouter class Workspace class << self include TwilioBase::Clients DEFAULT_TEMPLATE = 'FIFO' REQUIRED_EVENTS = %w[ task.canceled task.completed task.updated workflow.timeout ].freeze def create(friendly_name:) workspace_client.create( event_callback_url: event_callback_url, events_filter: events, friendly_name: friendly_name, multi_task_enabled: true, template: DEFAULT_TEMPLATE ) end def find(sid) workspace_client(sid) end private def event_callback_url TwilioBase::Engine.routes.url_helpers.task_router_callbacks_url end def workspace_client(sid = nil) if sid rest_client.taskrouter.v1.workspaces(sid) else rest_client.taskrouter.v1.workspaces end end def events REQUIRED_EVENTS.join(',') end end end end end