Skip to content

Commit

Permalink
Moves statistics from task router client to individual classes
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Apr 3, 2015
1 parent 241948a commit ef71524
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 32 deletions.
1 change: 1 addition & 0 deletions lib/twilio-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require 'twilio-ruby/rest/sip/credential_lists/credentials'
require 'twilio-ruby/rest/sip/ip_access_control_lists'
require 'twilio-ruby/rest/sip/ip_access_control_lists/ip_addresses'
require 'twilio-ruby/rest/task_router/statistics'
require 'twilio-ruby/rest/task_router/activities'
require 'twilio-ruby/rest/task_router/events'
require 'twilio-ruby/rest/task_router/reservations'
Expand Down
14 changes: 14 additions & 0 deletions lib/twilio-ruby/rest/task_router/statistics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Twilio
module REST
module TaskRouter
module Statistics
def statistics(args={})
path = "#{@path}/Statistics"
response = @client.get(path, args, true)
statistic_class = Object.const_get("#{self.class.to_s}Statistics")
statistic_class.new(path, @client, response)
end
end
end
end
end
13 changes: 11 additions & 2 deletions lib/twilio-ruby/rest/task_router/task_queues.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module Twilio
module REST
module TaskRouter
class TaskQueues < Twilio::REST::NextGenListResource; end
class TaskQueue < InstanceResource; end
class TaskQueues < Twilio::REST::NextGenListResource
def statistics(args={})
path = "#{@path}/Statistics"
stats = Twilio::REST::TaskRouter::TaskQueuesStatistics.new path, @client
stats.list args, true
end
end

class TaskQueue < InstanceResource
include Statistics
end
end
end
end
9 changes: 7 additions & 2 deletions lib/twilio-ruby/rest/task_router/workers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
module Twilio
module REST
module TaskRouter
class Workers < Twilio::REST::NextGenListResource; end
class Worker < InstanceResource; end
class Workers < Twilio::REST::NextGenListResource
include Twilio::REST::TaskRouter::Statistics
end

class Worker < InstanceResource
include Twilio::REST::TaskRouter::Statistics
end
end
end
end
5 changes: 4 additions & 1 deletion lib/twilio-ruby/rest/task_router/workflows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module Twilio
module REST
module TaskRouter
class Workflows < Twilio::REST::NextGenListResource; end
class Workflow < InstanceResource; end

class Workflow < InstanceResource
include Twilio::REST::TaskRouter::Statistics
end
end
end
end
2 changes: 2 additions & 0 deletions lib/twilio-ruby/rest/task_router/workspaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module TaskRouter
class Workspaces < Twilio::REST::NextGenListResource; end

class Workspace < InstanceResource
include Twilio::REST::TaskRouter::Statistics

def initialize(path, client, params={})
super path, client, params
@submodule = :TaskRouter
Expand Down
45 changes: 18 additions & 27 deletions lib/twilio-ruby/rest/task_router_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,58 +121,49 @@ def respond_to?(method_name, include_private=false)
##
# Get statistics of a task queue.
def task_queue_statistics(task_queue_sid, *args) # :doc:
if task_queue_sid.nil?
raise ArgumentError, 'Task queue SID is required'
end
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/#{task_queue_sid}/Statistics"
response = get path, args, true
Twilio::REST::TaskRouter::TaskQueueStatistics.new path, self, response
warn "[DEPRECATED] task_queue_statistics is deprecated. " \
"Please call client.task_queue.get(sid).statistics."
task_queues.get(task_queue_sid).statistics
end

##
# Get statistics of task queues.
def task_queues_statistics(*args) # :doc:
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/TaskQueues/Statistics"
stats = Twilio::REST::TaskRouter::TaskQueuesStatistics.new path, self
stats.list args, true
warn "[DEPRECATED] task_queues_statistics is deprecated. " \
"Please call client.task_queues.statistics."
task_queues.statistics
end

##
# Get statistics of a worker.
def worker_statistics(worker_sid, *args) # :doc:
if worker_sid.nil?
raise ArgumentError, 'Worker SID is required'
end
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/#{worker_sid}/Statistics"
response = get path, args, true
Twilio::REST::TaskRouter::WorkerStatistics.new path, self, response
warn "[DEPRECATED] worker_statistics is deprecated. " \
"Please call client.worker.get(sid).statistics."
workers.get(worker_sid).statistics
end

##
# Get statistics of workers.
def workers_statistics(*args) # :doc:
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workers/Statistics"
response = get path, args, true
Twilio::REST::TaskRouter::WorkersStatistics.new path, self, response
warn "[DEPRECATED] workers_statistics is deprecated. " \
"Please call client.workers.statistics."
workers.statistics
end

##
# Get statistics of a workflow.
def workflow_statistics(workflow_sid, *args) # :doc:
if workflow_sid.nil?
raise ArgumentError, 'Workflow SID is required'
end
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Workflows/#{workflow_sid}/Statistics"
response = get path, args, true
Twilio::REST::TaskRouter::WorkflowStatistics.new path, self, response
warn "[DEPRECATED] workflow_statistics is deprecated. " \
"Please call client.workflow.get(sid).statistics."
workflows.get(workflow_sid).statistics
end

##
# Get statistics of a workspace.
def workspace_statistics(*args) # :doc:
path = "/#{API_VERSION}/Workspaces/#{@workspace_sid}/Statistics"
response = get path, args, true
Twilio::REST::TaskRouter::WorkspaceStatistics.new path, self, response
warn "[DEPRECATED] worker_statistics is deprecated. " \
"Please call client.workspace.statistics."
workspace.statistics
end

protected
Expand Down

0 comments on commit ef71524

Please sign in to comment.