Class: Wavix::Cdrs::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wavix/cdrs/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/wavix/cdrs/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#get(request_options: {}, **params) ⇒ Wavix::Types::CdrResponse

Returns the call detail record for the call identified by call_id.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :call_id (String)
  • :show_transcription (Boolean, nil)

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/wavix/cdrs/client.rb', line 192

def get(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["show_transcription"] = params[:show_transcription] if params.key?(:show_transcription)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/cdrs/#{URI.encode_uri_component(params[:call_id].to_s)}",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::CdrResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Wavix::Types::CdrListResponse

Returns a paginated list of call detail records for the authenticated account, within the requested date range.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :from (String)
  • :to (String)
  • :type (String)
  • :disposition (Wavix::Types::CallDisposition, nil)
  • :from_search (String, nil)
  • :to_search (String, nil)
  • :sip_trunk (String, nil)
  • :uuid (String, nil)
  • :page (Integer, nil)
  • :per_page (Integer, nil)

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/wavix/cdrs/client.rb', line 34

def list(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["type"] = params[:type] if params.key?(:type)
  query_params["disposition"] = params[:disposition] if params.key?(:disposition)
  query_params["from_search"] = params[:from_search] if params.key?(:from_search)
  query_params["to_search"] = params[:to_search] if params.key?(:to_search)
  query_params["sip_trunk"] = params[:sip_trunk] if params.key?(:sip_trunk)
  query_params["uuid"] = params[:uuid] if params.key?(:uuid)
  query_params["page"] = params[:page] if params.key?(:page)
  query_params["per_page"] = params[:per_page] if params.key?(:per_page)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/cdrs",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::CdrListResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list_all(request_options: {}, **params) ⇒ String

Streams matching call detail records as newline-delimited JSON (NDJSON), one record per line, for bulk export.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :from (String)
  • :to (String)
  • :type (String)
  • :disposition (Wavix::Types::CallDisposition, nil)
  • :from_search (String, nil)
  • :to_search (String, nil)
  • :sip_trunk (String, nil)
  • :uuid (String, nil)
  • :page (Integer, nil)
  • :per_page (Integer, nil)

Returns:

  • (String)

Raises:

  • (error_class)


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/wavix/cdrs/client.rb', line 239

def list_all(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["type"] = params[:type] if params.key?(:type)
  query_params["disposition"] = params[:disposition] if params.key?(:disposition)
  query_params["from_search"] = params[:from_search] if params.key?(:from_search)
  query_params["to_search"] = params[:to_search] if params.key?(:to_search)
  query_params["sip_trunk"] = params[:sip_trunk] if params.key?(:sip_trunk)
  query_params["uuid"] = params[:uuid] if params.key?(:uuid)
  query_params["page"] = params[:page] if params.key?(:page)
  query_params["per_page"] = params[:per_page] if params.key?(:per_page)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/cdrs/all",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#retranscribe(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse

Transcribes the recording of the call identified by call_id. Transcription is asynchronous; poll the transcription endpoint for the result. Billed per minute at the account's call-transcription rate; fails with an insufficient-funds error when the balance cannot cover it.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :call_id (String)

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/wavix/cdrs/client.rb', line 118

def retranscribe(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request_data = Wavix::Cdrs::Types::CdrRetranscriptionRequest.new(params).to_h
  non_body_param_names = %w[call_id]
  body = request_data.except(*non_body_param_names)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PUT",
    path: "v1/cdrs/#{URI.encode_uri_component(params[:call_id].to_s)}/retranscribe",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::SuccessResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#search(request_options: {}, **params) ⇒ Wavix::Types::CdrTranscriptionSearchResponse

Searches call transcriptions for the given keywords or phrases and returns the matching CDRs with their transcriptions.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/wavix/cdrs/client.rb', line 81

def search(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/cdrs",
    body: Wavix::Cdrs::Types::CdrSearchRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::CdrTranscriptionSearchResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#transcription ⇒ Wavix::Transcription::Client

Returns:

  • (Wavix::Transcription::Client)


273
274
275
# File 'lib/wavix/cdrs/client.rb', line 273

def transcription
  @transcription ||= Wavix::Cdrs::Transcription::Client.new(client: @client)
end

#transcriptions(request_options: {}, **params) ⇒ Wavix::Types::CdrTranscriptionResponse

Returns the transcription of the recorded call identified by call_id. Alias of the transcription endpoint.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :call_id (String)

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/wavix/cdrs/client.rb', line 157

def transcriptions(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/cdrs/#{URI.encode_uri_component(params[:call_id].to_s)}/transcriptions",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::CdrTranscriptionResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end