vonage 7.15.1 → 7.16.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 +4 -4
- data/README.md +41 -0
- data/lib/vonage/api_error.rb +33 -0
- data/lib/vonage/client_error.rb +1 -1
- data/lib/vonage/errors.rb +21 -18
- data/lib/vonage/server_error.rb +1 -1
- data/lib/vonage/version.rb +1 -1
- data/lib/vonage.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eee7072db61e23948a8659c05fa1c1a071a231de32da5506c2a0a1f8e0dec525
|
4
|
+
data.tar.gz: 7082dab4129bb5f251f14cb5cbfc19cdd21b82da8349535194258bb95c656a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9274d4f25c3ac03361e7024aa24685e2be658db11c57601bbc349bc3c65784ef097d836e309318e87de8f4256dab45bbe814638d708230b7463df58589968fa8
|
7
|
+
data.tar.gz: e410a075c96c179c18ca87e047c9c16c3e364c97c36c535eb946dabe4497070a3d465332756db899016ee20af2b45c09dfa846156e9392dde29dfecda4955ae0
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
|
|
12
12
|
* [Installation](#installation)
|
13
13
|
* [Usage](#usage)
|
14
14
|
* [Logging](#logging)
|
15
|
+
* [Exceptions](#exceptions)
|
15
16
|
* [Overriding the default hosts](#overriding-the-default-hosts)
|
16
17
|
* [JWT authentication](#jwt-authentication)
|
17
18
|
* [Webhook signatures](#webhook-signatures)
|
@@ -82,6 +83,46 @@ By default the library sets the logger to `Rails.logger` if it is defined.
|
|
82
83
|
|
83
84
|
To disable logging set the logger to `nil`.
|
84
85
|
|
86
|
+
## Exceptions
|
87
|
+
|
88
|
+
Where exceptions result from an error response from the Vonage API (HTTP responses that aren't ion the range `2xx` or `3xx`), the `Net::HTTPResponse` object will be available as a property of the `Exception` object via a `http_response` getter method (where there is no `Net::HTTPResponse` object associated with the exception, the value of `http_response` will be `nil`).
|
89
|
+
|
90
|
+
You can rescue the the exception to access the `http_response`, as well as use other getters provided for specific parts of the response. For example:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
begin
|
94
|
+
verification_request = client.verify2.start_verification(
|
95
|
+
brand: 'Acme',
|
96
|
+
workflow: [{channel: 'sms', to: '44700000000'}]
|
97
|
+
)
|
98
|
+
rescue Vonage::APIError => error
|
99
|
+
if error.http_response
|
100
|
+
error.http_response # => #<Net::HTTPUnauthorized 401 Unauthorized readbody=true>
|
101
|
+
error.http_response_code # => "401"
|
102
|
+
error.http_response_headers # => {"date"=>["Sun, 24 Sep 2023 11:08:47 GMT"], ...rest of headers}
|
103
|
+
error.http_response_body # => {"title"=>"Unauthorized", ...rest of body}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
For certain legacy API products, such as the [SMS API](https://developer.vonage.com/en/messaging/sms/overview), [Verify v1 API](https://developer.vonage.com/en/verify/verify-v1/overview) and [Number Insight v1 API](https://developer.vonage.com/en/number-insight/overview), a `200` response is received even in situations where there is an API-related error. For exceptions raised in these situation, rather than a `Net::HTTPResponse` object, a `Vonage::Response` object will be made available as a property of the exception via a `response` getter method. The properties on this object will depend on the response data provided by the API endpoint. For example:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
begin
|
112
|
+
sms = client.sms.send(
|
113
|
+
from: 'Vonage',
|
114
|
+
to: '44700000000',
|
115
|
+
text: 'Hello World!'
|
116
|
+
)
|
117
|
+
rescue Vonage::Error => error
|
118
|
+
if error.is_a? Vonage::ServiceError
|
119
|
+
error.response # => #<Vonage::Response:0x0000555b2e49d4f8>
|
120
|
+
error.response.messages.first.status # => "4"
|
121
|
+
error.response.messages.first.error_text # => "Bad Credentials"
|
122
|
+
error.response.http_response # => #<Net::HTTPOK 200 OK readbody=true>
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
85
126
|
|
86
127
|
## Overriding the default hosts
|
87
128
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# typed: strong
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Vonage
|
5
|
+
class APIError < Error
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig { returns(Net::HTTPResponse) }
|
9
|
+
attr_reader :http_response
|
10
|
+
|
11
|
+
sig { params(message: T.nilable(String), http_response: T.nilable(Net::HTTPResponse)).void }
|
12
|
+
def initialize(message = nil, http_response: nil)
|
13
|
+
super(message)
|
14
|
+
@http_response = http_response
|
15
|
+
end
|
16
|
+
|
17
|
+
def http_response_code
|
18
|
+
return nil unless http_response
|
19
|
+
http_response.code
|
20
|
+
end
|
21
|
+
|
22
|
+
def http_response_headers
|
23
|
+
return nil unless http_response
|
24
|
+
http_response.to_hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def http_response_body
|
28
|
+
return nil unless http_response
|
29
|
+
return {} unless http_response.content_type && http_response.content_type.include?("json")
|
30
|
+
::JSON.parse(http_response.body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/vonage/client_error.rb
CHANGED
data/lib/vonage/errors.rb
CHANGED
@@ -27,27 +27,30 @@ module Vonage
|
|
27
27
|
when Net::HTTPServerError
|
28
28
|
ServerError
|
29
29
|
else
|
30
|
-
|
30
|
+
APIError
|
31
31
|
end
|
32
32
|
|
33
|
-
message =
|
34
|
-
if response.content_type == "application/json"
|
35
|
-
hash = ::JSON.parse(response.body)
|
33
|
+
message = response.content_type.to_s.include?("json") ? set_message(response) : ""
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
hash["description"]
|
43
|
-
elsif hash.key?("message")
|
44
|
-
hash["message"]
|
45
|
-
elsif problem_details?(hash)
|
46
|
-
problem_details_message(hash)
|
47
|
-
end
|
48
|
-
end
|
35
|
+
exception_class.new(message, http_response: response)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.set_message(response)
|
39
|
+
hash = ::JSON.parse(response.body)
|
49
40
|
|
50
|
-
|
41
|
+
if hash.key?("error_title")
|
42
|
+
hash["error_title"]
|
43
|
+
elsif hash.key?("error-code-label")
|
44
|
+
hash["error-code-label"]
|
45
|
+
elsif hash.key?("description")
|
46
|
+
hash["description"]
|
47
|
+
elsif hash.key?("message")
|
48
|
+
hash["message"]
|
49
|
+
elsif problem_details?(hash)
|
50
|
+
problem_details_message(hash)
|
51
|
+
else
|
52
|
+
""
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
sig { params(hash: T::Hash[String, T.untyped]).returns(T::Boolean) }
|
@@ -57,7 +60,7 @@ module Vonage
|
|
57
60
|
|
58
61
|
sig { params(hash: T::Hash[String, T.untyped]).returns(String) }
|
59
62
|
def self.problem_details_message(hash)
|
60
|
-
"#{hash["title"]}. #{hash["detail"]} See #{hash["type"]} for more info, or email support@
|
63
|
+
"#{hash["title"]}. #{hash["detail"]} See #{hash["type"]} for more info, or email support@vonage.com if you have any questions."
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
data/lib/vonage/server_error.rb
CHANGED
data/lib/vonage/version.rb
CHANGED
data/lib/vonage.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vonage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vonage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vonage-jwt
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/vonage/abstract_authentication.rb
|
114
114
|
- lib/vonage/account.rb
|
115
115
|
- lib/vonage/alerts.rb
|
116
|
+
- lib/vonage/api_error.rb
|
116
117
|
- lib/vonage/applications.rb
|
117
118
|
- lib/vonage/applications/list_response.rb
|
118
119
|
- lib/vonage/authentication_error.rb
|