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
35 changes: 35 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: [ "master" ]
pull_request:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.4']

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-version: '2.6.5'
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rake
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Dialpad Ruby Gem

![Tests](https://github.com/maddale/dialpad-ruby/workflows/Ruby/badge.svg)

A Ruby client for the Dialpad API that provides easy access to webhooks, subscriptions, contacts, and calls with full CRUD operations and comprehensive validation.

## Installation
Expand Down
2 changes: 1 addition & 1 deletion dialpad.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'faraday', '~> 2.0'
spec.add_dependency 'json', '~> 2.0'

spec.required_ruby_version = '>= 3.4.2'
spec.required_ruby_version = '>= 3.0.0'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 13.0'
Expand Down
11 changes: 7 additions & 4 deletions lib/dialpad.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
require 'dialpad/version'

module Dialpad
class Error < StandardError; end
class ConfigurationError < Error; end
class APIError < Error; end
end

require 'dialpad/client'
require 'dialpad/validations'
require 'dialpad/dialpad_object'
Expand All @@ -9,10 +16,6 @@
require 'dialpad/call'

module Dialpad
class Error < StandardError; end
class ConfigurationError < Error; end
class APIError < Error; end

class << self
attr_writer :base_url, :token

Expand Down
65 changes: 28 additions & 37 deletions lib/dialpad/call.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
module Dialpad
class Call < DialpadObject
class RequiredAttributeError < StandardError; end
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
date_started
call_id
state
direction
external_number
internal_number
date_rang
date_first_rang
date_queued
target_availability_status
call_recording_ids
callback_requested
contact
csat_score
date_connected
date_ended
talk_time
hold_time
date_first_rang
date_queued
date_rang
date_started
direction
duration
total_duration
contact
target
entry_point_call_id
entry_point_target
operator_call_id
proxy_target
event_timestamp
external_number
group_id
master_call_id
hold_time
internal_number
integrations
is_transferred
csat_score
routing_breadcrumbs
event_timestamp
mos_score
labels
was_recorded
master_call_id
mos_score
operator_call_id
proxy_target
recording_details
routing_breadcrumbs
state
talk_time
target
target_availability_status
total_duration
transcription_text
voicemail_link
voicemail_recording_id
call_recording_ids
transcription_text
recording_details
integrations
controller
action
was_recorded
).freeze

class << self
Expand All @@ -59,17 +57,10 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/calllist
def list(params = {})
data = Dialpad.client.get('call', params)
return [] if data['items'].nil? || data['items'].empty?

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

private

def from_hash(hash)
symbolized = hash.respond_to?(:to_h) ? hash.to_h.transform_keys(&:to_sym) : hash
attrs = ATTRIBUTES.filter_map { |key| [key, symbolized[key]] if symbolized.key?(key) }.to_h
new(attrs)
end
end
end
end
24 changes: 16 additions & 8 deletions lib/dialpad/contact.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Dialpad
class Contact
class RequiredAttributeError < StandardError; end
class Contact < DialpadObject
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
company_name
Expand All @@ -27,40 +27,48 @@ class << self
def retrieve(id = nil)
validate_required_attribute(id, "ID")

Dialpad.client.get("contacts/#{id}")
data = Dialpad.client.get("contacts/#{id}")
new(data)
end

# https://developers.dialpad.com/reference/contactslist
def list(params = {})
Dialpad.client.get('contacts', params)
data = Dialpad.client.get('contacts', params)
return [] if data['items'].nil? || data['items'].empty?

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

# https://developers.dialpad.com/reference/contactscreate
def create(attributes = {})
validate_required_attributes(attributes, %i(first_name last_name))

Dialpad.client.post('contacts', attributes)
data = Dialpad.client.post('contacts', attributes)
new(data)
end

# https://developers.dialpad.com/reference/contactscreate_with_uid
def create_or_update(attributes = {})
validate_required_attributes(attributes, %i(first_name last_name uid))

Dialpad.client.put('contacts', attributes)
data = Dialpad.client.put('contacts', attributes)
new(data)
end

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

Dialpad.client.patch("contacts/#{id}", attributes)
data = Dialpad.client.patch("contacts/#{id}", attributes)
new(data)
end

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

Dialpad.client.delete("contacts/#{id}")
data = Dialpad.client.delete("contacts/#{id}")
new(data)
end
end
end
Expand Down
13 changes: 11 additions & 2 deletions lib/dialpad/dialpad_object.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
module Dialpad
class DialpadObject
class RequiredAttributeError < Dialpad::APIError; end

attr_reader :attributes

def initialize(attributes = {})
@attributes = attributes.transform_keys(&:to_sym)
@attributes =
attributes.each_with_object({}) do |(key, value), hash|
hash[key.to_sym] = value
end
end

def method_missing(method, *args)
@attributes.key?(method) ? @attributes[method] : super
if @attributes.key?(method)
@attributes[method]
else
super
end
end

def respond_to_missing?(method, include_private = false)
Expand Down
4 changes: 3 additions & 1 deletion lib/dialpad/subscriptions/call_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Dialpad
module Subscriptions
class CallEvent < DialpadObject
class RequiredAttributeError < StandardError; end
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
call_states
Expand All @@ -25,6 +25,8 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhook_call_event_subscriptionlist
def list(params = {})
data = Dialpad.client.get('subscriptions/call', params)
return [] if data['items'].nil? || data['items'].empty?

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

Expand Down
4 changes: 3 additions & 1 deletion lib/dialpad/subscriptions/contact_event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Dialpad
module Subscriptions
class ContactEvent < DialpadObject
class RequiredAttributeError < StandardError; end
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
contact_type
Expand All @@ -25,6 +25,8 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhook_contact_event_subscriptionlist
def list(params = {})
data = Dialpad.client.get('subscriptions/contact', params)
return [] if data['items'].nil? || data['items'].empty?

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

Expand Down
4 changes: 3 additions & 1 deletion lib/dialpad/webhook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Dialpad
class Webhook < DialpadObject
class RequiredAttributeError < StandardError; end
class RequiredAttributeError < Dialpad::DialpadObject::RequiredAttributeError; end

ATTRIBUTES = %i(
hook_url
Expand All @@ -22,6 +22,8 @@ def retrieve(id = nil)
# https://developers.dialpad.com/reference/webhookslist
def list(params = {})
data = Dialpad.client.get('webhooks', params)
return [] if data['items'].nil? || data['items'].empty?

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

Expand Down
Loading
Loading