Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maskingSession #239

Merged
merged 42 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5d53cad
maskingSession
ajay-plivo May 2, 2024
3e2cb1e
maskingChanges
ajay-plivo May 6, 2024
f5b5347
masking
ajay-plivo May 6, 2024
59c595a
masking
ajay-plivo May 6, 2024
8c4772d
masking
ajay-plivo May 6, 2024
c048276
endpoint
ajay-plivo May 6, 2024
3f83236
changed
ajay-plivo May 6, 2024
601f606
masking
ajay-plivo May 6, 2024
fa23c02
masking
ajay-plivo May 6, 2024
d9ca3df
masking
ajay-plivo May 6, 2024
ed46ba0
masking
ajay-plivo May 6, 2024
bfa9c14
versionFix
ajay-plivo May 9, 2024
caf0c0f
versionFix
ajay-plivo May 9, 2024
c3481ef
masterMerge
ajay-plivo May 29, 2024
1a18213
unitTestCasesAdded
ajay-plivo May 29, 2024
ecb4cf1
rename
ajay-plivo May 29, 2024
7def2ec
rename
ajay-plivo May 29, 2024
7d552f0
rename
ajay-plivo May 29, 2024
41443c3
rename
ajay-plivo May 29, 2024
68e6599
userFriendly
ajay-plivo May 29, 2024
995047f
parse_and_set
ajay-plivo May 30, 2024
1edf4b9
parse_and_set
ajay-plivo May 30, 2024
33fd688
parse
ajay-plivo May 30, 2024
1b95c0a
parse
ajay-plivo May 30, 2024
3ee132e
parse
ajay-plivo May 30, 2024
e829d5a
parse
ajay-plivo May 30, 2024
a182f90
parse
ajay-plivo May 30, 2024
c8e7f73
parse
ajay-plivo May 30, 2024
5d22904
parse
ajay-plivo May 30, 2024
dd61852
parse
ajay-plivo May 30, 2024
2daa634
parse
ajay-plivo May 30, 2024
52181ec
parse
ajay-plivo May 30, 2024
d175fec
finalCommit
ajay-plivo May 30, 2024
97e57fa
VT-7574
ajay-plivo May 30, 2024
2baecec
VT-7574
ajay-plivo May 30, 2024
3100830
nilValuesRemoved
ajay-plivo May 30, 2024
15693a9
test
ajay-plivo May 30, 2024
29e8cd4
test
ajay-plivo May 30, 2024
6d31d14
test
ajay-plivo May 30, 2024
540fb94
url
ajay-plivo May 30, 2024
477ee53
url
ajay-plivo May 30, 2024
5bfc00c
version
ajay-plivo May 31, 2024
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Change Log

## [4.59.0)](https://github.com/plivo/plivo-go/tree/v4.59.0) (2024-05-31)
**Feature - SubAccount and GeoMatch**
- Added sub_account and geo_match support

## [4.58.0](https://github.com/plivo/plivo-ruby/tree/v4.58.0) (2023-05-17)
**Feature - Adding support for location whatsapp messages**
- Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages
- Added new param `location` in templates to support location based templated messages
-

## [4.57.0](https://github.com/plivo/plivo-ruby/tree/v4.57.0) (2023-05-07)
**Feature - Adding support for interactive whatsapp messages**
- Added new param `interactive` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive `whatsapp` messages


## [4.56.0](https://github.com/plivo/plivo-ruby/tree/v4.56.0) (2023-04-18)
**Feature - Support for dynamic button components when sending a templated WhatsApp message**
- Added new param `payload` in templates to support dynamic payload in templates
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.58.0'
gem 'plivo', '>= 4.59.0'
```

And then execute:
Expand Down
2 changes: 1 addition & 1 deletion lib/plivo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module Base
PHLO_API_URL = 'https://phlorunner.plivo.com'.freeze
LOOKUP_API_URL = 'https://lookup.plivo.com'.freeze
end
end
end
49 changes: 45 additions & 4 deletions lib/plivo/base/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,39 @@ def parse_and_set(resource_json)
@id = resource_json[@_identifier_string]
end

def set_instance_variables(hash)
hash.each do |k, v|
instance_var_name = "@#{k}"

if v.is_a?(Hash)
instance_variable_set(instance_var_name, v)
self.class.send(:attr_reader, k.to_sym)
v.each do |nested_k, nested_v|
instance_var_name = "@#{nested_k}"
instance_variable_set(instance_var_name, nested_v)
self.class.send(:attr_reader, nested_k.to_sym)
end
else
instance_variable_set(instance_var_name, v)
self.class.send(:attr_reader, k.to_sym)
end
end
end

def parse_and_set_response(resource_json)
return unless resource_json.is_a?(Hash)

set_instance_variables(resource_json)

if @_identifier_string && resource_json.key?(@_identifier_string)
@id = resource_json[@_identifier_string]
end
end

def perform_update(params, use_multipart_conn = false)
unless @id
raise_invalid_request("Cannot update a #{@_name} resource "\
'without an identifier')
'without an identifier')
end

response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request)
Expand All @@ -64,14 +93,26 @@ def perform_update(params, use_multipart_conn = false)
self
end

def perform_masking_update(params, use_multipart_conn = false)
unless @id
raise_invalid_request("Cannot update a #{@_name} resource "\
'without an identifier')
end

response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn, is_voice_request: @_is_voice_request)
parse_and_set(params)
parse_and_set_response(response_json)
self
end

def perform_action(action = nil, method = 'GET', params = nil, parse = false)
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
parse ? parse_and_set(response) : self
method == 'POST' ? parse_and_set(params) : self
self
end

def perform_custome_action(action = nil, method = 'GET', params = nil, parse = false)
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
response = @_client.send_request(resource_path, method, params,nil,false,is_voice_request: @_is_voice_request)
Expand Down Expand Up @@ -101,7 +142,7 @@ def perform_custom_action_apiresponse(action = nil, method = 'GET', params = nil
def perform_delete(params=nil)
unless @id
raise_invalid_request("Cannot delete a #{@_name} resource "\
'without an identifier')
'without an identifier')
end

Response.new(@_client.send_request(@_resource_uri, 'DELETE', params, nil, false, is_voice_request: @_is_voice_request),
Expand Down Expand Up @@ -145,4 +186,4 @@ def configure_secondary_resource_uri
end
end
end
end
end
12 changes: 12 additions & 0 deletions lib/plivo/base/resource_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def perform_get(identifier, params = nil)
@_resource_type.new(@_client, resource_json: response_json)
end

def perform_get_with_response(identifier, params = nil)
valid_param?(:identifier, identifier, [String, Symbol], true)
response_json = @_client.send_request(@_resource_uri + identifier.to_s + '/', 'GET', params, nil, false, is_voice_request: @_is_voice_request)
resource_json = response_json["response"]
# Pass the parsed JSON to initialize the resource object
@_resource_type.new(@_client, resource_json: resource_json)
end

def perform_get_without_identifier(params)
valid_param?(:params, params, Hash, true)
response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
Expand Down Expand Up @@ -98,6 +106,10 @@ def perform_list(params = nil)
}
end

def perform_list_with_response(params = nil)
@_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: @_is_voice_request)
end

def perform_action(action = nil, method = 'GET', params = nil, parse = false)
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
response = @_client.send_request(resource_path, method, params, nil, false, is_voice_request: @_is_voice_request)
Expand Down
64 changes: 34 additions & 30 deletions lib/plivo/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,41 +343,41 @@ 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')
error_message = if response_json.is_a?(Hash) && response_json.key?('error')
response_json['error']
else
exception_now[1] + " at: #{response[:url]}"
Expand All @@ -386,6 +386,10 @@ def handle_response_exceptions(response)
error_message = error_message['error']
end

# Add api_id to the error message if present
if response_json.is_a?(Hash) && response_json.key?('api_id')
error_message += " (api_id: #{response_json['api_id']})"
end
raise exception_now[0], error_message.to_s
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/plivo/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require_relative 'resources/calls'
require_relative 'resources/token'
require_relative 'resources/endpoints'
require_relative 'resources/maskingsession'
require_relative 'resources/addresses'
require_relative 'resources/identities'
require_relative 'resources/phlos'
Expand Down
Loading
Loading