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
1 change: 1 addition & 0 deletions lib/dialpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class APIError < Error; end
require 'dialpad/webhook'

require 'dialpad/call'
require 'dialpad/call_center'
require 'dialpad/contact'
require 'dialpad/department'
require 'dialpad/subscriptions/call_event'
Expand Down
4 changes: 1 addition & 3 deletions lib/dialpad/call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/calllist
def list(params = {})
response = Dialpad.client.get('call', params)
return [] if response.body['items'].nil?

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

# https://developers.dialpad.com/reference/callactionshangup
Expand Down
73 changes: 73 additions & 0 deletions lib/dialpad/call_center.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
module Dialpad
class CallCenter < DialpadObject
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
advanced_settings
alerts
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
state
thursday_hours
timezone
tuesday_hours
voice_intelligence
wednesday_hours
).freeze

class << self
include Validations

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

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

# https://developers.dialpad.com/reference/callcenterslistall
def list(params = {})
response = Dialpad.client.get('callcenters', params)
paginated_response_from(response)
end

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

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

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

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

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

response = Dialpad.client.delete("callcenters/#{id}")
new(response.body)
end
end
end
end
4 changes: 1 addition & 3 deletions lib/dialpad/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/contactslist
def list(params = {})
response = Dialpad.client.get('contacts', params)
return [] if response.body['items'].nil?

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

# https://developers.dialpad.com/reference/contactscreate
Expand Down
4 changes: 1 addition & 3 deletions lib/dialpad/department.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def retrieve(id = nil)
# 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) }
paginated_response_from(response)
end

# https://developers.dialpad.com/reference/departmentscreate
Expand Down
16 changes: 16 additions & 0 deletions lib/dialpad/dialpad_object.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
module Dialpad
PaginatedResponse = Struct.new(:cursor, :items)

class DialpadObject
class RequiredAttributeError < Dialpad::APIError; end

attr_reader :attributes

class << self
def paginated_response_from(response)
cursor = response.body['cursor']
items =
if response.body['items'].nil?
[]
else
response.body['items'].map { |item| new(item) }
end

PaginatedResponse.new(cursor, items)
end
end

def initialize(attributes = {})
@attributes =
attributes.each_with_object({}) do |(key, value), hash|
Expand Down
4 changes: 1 addition & 3 deletions lib/dialpad/subscriptions/call_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhook_call_event_subscriptionlist
def list(params = {})
response = Dialpad.client.get('subscriptions/call', params)
return [] if response.body['items'].nil?

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

# https://developers.dialpad.com/reference/webhook_call_event_subscriptioncreate
Expand Down
4 changes: 1 addition & 3 deletions lib/dialpad/subscriptions/contact_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhook_contact_event_subscriptionlist
def list(params = {})
response = Dialpad.client.get('subscriptions/contact', params)
return [] if response.body['items'].nil?

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

# https://developers.dialpad.com/reference/webhook_contact_event_subscriptioncreate
Expand Down
8 changes: 2 additions & 6 deletions lib/dialpad/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; e
do_not_disturb
emails
first_name
group_details
id
image_url
international_dialing_enabled
Expand All @@ -39,12 +40,7 @@ class << self
# https://developers.dialpad.com/reference/userslist
def list(params = {})
response = Dialpad.client.get('users', params)
return [] if response.body['items'].nil?

structure = {}
structure[:cursor] = response.body['cursor'] unless response.body['cursor'].nil?
structure[:items] = response.body['items'].map { |item| new(item) }
structure
paginated_response_from(response)
end

# https://developers.dialpad.com/reference/usersget
Expand Down
4 changes: 1 addition & 3 deletions lib/dialpad/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhookslist
def list(params = {})
response = Dialpad.client.get('webhooks', params)
return [] if response.body['items'].nil?

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

# https://developers.dialpad.com/reference/webhookscreate
Expand Down
Loading
Loading