plivo 4.58.0 → 4.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dcdea3382ce47522a95bff0850bcc67a582ebb54
4
- data.tar.gz: 77652b31e99304dc2166f94fa9e7b5384d0c5fe6
3
+ metadata.gz: 1d0565ad502d92b20824c8f478ffbb7b4ad518a5
4
+ data.tar.gz: 1deb5ee22ac0cfadd0ccf3bd9000d348fd3d1b32
5
5
  SHA512:
6
- metadata.gz: dda1d4228d6a950a364da677d7fc561a090e79cf83991c4a14659bf1f37f56229c029fd3f12a1f0e8e6dfc3d3a38237d54dca200095c0e7873025d924285e9ec
7
- data.tar.gz: e7e0832bb62f63262843787afc5a2107474c4e1133e3ef8b6cb088b8e0d32b15eb3de8afa2731b243af720fc26a908946539051140f8f134f9516c5027d130d1
6
+ metadata.gz: 9c6e100330904eaa6407b9b6064ac8d98e2037ecc9547c8725b66e499b80cf18e3f15b62bf76a0349c7fbe70ef21d2303962a4a65ee4d258cac6bd0f4e315d8e
7
+ data.tar.gz: f2c4ec8bd749f91da845c7041380fc54f55e7e3ffb88380a74764502152833b4b462f87f11d034f436c50a44829d3173a8404d21cdcff016443bcdc26130ce77
data/CHANGELOG.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.59.0)](https://github.com/plivo/plivo-go/tree/v4.59.0) (2024-05-31)
4
+ **Feature - SubAccount and GeoMatch**
5
+ - Added sub_account and geo_match support
6
+
3
7
  ## [4.58.0](https://github.com/plivo/plivo-ruby/tree/v4.58.0) (2023-05-17)
4
8
  **Feature - Adding support for location whatsapp messages**
5
9
  - Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages
6
10
  - Added new param `location` in templates to support location based templated messages
11
+ -
7
12
 
8
13
  ## [4.57.0](https://github.com/plivo/plivo-ruby/tree/v4.57.0) (2023-05-07)
9
14
  **Feature - Adding support for interactive whatsapp messages**
10
15
  - Added new param `interactive` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive `whatsapp` messages
11
16
 
17
+
12
18
  ## [4.56.0](https://github.com/plivo/plivo-ruby/tree/v4.56.0) (2023-04-18)
13
19
  **Feature - Support for dynamic button components when sending a templated WhatsApp message**
14
20
  - Added new param `payload` in templates to support dynamic payload in templates
data/README.md CHANGED
@@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'plivo', '>= 4.58.0'
12
+ gem 'plivo', '>= 4.59.0'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -51,10 +51,39 @@ module Plivo
51
51
  @id = resource_json[@_identifier_string]
52
52
  end
53
53
 
54
+ def set_instance_variables(hash)
55
+ hash.each do |k, v|
56
+ instance_var_name = "@#{k}"
57
+
58
+ if v.is_a?(Hash)
59
+ instance_variable_set(instance_var_name, v)
60
+ self.class.send(:attr_reader, k.to_sym)
61
+ v.each do |nested_k, nested_v|
62
+ instance_var_name = "@#{nested_k}"
63
+ instance_variable_set(instance_var_name, nested_v)
64
+ self.class.send(:attr_reader, nested_k.to_sym)
65
+ end
66
+ else
67
+ instance_variable_set(instance_var_name, v)
68
+ self.class.send(:attr_reader, k.to_sym)
69
+ end
70
+ end
71
+ end
72
+
73
+ def parse_and_set_response(resource_json)
74
+ return unless resource_json.is_a?(Hash)
75
+
76
+ set_instance_variables(resource_json)
77
+
78
+ if @_identifier_string && resource_json.key?(@_identifier_string)
79
+ @id = resource_json[@_identifier_string]
80
+ end
81
+ end
82
+
54
83
  def perform_update(params, use_multipart_conn = false)
55
84
  unless @id
56
85
  raise_invalid_request("Cannot update a #{@_name} resource "\
57
- 'without an identifier')
86
+ 'without an identifier')
58
87
  end
59
88
 
60
89
  response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request)
@@ -64,6 +93,18 @@ module Plivo
64
93
  self
65
94
  end
66
95
 
96
+ def perform_masking_update(params, use_multipart_conn = false)
97
+ unless @id
98
+ raise_invalid_request("Cannot update a #{@_name} resource "\
99
+ 'without an identifier')
100
+ end
101
+
102
+ response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request)
103
+ parse_and_set(params)
104
+ parse_and_set_response(response_json)
105
+ self
106
+ end
107
+
67
108
  def perform_action(action = nil, method = 'GET', params = nil, parse = false)
68
109
  resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
69
110
  response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
@@ -71,7 +112,7 @@ module Plivo
71
112
  method == 'POST' ? parse_and_set(params) : self
72
113
  self
73
114
  end
74
-
115
+
75
116
  def perform_custome_action(action = nil, method = 'GET', params = nil, parse = false)
76
117
  resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
77
118
  response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
@@ -101,7 +142,7 @@ module Plivo
101
142
  def perform_delete(params=nil)
102
143
  unless @id
103
144
  raise_invalid_request("Cannot delete a #{@_name} resource "\
104
- 'without an identifier')
145
+ 'without an identifier')
105
146
  end
106
147
 
107
148
  Response.new(@_client.send_request(@_resource_uri, 'DELETE', params, nil, false, is_voice_request: @_is_voice_request),
@@ -145,4 +186,4 @@ module Plivo
145
186
  end
146
187
  end
147
188
  end
148
- end
189
+ end
@@ -46,6 +46,14 @@ module Plivo
46
46
  @_resource_type.new(@_client, resource_json: response_json)
47
47
  end
48
48
 
49
+ def perform_get_with_response(identifier, params = nil)
50
+ valid_param?(:identifier, identifier, [String, Symbol], true)
51
+ response_json = @_client.send_request(@_resource_uri + identifier.to_s + '/', 'GET', params, nil, false, is_voice_request: @_is_voice_request)
52
+ resource_json = response_json["response"]
53
+ # Pass the parsed JSON to initialize the resource object
54
+ @_resource_type.new(@_client, resource_json: resource_json)
55
+ end
56
+
49
57
  def perform_get_without_identifier(params)
50
58
  valid_param?(:params, params, Hash, true)
51
59
  response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
@@ -98,6 +106,10 @@ module Plivo
98
106
  }
99
107
  end
100
108
 
109
+ def perform_list_with_response(params = nil)
110
+ @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
111
+ end
112
+
101
113
  def perform_action(action = nil, method = 'GET', params = nil, parse = false)
102
114
  resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
103
115
  response = @_client.send_request(resource_path, method, params, nil, false, is_voice_request: @_is_voice_request)
data/lib/plivo/base.rb CHANGED
@@ -14,4 +14,4 @@ module Plivo
14
14
  PHLO_API_URL = 'https://phlorunner.plivo.com'.freeze
15
15
  LOOKUP_API_URL = 'https://lookup.plivo.com'.freeze
16
16
  end
17
- end
17
+ end
@@ -343,41 +343,41 @@ module Plivo
343
343
 
344
344
  def handle_response_exceptions(response)
345
345
  exception_mapping = {
346
- 400 => [
347
- Exceptions::ValidationError,
348
- 'A parameter is missing or is invalid while accessing resource'
349
- ],
350
- 401 => [
351
- Exceptions::AuthenticationError,
352
- 'Failed to authenticate while accessing resource'
353
- ],
354
- 404 => [
355
- Exceptions::ResourceNotFoundError,
356
- 'Resource not found'
357
- ],
358
- 405 => [
359
- Exceptions::InvalidRequestError,
360
- 'HTTP method used is not allowed to access resource'
361
- ],
362
- 409 => [
363
- Exceptions::InvalidRequestError,
364
- 'Conflict'
365
- ],
366
- 422 => [
367
- Exceptions::InvalidRequestError,
368
- 'Unprocessable Entity'
369
- ],
370
- 500 => [
371
- Exceptions::PlivoServerError,
372
- 'A server error occurred while accessing resource'
373
- ]
346
+ 400 => [
347
+ Exceptions::ValidationError,
348
+ 'A parameter is missing or is invalid while accessing resource'
349
+ ],
350
+ 401 => [
351
+ Exceptions::AuthenticationError,
352
+ 'Failed to authenticate while accessing resource'
353
+ ],
354
+ 404 => [
355
+ Exceptions::ResourceNotFoundError,
356
+ 'Resource not found'
357
+ ],
358
+ 405 => [
359
+ Exceptions::InvalidRequestError,
360
+ 'HTTP method used is not allowed to access resource'
361
+ ],
362
+ 409 => [
363
+ Exceptions::InvalidRequestError,
364
+ 'Conflict'
365
+ ],
366
+ 422 => [
367
+ Exceptions::InvalidRequestError,
368
+ 'Unprocessable Entity'
369
+ ],
370
+ 500 => [
371
+ Exceptions::PlivoServerError,
372
+ 'A server error occurred while accessing resource'
373
+ ]
374
374
  }
375
375
 
376
376
  response_json = response[:body]
377
- return unless exception_mapping.key? response[:status]
377
+ return unless exception_mapping.key?(response[:status])
378
378
 
379
379
  exception_now = exception_mapping[response[:status]]
380
- error_message = if (response_json.is_a? Hash) && (response_json.key? 'error')
380
+ error_message = if response_json.is_a?(Hash) && response_json.key?('error')
381
381
  response_json['error']
382
382
  else
383
383
  exception_now[1] + " at: #{response[:url]}"
@@ -386,6 +386,10 @@ module Plivo
386
386
  error_message = error_message['error']
387
387
  end
388
388
 
389
+ # Add api_id to the error message if present
390
+ if response_json.is_a?(Hash) && response_json.key?('api_id')
391
+ error_message += " (api_id: #{response_json['api_id']})"
392
+ end
389
393
  raise exception_now[0], error_message.to_s
390
394
  end
391
395
  end
@@ -0,0 +1,214 @@
1
+ module Plivo
2
+ module Resources
3
+ include Plivo::Utils
4
+ class MaskingSession < Base::Resource
5
+ def initialize(client, options = nil)
6
+ @_name = 'Masking/Session'
7
+ @_identifier_string = 'session_uuid'
8
+ super
9
+ @_is_voice_request = true
10
+ end
11
+
12
+ def update(options = nil)
13
+ return if options.nil?
14
+ valid_param?(:options, options, Hash, true)
15
+
16
+ params = {}
17
+ params_expected = %i[session_expiry call_time_limit record record_file_format recording_callback_url
18
+ callback_url callback_method ring_timeout first_party_play_url second_party_play_url recording_callback_method
19
+ subaccount geomatch]
20
+ params_expected.each do |param|
21
+ if options.key?(param) && valid_param?(param, options[param], [String, Symbol, TrueClass, FalseClass], true)
22
+ params[param] = options[param]
23
+ end
24
+ end
25
+
26
+ updated_session = perform_masking_update(params)
27
+ session_data = updated_session.instance_variables.map do |var|
28
+ [var[1..-1].to_sym, updated_session.instance_variable_get(var)]
29
+ end.to_h
30
+
31
+ relevant_keys = %i[api_id message session]
32
+ filtered_session_data = session_data.select { |key, _| relevant_keys.include?(key) }
33
+
34
+ if filtered_session_data[:session]
35
+ session_instance = filtered_session_data[:session]
36
+ session_data = session_instance.map do |key, value|
37
+ [key.to_sym, value]
38
+ end.to_h
39
+
40
+ # Extract relevant keys from session
41
+ session_relevant_keys = %i[first_party second_party virtual_number status initiate_call_to_first_party session_uuid callback_url callback_method created_time
42
+ modified_time expiry_time duration amount call_time_limit ring_timeout first_party_play_url second_party_play_url record record_file_format recording_callback_url
43
+ recording_callback_method interaction total_call_amount total_call_count total_call_billed_duration total_session_amount last_interaction_time unknown_caller_play
44
+ is_pin_authentication_required generate_pin generate_pin_length first_party_pin second_party_pin pin_prompt_play pin_retry pin_retry_wait incorrect_pin_play]
45
+
46
+ filtered_session_data[:session] = session_data.select { |key, _| session_relevant_keys.include?(key) }
47
+ end
48
+
49
+ filtered_session_data
50
+ end
51
+
52
+ def delete
53
+ perform_delete
54
+ end
55
+
56
+ def to_s
57
+ {
58
+ first_party: @first_party,
59
+ second_party: @second_party,
60
+ virtual_number: @virtual_number,
61
+ status: @status,
62
+ initiate_call_to_first_party: @initiate_call_to_first_party,
63
+ session_uuid: @session_uuid,
64
+ callback_url: @callback_url,
65
+ callback_method: @callback_method,
66
+ created_time: @created_time,
67
+ modified_time: @modified_time,
68
+ expiry_time: @expiry_time,
69
+ duration: @duration,
70
+ amount: @amount,
71
+ call_time_limit: @call_time_limit,
72
+ ring_timeout: @ring_timeout,
73
+ first_party_play_url: @first_party_play_url,
74
+ second_party_play_url: @second_party_play_url,
75
+ record: @record,
76
+ record_file_format: @record_file_format,
77
+ recording_callback_url: @recording_callback_url,
78
+ recording_callback_method: @recording_callback_method,
79
+ interaction: @interaction,
80
+ total_call_amount: @total_call_amount,
81
+ total_call_count: @total_call_count,
82
+ total_call_billed_duration: @total_call_billed_duration,
83
+ total_session_amount: @total_session_amount,
84
+ last_interaction_time: @last_interaction_time,
85
+ is_pin_authentication_required: @is_pin_authentication_required,
86
+ generate_pin: @generate_pin,
87
+ generate_pin_length: @generate_pin_length,
88
+ second_party_pin: @second_party_pin,
89
+ pin_prompt_play: @pin_prompt_play,
90
+ pin_retry: @pin_retry,
91
+ pin_retry_wait: @pin_retry_wait,
92
+ incorrect_pin_play: @incorrect_pin_play,
93
+ unknown_caller_play: @unknown_caller_play
94
+ }.to_s
95
+ end
96
+ end
97
+
98
+ class MaskingSessionInterface < Base::ResourceInterface
99
+ def initialize(client, resource_list_json = nil)
100
+ @_name = 'Masking/Session'
101
+ @_resource_type = MaskingSession
102
+ @_identifier_string = 'session_uuid'
103
+ super
104
+ @_is_voice_request = true
105
+ end
106
+
107
+ def get(session_uuid)
108
+ valid_param?(:session_uuid, session_uuid, [String, Symbol], true)
109
+ perform_get_with_response(session_uuid)
110
+ end
111
+
112
+ def create(first_party:, second_party:, session_expiry: nil, call_time_limit: nil, record: nil, record_file_format: nil,
113
+ recording_callback_url: nil, initiate_call_to_first_party: nil, callback_url: nil, callback_method: nil, ring_timeout: nil,
114
+ first_party_play_url: nil, second_party_play_url: nil, recording_callback_method: nil, is_pin_authentication_required: nil,
115
+ generate_pin: nil, generate_pin_length: nil, first_party_pin: nil, second_party_pin: nil, pin_prompt_play: nil, pin_retry: nil,
116
+ pin_retry_wait: nil, incorrect_pin_play: nil, unknown_caller_play: nil, subaccount: nil, geomatch: nil)
117
+
118
+ valid_param?(:first_party, first_party, [String, Symbol], true)
119
+ valid_param?(:second_party, second_party, [String, Symbol], true)
120
+
121
+ params = {}
122
+ params[:first_party] = first_party
123
+ params[:second_party] = second_party
124
+ params[:session_expiry] = session_expiry unless session_expiry.nil?
125
+ params[:call_time_limit] = call_time_limit unless call_time_limit.nil?
126
+ params[:record] = record unless record.nil?
127
+ params[:record_file_format] = record_file_format unless record_file_format.nil?
128
+ params[:recording_callback_url] = recording_callback_url unless recording_callback_url.nil?
129
+ params[:initiate_call_to_first_party] = initiate_call_to_first_party unless initiate_call_to_first_party.nil?
130
+ params[:callback_url] = callback_url unless callback_url.nil?
131
+ params[:callback_method] = callback_method unless callback_method.nil?
132
+ params[:ring_timeout] = ring_timeout unless ring_timeout.nil?
133
+ params[:first_party_play_url] = first_party_play_url unless first_party_play_url.nil?
134
+ params[:second_party_play_url] = second_party_play_url unless second_party_play_url.nil?
135
+ params[:recording_callback_method] = recording_callback_method unless recording_callback_method.nil?
136
+ params[:is_pin_authentication_required] = is_pin_authentication_required unless is_pin_authentication_required.nil?
137
+ params[:generate_pin] = generate_pin unless generate_pin.nil?
138
+ params[:generate_pin_length] = generate_pin_length unless generate_pin_length.nil?
139
+ params[:first_party_pin] = first_party_pin unless first_party_pin.nil?
140
+ params[:second_party_pin] = second_party_pin unless second_party_pin.nil?
141
+ params[:pin_prompt_play] = pin_prompt_play unless pin_prompt_play.nil?
142
+ params[:pin_retry] = pin_retry unless pin_retry.nil?
143
+ params[:pin_retry_wait] = pin_retry_wait unless pin_retry_wait.nil?
144
+ params[:incorrect_pin_play] = incorrect_pin_play unless incorrect_pin_play.nil?
145
+ params[:unknown_caller_play] = unknown_caller_play unless unknown_caller_play.nil?
146
+ params[:subaccount] = subaccount unless subaccount.nil?
147
+ params[:geomatch] = geomatch unless geomatch.nil?
148
+
149
+ perform_create(params)
150
+ end
151
+
152
+ def list(options = nil)
153
+ return perform_list_with_response if options.nil?
154
+ valid_param?(:options, options, Hash, true)
155
+
156
+ raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0
157
+
158
+ if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
159
+ raise_invalid_request('The maximum number of results that can be '\
160
+ "fetched is 20. limit can't be more than 20 or less than 1")
161
+ end
162
+
163
+ params = %i[
164
+ first_party
165
+ second_party
166
+ virtual_number
167
+ status
168
+ created_time
169
+ created_time__lt
170
+ created_time__gt
171
+ created_time__lte
172
+ created_time__gte
173
+ expiry_time
174
+ expiry_time__lt
175
+ expiry_time__gt
176
+ expiry_time__lte
177
+ expiry_time__gte
178
+ duration
179
+ duration__lt
180
+ duration__gt
181
+ duration__lte
182
+ duration__gte
183
+ limit
184
+ offset
185
+ subaccount
186
+ ].reduce({}) do |result_hash, param|
187
+ if options.key?(param)
188
+ if valid_param?(param, options[param], [String, Symbol], true)
189
+ result_hash[param] = options[param]
190
+ end
191
+ end
192
+ result_hash
193
+ end
194
+
195
+ perform_list_with_response(params)
196
+ end
197
+
198
+ def each
199
+ maskingsession_list = list
200
+ maskingsession_list[:objects].each { |maskingsession| yield maskingsession }
201
+ end
202
+
203
+ def update(session_uuid, options = nil)
204
+ valid_param?(:session_uuid, session_uuid, [String, Symbol], true)
205
+ MaskingSession.new(@_client, resource_id: session_uuid).update(options)
206
+ end
207
+
208
+ def delete(session_uuid)
209
+ valid_param?(:session_uuid, session_uuid, [String, Symbol], true)
210
+ MaskingSession.new(@_client, resource_id: session_uuid).delete
211
+ end
212
+ end
213
+ end
214
+ end
@@ -9,6 +9,7 @@ require_relative 'resources/conferences'
9
9
  require_relative 'resources/calls'
10
10
  require_relative 'resources/token'
11
11
  require_relative 'resources/endpoints'
12
+ require_relative 'resources/maskingsession'
12
13
  require_relative 'resources/addresses'
13
14
  require_relative 'resources/identities'
14
15
  require_relative 'resources/phlos'
@@ -21,6 +21,7 @@ module Plivo
21
21
  attr_reader :verify_session
22
22
  attr_reader :tollfree_verifications
23
23
  attr_reader :verify_caller_id
24
+ attr_reader :maskingsession
24
25
 
25
26
  def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5)
26
27
  configure_base_uri
@@ -56,6 +57,7 @@ module Plivo
56
57
  @calls = Resources::CallInterface.new(self)
57
58
  @token = Resources::TokenInterface.new(self)
58
59
  @endpoints = Resources::EndpointInterface.new(self)
60
+ @maskingsession = Resources::MaskingSessionInterface.new(self)
59
61
  @applications = Resources::ApplicationInterface.new(self)
60
62
  @addresses = Resources::AddressInterface.new(self)
61
63
  @identities = Resources::IdentityInterface.new(self)
data/lib/plivo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = "4.58.0".freeze
2
+ VERSION = "4.59.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.58.0
4
+ version: 4.59.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Plivo SDKs Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -182,6 +182,7 @@ files:
182
182
  - lib/plivo/resources/endpoints.rb
183
183
  - lib/plivo/resources/identities.rb
184
184
  - lib/plivo/resources/lookup.rb
185
+ - lib/plivo/resources/maskingsession.rb
185
186
  - lib/plivo/resources/media.rb
186
187
  - lib/plivo/resources/messages.rb
187
188
  - lib/plivo/resources/multipartycalls.rb