Class: Pinnacle::Calls::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/pinnacle/calls/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/pinnacle/calls/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(request_options: {}, **params) ⇒ Pinnacle::Types::Call

End a live call. Terminal calls are returned unchanged.

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):

  • :id (String)

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/pinnacle/calls/client.rb', line 145

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

#create(request_options: {}, **params) ⇒ Pinnacle::Types::CreatedCall

Start an outbound voice call from a voice-enabled phone number owned by your team.

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:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pinnacle/calls/client.rb', line 76

def create(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "calls",
    body: Pinnacle::Calls::Types::CreateCallParams.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::CreatedCall.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#create_stream_token(request_options: {}, **params) ⇒ Pinnacle::Types::CallStreamToken

Mint a short-lived WebSocket token for a call. Use the returned ‘stream_url` to connect to Pinnacle’s bidirectional voice stream.

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):

  • :id (String)

Returns:



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/pinnacle/calls/client.rb', line 260

def create_stream_token(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request_data = Pinnacle::Calls::Types::CreateStreamTokenParams.new(params).to_h
  non_body_param_names = %w[id]
  body = request_data.except(*non_body_param_names)

  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "calls/#{URI.encode_uri_component(params[:id].to_s)}/stream-token",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::CallStreamToken.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete_recording(request_options: {}, **params) ⇒ untyped

Delete the canonical recording and queued fragments for a terminal call.

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):

  • :id (String)

Returns:

  • (untyped)

Raises:

  • (error_class)


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/pinnacle/calls/client.rb', line 338

def delete_recording(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "calls/#{URI.encode_uri_component(params[:id].to_s)}/recording",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

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

#download_recording(request_options: {}, **params) ⇒ Pinnacle::Types::RecordingDownload

Return a short-lived signed URL for the call recording.

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):

  • :id (String)
  • :expires_in (Integer, nil)

Returns:



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/pinnacle/calls/client.rb', line 300

def download_recording(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["expires_in"] = params[:expires_in] if params.key?(:expires_in)

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

#get(request_options: {}, **params) ⇒ Pinnacle::Types::Call

Retrieve one voice call by its Pinnacle 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):

  • :id (String)

Returns:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/pinnacle/calls/client.rb', line 111

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

#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListCallsResponse

List voice calls for your team. Results are sorted newest first.

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):

Returns:



32
33
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
# File 'lib/pinnacle/calls/client.rb', line 32

def list(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["cursor"] = params[:cursor] if params.key?(:cursor)
  query_params["state"] = params[:state] if params.key?(:state)
  query_params["direction"] = params[:direction] if params.key?(:direction)
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["created_after"] = params[:created_after] if params.key?(:created_after)
  query_params["created_before"] = params[:created_before] if params.key?(:created_before)

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

#list_events(request_options: {}, **params) ⇒ Pinnacle::Types::ListCallEventsResponse

List the event timeline for a call.

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):

  • :id (String)
  • :limit (Integer, nil)
  • :cursor (String, nil)

Returns:



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/pinnacle/calls/client.rb', line 220

def list_events(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["cursor"] = params[:cursor] if params.key?(:cursor)

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

#update(request_options: {}, **params) ⇒ Pinnacle::Types::Call

Replace a call’s metadata. For live calls, future call events carry the updated metadata.

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):

  • :id (String)

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/pinnacle/calls/client.rb', line 179

def update(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request_data = Pinnacle::Calls::Types::UpdateCallParams.new(params).to_h
  non_body_param_names = %w[id]
  body = request_data.except(*non_body_param_names)

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