Skip to content
Open

test #242

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
8 changes: 6 additions & 2 deletions lib/plivo/base/resource_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,15 @@ def perform_list(params = nil)

def perform_list_with_response(params = nil)
response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
# parse_and_set(response_json)
objects = if response_json["response"]["objects"].empty?
[]
else
parse_and_set_list(response_json["response"]["objects"])
end
{
api_id: response_json["api_id"],
meta: response_json["response"]["meta"],
objects: parse_and_set_list(response_json["response"]["objects"])
objects: objects
}
end

Expand Down
68 changes: 33 additions & 35 deletions lib/plivo/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,48 +343,46 @@ def send_delete(resource_path, data, timeout, options = nil)

def handle_response_exceptions(response)
exception_mapping = {
400 => [
Exceptions::ValidationError,
'A parameter is missing or is invalid while accessing resource'
],
401 => [
Exceptions::AuthenticationError,
'Failed to authenticate while accessing resource'
],
404 => [
Exceptions::ResourceNotFoundError,
'Resource not found'
],
405 => [
Exceptions::InvalidRequestError,
'HTTP method used is not allowed to access resource'
],
409 => [
Exceptions::InvalidRequestError,
'Conflict'
],
422 => [
Exceptions::InvalidRequestError,
'Unprocessable Entity'
],
500 => [
Exceptions::PlivoServerError,
'A server error occurred while accessing resource'
]
400 => [
Exceptions::ValidationError,
'A parameter is missing or is invalid while accessing resource'
],
401 => [
Exceptions::AuthenticationError,
'Failed to authenticate while accessing resource'
],
404 => [
Exceptions::ResourceNotFoundError,
'Resource not found'
],
405 => [
Exceptions::InvalidRequestError,
'HTTP method used is not allowed to access resource'
],
409 => [
Exceptions::InvalidRequestError,
'Conflict'
],
422 => [
Exceptions::InvalidRequestError,
'Unprocessable Entity'
],
500 => [
Exceptions::PlivoServerError,
'A server error occurred while accessing resource'
]
}

response_json = response[:body]
return unless exception_mapping.key? response[:status]
return unless exception_mapping.key?(response[:status])

exception_now = exception_mapping[response[:status]]
error_message = if (response_json.is_a? Hash) && (response_json.key? 'error')
response_json['error']
error_message = if response[:body].is_a?(Hash) && response[:body].key?('error')
api_id = response[:body]['api_id']
error_message = response[:body]['error']
"API ID: #{api_id}, Error: #{error_message}"
else
exception_now[1] + " at: #{response[:url]}"
end
if error_message.is_a?(Hash) && error_message.key?('error')
error_message = error_message['error']
end

raise exception_now[0], error_message.to_s
end
Expand Down
50 changes: 25 additions & 25 deletions lib/plivo/resources/maskingsession.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,37 @@ def create(first_party:, second_party:, session_expiry: nil, call_time_limit: ni
first_party_play_url: nil, second_party_play_url: nil, recording_callback_method: nil, is_pin_authentication_required: nil,
generate_pin: nil, generate_pin_length: nil, first_party_pin: nil, second_party_pin: nil, pin_prompt_play: nil, pin_retry: nil,
pin_retry_wait: nil, incorrect_pin_play: nil, unknown_caller_play: nil, subaccount: nil, geomatch: nil)

valid_param?(:first_party, first_party, [String, Symbol], true)
valid_param?(:second_party, second_party, [String, Symbol], true)

params = {}
params[:first_party] = first_party
params[:second_party] = second_party
params[:session_expiry] = session_expiry if session_expiry
params[:call_time_limit] = call_time_limit if call_time_limit
params[:record] = record if record
params[:record_file_format] = record_file_format if record_file_format
params[:recording_callback_url] = recording_callback_url if recording_callback_url
params[:initiate_call_to_first_party] = initiate_call_to_first_party if initiate_call_to_first_party
params[:callback_url] = callback_url if callback_url
params[:callback_method] = callback_method if callback_method
params[:ring_timeout] = ring_timeout if ring_timeout
params[:first_party_play_url] = first_party_play_url if first_party_play_url
params[:second_party_play_url] = second_party_play_url if second_party_play_url
params[:recording_callback_method] = recording_callback_method if recording_callback_method
params[:is_pin_authentication_required] = is_pin_authentication_required if is_pin_authentication_required
params[:generate_pin] = generate_pin if generate_pin
params[:generate_pin_length] = generate_pin_length if generate_pin_length
params[:first_party_pin] = first_party_pin if first_party_pin
params[:second_party_pin] = second_party_pin if second_party_pin
params[:pin_prompt_play] = pin_prompt_play if pin_prompt_play
params[:pin_retry] = pin_retry if pin_retry
params[:pin_retry_wait] = pin_retry_wait if pin_retry_wait
params[:incorrect_pin_play] = incorrect_pin_play if incorrect_pin_play
params[:unknown_caller_play] = unknown_caller_play if unknown_caller_play
params[:subaccount] = subaccount if subaccount
params[:geomatch] = geomatch if geomatch

params[:session_expiry] = session_expiry unless session_expiry.nil?
params[:call_time_limit] = call_time_limit unless call_time_limit.nil?
params[:record] = record unless record.nil?
params[:record_file_format] = record_file_format unless record_file_format.nil?
params[:recording_callback_url] = recording_callback_url unless recording_callback_url.nil?
params[:initiate_call_to_first_party] = initiate_call_to_first_party unless initiate_call_to_first_party.nil?
params[:callback_url] = callback_url unless callback_url.nil?
params[:callback_method] = callback_method unless callback_method.nil?
params[:ring_timeout] = ring_timeout unless ring_timeout.nil?
params[:first_party_play_url] = first_party_play_url unless first_party_play_url.nil?
params[:second_party_play_url] = second_party_play_url unless second_party_play_url.nil?
params[:recording_callback_method] = recording_callback_method unless recording_callback_method.nil?
params[:is_pin_authentication_required] = is_pin_authentication_required unless is_pin_authentication_required.nil?
params[:generate_pin] = generate_pin unless generate_pin.nil?
params[:generate_pin_length] = generate_pin_length unless generate_pin_length.nil?
params[:first_party_pin] = first_party_pin unless first_party_pin.nil?
params[:second_party_pin] = second_party_pin unless second_party_pin.nil?
params[:pin_prompt_play] = pin_prompt_play unless pin_prompt_play.nil?
params[:pin_retry] = pin_retry unless pin_retry.nil?
params[:pin_retry_wait] = pin_retry_wait unless pin_retry_wait.nil?
params[:incorrect_pin_play] = incorrect_pin_play unless incorrect_pin_play.nil?
params[:unknown_caller_play] = unknown_caller_play unless unknown_caller_play.nil?
params[:subaccount] = subaccount unless subaccount.nil?
params[:geomatch] = geomatch unless geomatch.nil?
perform_create(params)
end

Expand Down