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

Add GeoPermissions exception on synchronous geo permissions error #252

Merged
merged 1 commit into from
Feb 19, 2025
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
## [4.61.3](https://github.com/plivo/plivo-ruby/tree/v4.61.3) (2025-02-18)
**Feature - Throw GeoPermissionsError Exception on synchronous geo permissions error**

## [4.61.2](https://github.com/plivo/plivo-ruby/tree/v4.61.2)(2024-10-23)
**Feature - FraudCheck param in Create, Get and List Session**
- Support for the `fraud_check` parameter in sms verify session request
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.61.2'
gem 'plivo', '>= 4.61.3'
```

And then execute:
Expand Down
12 changes: 10 additions & 2 deletions lib/plivo/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BaseClient
# Base stuff
attr_reader :headers, :auth_credentials
@@voice_retry_count = 0
GEO_PERMISSION_ENDPOINTS = ['/Message/', '/Session/', '/Call/'].freeze
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
configure_credentials(auth_id, auth_token)
configure_proxies(proxy_options)
Expand All @@ -26,7 +27,7 @@ def auth_id
end

def process_response(method, response)
handle_response_exceptions(response)
handle_response_exceptions(response, method)
if method == 'DELETE'
if !([200, 204].include? response[:status])
raise Exceptions::PlivoRESTError, "Resource at #{response[:url]} "\
Expand Down Expand Up @@ -341,7 +342,7 @@ def send_delete(resource_path, data, timeout, options = nil)
response
end

def handle_response_exceptions(response)
def handle_response_exceptions(response, method)
exception_mapping = {
400 => [
Exceptions::ValidationError,
Expand Down Expand Up @@ -373,6 +374,13 @@ def handle_response_exceptions(response)
]
}

if response[:status] == 403 && method == 'POST' && GEO_PERMISSION_ENDPOINTS.any? { |endpoint| response[:url].to_s.end_with?(endpoint) }
exception_mapping[403] = [
Exceptions::GeoPermissionsError,
'Geo-permission to the destination country is not enabled'
]
end

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

Expand Down
4 changes: 4 additions & 0 deletions lib/plivo/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ module Exceptions
##
# This will be raised when there is an authentication error
ResourceNotFoundError = Class.new(PlivoRESTError)

##
# This will be raised when the destination country is not enabled for sms/voice
GeoPermissionsError = Class.new(PlivoRESTError)
end
end
2 changes: 1 addition & 1 deletion lib/plivo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Plivo
VERSION = "4.61.2".freeze
VERSION = "4.61.3".freeze
end