Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/dialpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class APIError < Error; end
require 'dialpad/validations'
require 'dialpad/dialpad_object'
require 'dialpad/webhook'

require 'dialpad/call'
require 'dialpad/contact'
require 'dialpad/department'
require 'dialpad/subscriptions/call_event'
require 'dialpad/subscriptions/contact_event'
require 'dialpad/contact'
require 'dialpad/user'
require 'dialpad/call'
require 'dialpad/websocket'

module Dialpad
Expand Down
83 changes: 83 additions & 0 deletions lib/dialpad/department.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module Dialpad
class Department < DialpadObject
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
auto_call_recording
availability_status
country
first_action
friday_hours
group_description
hold_queue
hours_on
id
monday_hours
name
no_operators_action
office_id
phone_numbers
ring_seconds
routing_options
saturday_hours
state
sunday_hours
thursday_hours
timezone
tuesday_hours
voice_intelligence
wednesday_hours
).freeze

def operator_users
response = Dialpad.client.get("departments/#{id}/operators")
return [] if response.body['users'].nil?

response.body['users'].map { |user| User.new(user) }
end

class << self
include Validations

# https://developers.dialpad.com/reference/departmentsget
def retrieve(id = nil)
validate_required_attribute(id, "ID")

response = Dialpad.client.get("departments/#{id}")
new(response.body)
end

# https://developers.dialpad.com/reference/departmentslistall
def list(params = {})
response = Dialpad.client.get('departments', params)
return [] if response.body['items'].nil?

response.body['items'].map { |item| new(item) }
end

# https://developers.dialpad.com/reference/departmentscreate
def create(attributes = {})
validate_required_attributes(attributes, %i(name office_id))

response = Dialpad.client.post('departments', attributes)
new(response.body)
end

# https://developers.dialpad.com/reference/departmentsupdate
def update(id = nil, attributes = {})
validate_required_attribute(id, "ID")

response = Dialpad.client.patch("departments/#{id}", attributes)
new(response.body)
end

# https://developers.dialpad.com/reference/departmentsdelete
def destroy(id = nil)
validate_required_attribute(id, "ID")

response = Dialpad.client.delete("departments/#{id}")
new(response.body)
end
end
end
end
8 changes: 8 additions & 0 deletions lib/dialpad/dialpad_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,13 @@ def method_missing(method, *args)
def respond_to_missing?(method, include_private = false)
self.class::ATTRIBUTES.include?(method) || super
end

def update(attributes)
self.class.update(id, attributes)
end

def destroy
self.class.destroy(id)
end
end
end
102 changes: 0 additions & 102 deletions spec/dialpad/call_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,108 +346,6 @@
it 'raises NoMethodError for undefined attributes' do
expect { call.undefined_attribute }.to raise_error(NoMethodError)
end

it 'responds to defined attributes' do
expect(call.respond_to?(:call_id)).to be true
expect(call.respond_to?(:direction)).to be true
expect(call.respond_to?(:state)).to be true
expect(call.respond_to?(:duration)).to be true
end

it 'does not respond to undefined attributes' do
expect(call.respond_to?(:undefined_attribute)).to be false
end
end

describe 'call recording attributes' do
let(:call_with_recordings) do
described_class.new(
call_id: 5780678246121472,
was_recorded: true,
call_recording_ids: ['rec_123', 'rec_456'],
voicemail_link: 'https://example.com/voicemail1.mp3',
voicemail_recording_id: 'vm_789',
recording_details: [
{ 'id' => 'rec_123', 'url' => 'https://example.com/recording1.mp3' },
{ 'id' => 'rec_456', 'url' => 'https://example.com/recording2.mp3' }
]
)
end

it 'handles recording data' do
expect(call_with_recordings.was_recorded).to be true
expect(call_with_recordings.call_recording_ids).to eq(['rec_123', 'rec_456'])
expect(call_with_recordings.voicemail_link).to eq('https://example.com/voicemail1.mp3')
expect(call_with_recordings.voicemail_recording_id).to eq('vm_789')
expect(call_with_recordings.recording_details).to be_an(Array)
expect(call_with_recordings.recording_details.length).to eq(2)
end
end

describe 'CSAT attributes' do
let(:call_with_csat) do
described_class.new(
call_id: 5780678246121472,
csat_score: 4,
mos_score: 4.2
)
end

it 'handles CSAT data' do
expect(call_with_csat.csat_score).to eq(4)
expect(call_with_csat.mos_score).to eq(4.2)
end
end

describe 'call routing attributes' do
let(:call_with_routing) do
described_class.new(
call_id: 5780678246121472,
routing_breadcrumbs: ['ivr', 'sales_queue', 'agent_123'],
entry_point_target: { 'type' => 'department', 'name' => 'sales' },
proxy_target: { 'type' => 'agent', 'id' => 'agent_456' },
target: {
'id' => 1234567890123456,
'type' => 'user',
'name' => 'Agent Smith'
}
)
end

it 'handles routing information' do
expect(call_with_routing.routing_breadcrumbs).to eq(['ivr', 'sales_queue', 'agent_123'])
expect(call_with_routing.entry_point_target).to be_a(Hash)
expect(call_with_routing.proxy_target).to be_a(Hash)
expect(call_with_routing.target).to be_a(Hash)
expect(call_with_routing.target['name']).to eq('Agent Smith')
end
end

describe 'call metadata' do
let(:call_with_metadata) do
described_class.new(
call_id: 5780678246121472,
group_id: 123456789,
operator_call_id: 987654321,
master_call_id: 111222333,
entry_point_call_id: 444555666,
event_timestamp: 1759338816268,
talk_time: 120,
hold_time: 30,
total_duration: 150
)
end

it 'handles call metadata' do
expect(call_with_metadata.group_id).to eq(123456789)
expect(call_with_metadata.operator_call_id).to eq(987654321)
expect(call_with_metadata.master_call_id).to eq(111222333)
expect(call_with_metadata.entry_point_call_id).to eq(444555666)
expect(call_with_metadata.event_timestamp).to eq(1759338816268)
expect(call_with_metadata.talk_time).to eq(120)
expect(call_with_metadata.hold_time).to eq(30)
expect(call_with_metadata.total_duration).to eq(150)
end
end
end

Expand Down
Loading
Loading