From 138a2cf32b7a34222ec3f4a4128d074f855244c8 Mon Sep 17 00:00:00 2001 From: Ali Yazdani Date: Fri, 24 Jun 2022 17:04:37 -0700 Subject: [PATCH 1/2] 1. moved limit/offset checks to top of method so raising is done early 2. added missing keys to array and consolidated the conditionals to remove some repetition and hopefully make it more readable --- lib/plivo/resources/calls.rb | 69 ++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/lib/plivo/resources/calls.rb b/lib/plivo/resources/calls.rb index c4f53403..dd7c939a 100644 --- a/lib/plivo/resources/calls.rb +++ b/lib/plivo/resources/calls.rb @@ -275,14 +275,14 @@ def initialize(client, resource_list_json = nil) # @option options [String] :parent_call_uuid - The call_uuid of the first leg in an ongoing conference call. It is recommended to use this parameter in scenarios where a member who is already present in the conference intends to add new members by initiating outbound API calls. This minimizes the delay in adding a new memeber to the conference. # @option options [Boolean] :error_parent_not_found - if set to true and the parent_call_uuid cannot be found, the API request would return an error. If set to false, the outbound call API request will be executed even if the parent_call_uuid is not found. Defaults to false. # @return [Call] Call - def create(from, to, answer_url, options = nil) + def create(from, to, answer_url, options = nil) valid_param?(:from, from, [String, Symbol, Integer], true) valid_param?(:to, to, Array, true) to.each do |to_num| valid_param?(:to_num, to_num, [Integer, String, Symbol], true) end valid_param?(:answer_url, answer_url, [String, Symbol], true) - + params = { from: from, @@ -345,31 +345,6 @@ def list(options = nil) return perform_list if options.nil? valid_param?(:options, options, Hash, true) - params = {} - params_expected = %i[ - subaccount bill_duration bill_duration__gt bill_duration__gte - bill_duration__lt bill_duration__lte end_time end_time__gt - end_time__gte end_time__lt end_time__lte parent_call_uuid hangup_source - ] - params_expected.each do |param| - if options.key?(param) && - valid_param?(param, options[param], [String, Symbol], true) - params[param] = options[param] - end - end - - if options.key?(:call_direction) && - valid_param?(:call_direction, options[:call_direction], - [String, Symbol], true, %w[inbound outbound]) - params[:call_direction] = options[:call_direction] - end - - %i[offset limit hangup_cause_code].each do |param| - if options.key?(param) && valid_param?(param, options[param], [Integer, Integer], true) - params[param] = options[param] - end - end - raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0 if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0) @@ -377,6 +352,46 @@ def list(options = nil) "fetched is 20. limit can't be more than 20 or less than 1") end + # initial list of possible params + params = %i[ + bill_duration + bill_duration__gt + bill_duration__gte + bill_duration__lt + bill_duration__lte + call_direction + end_time + end_time__gt + end_time__gte + end_time__lt + end_time__lte + from_number + hangup_cause_code + hangup_source + limit + offset + parent_call_uuid + subaccount + to_number + ].reduce({}) do |result_hash, param| + if options.key?(param) + if param == :call_direction + if valid_param?(:call_direction, options[:call_direction], + [String, Symbol], true, %w[inbound outbound]) + result_hash[:call_direction] = options[:call_direction] + end + elsif %i[offset limit hangup_cause_code].include?(param) + if valid_param?(param, options[param], [Integer, Integer], true) + result_hash[param] = options[param] + end + elsif valid_param?(param, options[param], [String, Symbol], true) + result_hash[param] = options[param] + end + end + + result_hash + end + perform_list(params) end From 626280ea13b8067ef26b573e7d2f9eaab4e904ef Mon Sep 17 00:00:00 2001 From: abhishekgupta Date: Thu, 30 Jun 2022 12:36:50 +0530 Subject: [PATCH 2/2] stir_verification params add into Retrieve calls and minor version change --- CHANGELOG.md | 3 +++ README.md | 2 +- lib/plivo/resources/calls.rb | 1 + lib/plivo/version.rb | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98ea83ce..283895e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## [4.27.1](https://github.com/plivo/plivo-ruby/tree/v4.27.1) (2022-06-30) +- `from_number`, `to_number` and `stir_verification` added to filter param [Retrieve all calls] (https://www.plivo.com/docs/voice/api/call#retrieve-all-calls) + ## [4.27.0](https://github.com/plivo/plivo-ruby/tree/v4.27.0) (2022-05-05) **Feature - List all recordings** - `from_number` and `to_number` added to filter param [List all recordings](https://www.plivo.com/docs/voice/api/recording#list-all-recordings) diff --git a/README.md b/README.md index 02cc57b3..37ee2780 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a Add this line to your application's Gemfile: ```ruby -gem 'plivo', '>= 4.27.0' +gem 'plivo', '>= 4.27.1' ``` And then execute: diff --git a/lib/plivo/resources/calls.rb b/lib/plivo/resources/calls.rb index dd7c939a..e1037714 100644 --- a/lib/plivo/resources/calls.rb +++ b/lib/plivo/resources/calls.rb @@ -373,6 +373,7 @@ def list(options = nil) parent_call_uuid subaccount to_number + stir_verification ].reduce({}) do |result_hash, param| if options.key?(param) if param == :call_direction diff --git a/lib/plivo/version.rb b/lib/plivo/version.rb index c9c840ae..973b1064 100644 --- a/lib/plivo/version.rb +++ b/lib/plivo/version.rb @@ -1,3 +1,3 @@ module Plivo - VERSION = "4.27.0".freeze + VERSION = "4.27.1".freeze end