Skip to content

Commit

Permalink
Merge pull request #213 from Vonage/dev
Browse files Browse the repository at this point in the history
Release 7.5.0
  • Loading branch information
superchilled authored Mar 16, 2022
2 parents f6b79ce + f3badb5 commit 5e08c4c
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 29 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 7.5.0

* Adds a `ServiceError` exception class, which provides access to a `Response` object for improved error context in certain situations. See issue [#197](https://github.com/Vonage/vonage-ruby-sdk/issues/197) and PR [#208](https://github.com/Vonage/vonage-ruby-sdk/pull/208)
* Fixes issue with `Vonage::Voice::Ncco` class. See issue [#205](https://github.com/Vonage/vonage-ruby-sdk/issues/205) and PR [#206](https://github.com/Vonage/vonage-ruby-sdk/pull/206).

Merci beaucoup/ thanks a lot to [@cyb-](https://github.com/KaanOzkan) for work on these additions and fixes.

# 7.4.1

* Bug fix: updated `sorbet` signature to fix issue with `T.nilable(T.untyped)`. See issue [#200](https://github.com/Vonage/vonage-ruby-sdk/issues/200) and PR [#199](https://github.com/Vonage/vonage-ruby-sdk/pull/199). Thanks to [@KaanOzkan](https://github.com/KaanOzkan) and [@vinistock](https://github.com/vinistock)
Expand Down
8 changes: 4 additions & 4 deletions lib/vonage/number_insight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class NumberInsight < Namespace
def basic(params)
response = request('/ni/basic/json', params: params)

raise Error, response[:status_message] unless response.status.zero?
raise ServiceError.new(response: response), response[:status_message] unless response.status.zero?

response
end
Expand Down Expand Up @@ -57,7 +57,7 @@ def basic(params)
def standard(params)
response = request('/ni/standard/json', params: params)

raise Error, response[:status_message] unless response.status.zero?
raise ServiceError.new(response: response), response[:status_message] unless response.status.zero?

response
end
Expand Down Expand Up @@ -93,7 +93,7 @@ def standard(params)
def advanced(params)
response = request('/ni/advanced/json', params: params)

raise Error, response[:status_message] unless response.status.zero?
raise ServiceError.new(response: response), response[:status_message] unless response.status.zero?

response
end
Expand Down Expand Up @@ -132,7 +132,7 @@ def advanced(params)
def advanced_async(params)
response = request('/ni/advanced/async/json', params: params)

raise Error, response[:status_message] unless response.status.zero?
raise ServiceError.new(response: response), response[:status_message] unless response.status.zero?

response
end
Expand Down
16 changes: 16 additions & 0 deletions lib/vonage/service_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# typed: strong

module Vonage
class ServiceError < Error
extend T::Sig

sig { returns(Vonage::Response) }
attr_reader :response

sig { params(message: T.nilable(String), response: Vonage::Response).void }
def initialize(message = nil, response:)
super(message)
@response = response
end
end
end
2 changes: 1 addition & 1 deletion lib/vonage/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def send(params)
response = request('/sms/json', params: hyphenate(params), type: Post)

unless response.messages.first.status == '0'
raise Error, response.messages.first[:error_text]
raise ServiceError.new(response: response), response.messages.first[:error_text]
end

response
Expand Down
12 changes: 6 additions & 6 deletions lib/vonage/verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Verify < Namespace
def request(params, uri = '/verify/json')
response = http_request(uri, params: params, type: Post)

raise Error, response[:error_text] if error?(response)
raise ServiceError.new(response: response), response[:error_text] if error?(response)

response
end
Expand Down Expand Up @@ -97,7 +97,7 @@ def request(params, uri = '/verify/json')
def check(params)
response = http_request('/verify/check/json', params: params, type: Post)

raise Error, response[:error_text] if error?(response)
raise ServiceError.new(response: response), response[:error_text] if error?(response)

response
end
Expand All @@ -124,7 +124,7 @@ def check(params)
def search(params)
response = http_request('/verify/search/json', params: params)

raise Error, response[:error_text] if error?(response)
raise ServiceError.new(response: response), response[:error_text] if error?(response)

response
end
Expand All @@ -151,7 +151,7 @@ def search(params)
def control(params)
response = http_request('/verify/control/json', params: params, type: Post)

raise Error, response[:error_text] if error?(response)
raise ServiceError.new(response: response), response[:error_text] if error?(response)

response
end
Expand Down Expand Up @@ -234,11 +234,11 @@ def trigger_next_event(id)
#
# @see https://developer.nexmo.com/api/verify#verifyRequestWithPSD2
#
sig { params(params: T.untyped, uri: T.untyped).returns(T.any(Vonage::Error, Vonage::Response)) }
sig { params(params: T.untyped, uri: T.untyped).returns(T.any(Vonage::ServiceError, Vonage::Response)) }
def psd2(params, uri = '/verify/psd2/json')
response = http_request(uri, params: params, type: Post)

raise Error, response[:error_text] if error?(response)
raise ServiceError.new(response: response), response[:error_text] if error?(response)

response
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vonage/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# typed: strong

module Vonage
VERSION = '7.4.1'
VERSION = '7.5.0'
end
10 changes: 6 additions & 4 deletions lib/vonage/voice/ncco.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ class Voice::Ncco
talk: Vonage::Voice::Actions::Talk
}

ACTIONS.keys.each do |method|
self.class.send :define_method, method do |attributes|
ACTIONS[method].new(**attributes).action
class << self
ACTIONS.keys.each do |method|
define_method method do |attributes|
ACTIONS[method].new(**attributes).action
end
end
end

Expand All @@ -39,4 +41,4 @@ def self.create(*actions)
actions.flatten!
end
end
end
end
20 changes: 16 additions & 4 deletions test/vonage/number_insight_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ def test_basic_method

assert_kind_of Vonage::Response, number_insight.basic(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
number_insight.basic(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_standard_method
Expand All @@ -47,9 +50,12 @@ def test_standard_method

assert_kind_of Vonage::Response, number_insight.standard(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
number_insight.standard(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_advanced_method
Expand All @@ -59,9 +65,12 @@ def test_advanced_method

assert_kind_of Vonage::Response, number_insight.advanced(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
number_insight.advanced(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_advanced_async_method
Expand All @@ -71,8 +80,11 @@ def test_advanced_async_method

assert_kind_of Vonage::Response, number_insight.advanced_async(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
number_insight.advanced_async(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end
end
5 changes: 4 additions & 1 deletion test/vonage/sms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ def test_send_method

assert_kind_of Vonage::Response, sms.send(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
sms.send(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_mapping_underscored_keys_to_hyphenated_string_keys
Expand Down
35 changes: 28 additions & 7 deletions test/vonage/verify_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ def test_request_method

assert_kind_of Vonage::Response, verify.request(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.request(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_check_method
Expand All @@ -47,9 +50,12 @@ def test_check_method

assert_kind_of Vonage::Response, verify.check(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.check(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_search_method
Expand All @@ -61,9 +67,12 @@ def test_search_method

assert_kind_of Vonage::Response, verify.search(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.search(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_control_method
Expand All @@ -75,9 +84,12 @@ def test_control_method

assert_kind_of Vonage::Response, verify.control(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.control(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_cancel_method
Expand All @@ -89,9 +101,12 @@ def test_cancel_method

assert_kind_of Vonage::Response, verify.cancel(request_id)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.cancel(request_id)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_trigger_next_event_method
Expand All @@ -103,9 +118,12 @@ def test_trigger_next_event_method

assert_kind_of Vonage::Response, verify.trigger_next_event(request_id)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.trigger_next_event(request_id)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end

def test_psd2_method
Expand All @@ -117,8 +135,11 @@ def test_psd2_method

assert_kind_of Vonage::Response, verify.psd2(params)

assert_raises Vonage::Error do
error = assert_raises Vonage::ServiceError do
verify.psd2(params)
end

assert_kind_of Vonage::Error, error
assert_kind_of Vonage::Response, error.response
end
end
9 changes: 8 additions & 1 deletion test/vonage/voice/ncco_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ def test_ncco_with_invalid_action

assert_match "NCCO action must be one of the valid options. Please refer to https://developer.nexmo.com/voice/voice-api/ncco-reference#ncco-actions for a complete list.", exception.message
end
end

Vonage::Voice::Ncco::ACTIONS.keys.each do |method_name|
define_method "test_ncco_#{method_name}_defined_class_method" do
assert_respond_to ncco, method_name
refute_respond_to ncco.class, method_name
end
end
end

0 comments on commit 5e08c4c

Please sign in to comment.