vonage 7.17.0 → 7.19.0.exp.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e40765a9a9b5858befa5702b61359c79941b70075618dbd071f32e8798dbceb0
4
- data.tar.gz: 4c0b3a037b50b85507e3344e1455ede6dc59c75953466a1a060294f8e89f00e6
3
+ metadata.gz: 72c07b64fdfe3cdc62e2ee5a8e1d9669d3636f4cc4a875e239598633978b39c3
4
+ data.tar.gz: 98b503219aef2a6ad1257eef48afa310eb8ab9d656d5663645b866317cb8da52
5
5
  SHA512:
6
- metadata.gz: f2b8d8a22e65833b766f17433786188b9d1d504109128fcc1cffd0bcfd3b1648897054e14089ebf85713165c453cd12b7e74ea9c7cb59785e7e53de9fc9c8c61
7
- data.tar.gz: '08a5577b9121dee24869d6c32e1f9eb25dca5d09e071d69e5b115b6cab756ddccd296f16e7e446b3be6dc6e26055346b5eee2935ea64a784b7b5a77d45a7b1f6'
6
+ metadata.gz: d42da6c1edafffe6e0b63a5a09ca685be3e894e827a2ab08f25f893faca8ce7b41dda650b43484f09019a2db88a0b4e8734daa5bd962ebd55f9c764c2d0eac60
7
+ data.tar.gz: d8f6ae648a6b76eced66204bf7a96a2c06b8d3be436a572eecadec8233e0c36f3e302cbf0bdcb4b52199e188380436c178439919fcb46ffa5795cbd00af674eb
data/README.md CHANGED
@@ -17,13 +17,15 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
17
17
  * [JWT authentication](#jwt-authentication)
18
18
  * [Webhook signatures](#webhook-signatures)
19
19
  * [Pagination](#pagination)
20
- * [NCCO Builder](#ncco-builder)
21
20
  * [Messages API](#messages-api)
22
21
  * [Verify API v2](#verify-api-v2)
22
+ * [Voice API](#voice-api)
23
+ * [NCCO Builder](#ncco-builder)
23
24
  * [Documentation](#documentation)
24
- * [Frequently Asked Questions](#frequently-asked-questions)
25
- * [Supported APIs](#supported-apis)
25
+ * [Supported APIs](#supported-apis)
26
+ * [Other SDKs and Tools](#other-sdks-and-tools)
26
27
  * [License](#license)
28
+ * [Contribute](#contribute)
27
29
 
28
30
 
29
31
  ## Requirements
@@ -66,8 +68,47 @@ For production you can specify the `VONAGE_API_KEY` and `VONAGE_API_SECRET`
66
68
  environment variables instead of specifying the key and secret explicitly,
67
69
  keeping your credentials out of source control.
68
70
 
71
+ For APIs which use a JWT for authentication you'll need to pass `application_id` and `private_key` arguments to the
72
+ `Client` constructor as well as or instead of `api_key` and `api_secret`. See [JWT Authentication](#jwt-authentication).
69
73
 
70
- ## Logging
74
+ It is also possible to over-ride the default hosts at `Client` instantiation. See [Overriding the default hosts](overriding-the-default-hosts).
75
+
76
+ ### JWT authentication
77
+
78
+ To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
79
+ also need to specify the `application_id` and `private_key` options. For example:
80
+
81
+ ```ruby
82
+ client = Vonage::Client.new(application_id: application_id, private_key: private_key)
83
+ ```
84
+
85
+ Both arguments should have string values corresponding to the `id` and `private_key`
86
+ values returned in a ["create an application"](https://developer.nexmo.com/api/application.v2#createApplication)
87
+ response. These credentials can be stored in a datastore, in environment variables,
88
+ on disk outside of source control, or in some kind of key management infrastructure.
89
+
90
+ By default the library generates a short lived JWT per request. To generate a long lived
91
+ JWT for multiple requests or to specify JWT claims directly use `Vonage::JWT.generate` and
92
+ the token option. For example:
93
+
94
+ ```ruby
95
+ claims = {
96
+ application_id: application_id,
97
+ private_key: 'path/to/private.key',
98
+ nbf: 1483315200,
99
+ ttl: 800
100
+ }
101
+
102
+ token = Vonage::JWT.generate(claims)
103
+
104
+ client = Vonage::Client.new(token: token)
105
+ ```
106
+
107
+ Documentation for the Vonage Ruby JWT generator gem can be found at
108
+ [https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby](https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby).
109
+ The documentation outlines all the possible parameters you can use to customize and build a token with.
110
+
111
+ ### Logging
71
112
 
72
113
  Use the logger option to specify a logger. For example:
73
114
 
@@ -83,7 +124,7 @@ By default the library sets the logger to `Rails.logger` if it is defined.
83
124
 
84
125
  To disable logging set the logger to `nil`.
85
126
 
86
- ## Exceptions
127
+ ### Exceptions
87
128
 
88
129
  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
130
 
@@ -124,7 +165,7 @@ rescue Vonage::Error => error
124
165
  end
125
166
  ```
126
167
 
127
- ## Overriding the default hosts
168
+ ### Overriding the default hosts
128
169
 
129
170
  To override the default hosts that the SDK uses for HTTP requests, you need to
130
171
  specify the `api_host`, `rest_host` or both in the client configuration. For example:
@@ -139,104 +180,138 @@ client = Vonage::Client.new(
139
180
  By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respectively.
140
181
 
141
182
 
142
- ## JWT authentication
143
183
 
144
- To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
145
- also need to specify the `application_id` and `private_key` options. For example:
146
184
 
147
- ```ruby
148
- client = Vonage::Client.new(application_id: application_id, private_key: private_key)
149
- ```
185
+ ### Webhook signatures
150
186
 
151
- Both arguments should have string values corresponding to the `id` and `private_key`
152
- values returned in a ["create an application"](https://developer.nexmo.com/api/application.v2#createApplication)
153
- response. These credentials can be stored in a datastore, in environment variables,
154
- on disk outside of source control, or in some kind of key management infrastructure.
187
+ Certain Vonage APIs provide signed [webhooks](https://developer.vonage.com/en/getting-started/concepts/webhooks) as a means of verifying the origin of the webhooks. The exact signing mechanism varies depending on the API.
155
188
 
156
- By default the library generates a short lived JWT per request. To generate a long lived
157
- JWT for multiple requests or to specify JWT claims directly use `Vonage::JWT.generate` and
158
- the token option. For example:
189
+ #### Signature in Request Body
190
+
191
+ The [SMS API](https://developer.vonage.com/en/messaging/sms/overview) signs the webhook request using a hash digest. This is assigned to a `sig` parameter in the request body.
192
+
193
+ You can verify the webhook request using the `Vonage::SMS#verify_webhook_sig` method. As well as the **request params** from the received webhook, the method also needs access to the signature secret associated with the Vonage account (available from the [Vonage Dashboard](https://dashboard.nexmo.com/settings)), and the signature method used for signing (e.g. `sha512`), again this is based on thes setting in the Dashboard.
194
+
195
+ There are a few different ways of providing these values to the method:
196
+
197
+ 1. Pass all values to the method invocation.
159
198
 
160
199
  ```ruby
161
- claims = {
162
- application_id: application_id,
163
- private_key: 'path/to/private.key',
164
- nbf: 1483315200,
165
- ttl: 800
166
- }
200
+ client = Vonage::Client.new
167
201
 
168
- token = Vonage::JWT.generate(claims)
202
+ client.sms.verify_webhook_sig(
203
+ webhook_params: params,
204
+ signature_secret: 'secret',
205
+ signature_method: 'sha512'
206
+ ) # => returns true if the signature is valid, false otherwise
207
+ ```
169
208
 
170
- client = Vonage::Client.new(token: token)
171
- ````
209
+ 2. Set `signature_secret` and `signature_method` at `Client` instantiation.
172
210
 
173
- Documentation for the Vonage Ruby JWT generator gem can be found at
174
- [https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby](https://www.rubydoc.info/github/nexmo/nexmo-jwt-ruby).
175
- The documentation outlines all the possible parameters you can use to customize and build a token with.
211
+ ```ruby
212
+ client = Vonage::Client.new(
213
+ signature_secret: 'secret',
214
+ signature_method: 'sha512'
215
+ )
176
216
 
177
- ## Webhook signatures
217
+ client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
218
+ ```
178
219
 
179
- To check webhook signatures you'll also need to specify the `signature_secret` option. For example:
220
+ 3. Set `signature_secret` and `signature_method` on the `Config` object.
180
221
 
181
222
  ```ruby
182
223
  client = Vonage::Client.new
183
224
  client.config.signature_secret = 'secret'
184
225
  client.config.signature_method = 'sha512'
185
226
 
186
- if client.signature.check(request.GET)
187
- # valid signature
188
- else
189
- # invalid signature
190
- end
227
+ client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
191
228
  ```
192
229
 
193
- Alternatively you can set the `VONAGE_SIGNATURE_SECRET` environment variable.
230
+ 4. Set `signature_secret` and `signature_method` as environment variables named `VONAGE_SIGNATURE_SECRET` and `VONAGE_SIGNATURE_METHOD`
194
231
 
195
- Note: you'll need to contact support@nexmo.com to enable message signing on your account.
232
+ ```ruby
233
+ client = Vonage::Client.new
196
234
 
197
- ## Pagination
235
+ client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the signature is valid, false otherwise
236
+ ```
198
237
 
199
- Vonage APIs paginate list requests. This means that if a collection is requested that is larger than the API default, the API will return the first page of items in the collection. The Ruby SDK provides an `auto_advance` parameter that will traverse through the pages and return all the results in one response object.
238
+ **Note:** Webhook signing for the SMS API is not switched on by default. You'll need to contact support@vonage.com to enable message signing on your account.
200
239
 
201
- The `auto_advance` parameter is set to a default of `true` for the following APIs:
240
+ #### Signed JWT in Header
202
241
 
203
- * [Account API](https://developer.nexmo.com/api/developer/account)
204
- * [Application API](https://developer.nexmo.com/api/application.v2)
205
- * [Conversation API](https://developer.nexmo.com/api/conversation)
206
- * [Voice API](https://developer.nexmo.com/api/voice)
242
+ The [Voice API](https://developer.vonage.com/en/voice/voice-api/overview) and [Messages API](https://developer.vonage.com/en/messages/overview) both include an `Authorization` header in their webhook requests. The value of this header includes a JSON Web Token (JWT) signed using the Signature Secret associated with your Vonage account.
207
243
 
208
- To modify the `auto_advance` behavior you can specify it in your method:
244
+ The `Vonage::Voice` and `Vonage::Messaging` classes both define a `verify_webhook_token` method which can be used to verify the JWT received in the webhook `Authorization` header.
245
+
246
+ To verify the JWT, you'll first need to extract it from the `Authorization` header. The header value will look something like the following:
209
247
 
210
248
  ```ruby
211
- client.applications.list(auto_advance: false)
249
+ "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE1OTUyN" # remainder of token omitted for brevity
212
250
  ```
213
251
 
214
- ## NCCO Builder
252
+ Note: we are only interested in the token itself, which comes *after* the word `Bearer` and the space.
215
253
 
216
- The Vonage Voice API accepts instructions via JSON objects called NCCOs. Each NCCO can be made up multiple actions that are executed in the order they are written. The Vonage API Developer Portal contains an [NCCO Reference](https://developer.vonage.com/voice/voice-api/ncco-reference) with instructions and information on all the parameters possible.
254
+ Once you have extrated the token, you can pass it to the `verify_webhook_token` method in order to verify it.
217
255
 
218
- The SDK includes an NCCO builder that you can use to build NCCOs for your Voice API methods.
256
+ The method also needs access to the the method also needs access to the signature secret associated with the Vonage account (available from the [Vonage Dashboard](https://dashboard.nexmo.com/settings)). There are a few different ways of providing this value to the method:
219
257
 
220
- For example, to build `talk` and `input` NCCO actions and then combine them into a single NCCO you would do the following:
258
+ 1. Pass all values to the method invocation.
221
259
 
222
260
  ```ruby
223
- talk = Vonage::Voice::Ncco.talk(text: 'Hello World!')
224
- input = Vonage::Voice::Ncco.input(type: ['dtmf'], dtmf: { bargeIn: true })
225
- ncco = Vonage::Voice::Ncco.build(talk, input)
261
+ client = Vonage::Client.new
226
262
 
227
- # => [{:action=>"talk", :text=>"Hello World!"}, {:action=>"input", :type=>["dtmf"], :dtmf=>{:bargeIn=>true}}]
263
+ client.voice.verify_webhook_token(
264
+ token: extracted_token,
265
+ signature_secret: 'secret'
266
+ ) # => returns true if the token is valid, false otherwise
228
267
  ```
229
268
 
230
- Once you have the constructed NCCO you can then use it in a Voice API request:
269
+ 2. Set `signature_secret` at `Client` instantiation.
231
270
 
232
271
  ```ruby
233
- response = client.voice.create({
234
- to: [{type: 'phone', number: '14843331234'}],
235
- from: {type: 'phone', number: '14843335555'},
236
- ncco: ncco
237
- })
272
+ client = Vonage::Client.new(
273
+ signature_secret: 'secret'
274
+ )
275
+
276
+ client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
277
+ ```
278
+
279
+ 3. Set `signature_secret` on the `Config` object.
280
+
281
+ ```ruby
282
+ client = Vonage::Client.new
283
+ client.config.signature_secret = 'secret'
284
+ client.config.signature_method = 'sha512'
285
+
286
+ client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
287
+ ```
288
+
289
+ 4. Set `signature_secret` as an environment variable named `VONAGE_SIGNATURE_SECRET`
290
+
291
+ ```ruby
292
+ client = Vonage::Client.new
293
+
294
+ client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
295
+ ```
296
+
297
+ ### Pagination
298
+
299
+ Vonage APIs paginate list requests. This means that if a collection is requested that is larger than the API default, the API will return the first page of items in the collection. The Ruby SDK provides an `auto_advance` parameter that will traverse through the pages and return all the results in one response object.
300
+
301
+ The `auto_advance` parameter is set to a default of `true` for the following APIs:
302
+
303
+ * [Account API](https://developer.nexmo.com/api/developer/account)
304
+ * [Application API](https://developer.nexmo.com/api/application.v2)
305
+ * [Conversation API](https://developer.nexmo.com/api/conversation)
306
+ * [Voice API](https://developer.nexmo.com/api/voice)
307
+
308
+ To modify the `auto_advance` behavior you can specify it in your method:
309
+
310
+ ```ruby
311
+ client.applications.list(auto_advance: false)
238
312
  ```
239
313
 
314
+
240
315
  ## Messages API
241
316
 
242
317
  The [Vonage Messages API](https://developer.vonage.com/messages/overview) allows you to send messages over a number of different channels, and various message types within each channel. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/api/messages-olympus) listing all the channel and message type combinations.
@@ -388,40 +463,85 @@ if code_check.http_response.code == '200'
388
463
  end
389
464
  ```
390
465
 
466
+ ## Voice API
467
+
468
+ The [Vonage Voice API](The [Vonage Verify API v2](https://developer.vonage.com/en/verify/verify-v2/overview) allows you to automate voice interactions by creating calls, streaming audio, playing text to speech, playing DTMF tones, and other actions. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/voice) listing all the Voice API capabilities.
469
+
470
+ The Ruby SDK provides numerous methods for interacting with the Voice v2 API. Here's an example of using the `create` method to make an outbound text-to-speech call:
471
+
472
+ ```ruby
473
+ response = client.voice.create(
474
+ to: [{
475
+ type: 'phone',
476
+ number: '447700900000'
477
+ }],
478
+ from: {
479
+ type: 'phone',
480
+ number: '447700900001'
481
+ },
482
+ answer_url: [
483
+ 'https://raw.githubusercontent.com/nexmo-community/ncco-examples/gh-pages/text-to-speech.json'
484
+ ]
485
+ )
486
+ ```
487
+
488
+ ### NCCO Builder
489
+
490
+ The Vonage Voice API accepts instructions via JSON objects called NCCOs. Each NCCO can be made up multiple actions that are executed in the order they are written. The Vonage API Developer Portal contains an [NCCO Reference](https://developer.vonage.com/voice/voice-api/ncco-reference) with instructions and information on all the parameters possible.
491
+
492
+ The SDK includes an NCCO builder that you can use to build NCCOs for your Voice API methods.
493
+
494
+ For example, to build `talk` and `input` NCCO actions and then combine them into a single NCCO you would do the following:
495
+
496
+ ```ruby
497
+ talk = Vonage::Voice::Ncco.talk(text: 'Hello World!')
498
+ input = Vonage::Voice::Ncco.input(type: ['dtmf'], dtmf: { bargeIn: true })
499
+ ncco = Vonage::Voice::Ncco.build(talk, input)
500
+
501
+ # => [{:action=>"talk", :text=>"Hello World!"}, {:action=>"input", :type=>["dtmf"], :dtmf=>{:bargeIn=>true}}]
502
+ ```
503
+
504
+ Once you have the constructed NCCO you can then use it in a Voice API request:
505
+
506
+ ```ruby
507
+ response = client.voice.create({
508
+ to: [{type: 'phone', number: '14843331234'}],
509
+ from: {type: 'phone', number: '14843335555'},
510
+ ncco: ncco
511
+ })
512
+ ```
513
+
391
514
  ## Documentation
392
515
 
393
- Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk
516
+ Vonage Ruby SDK documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk
394
517
 
395
- Vonage Ruby code examples: https://github.com/Vonage/vonage-ruby-code-snippets
518
+ Vonage Ruby SDK code examples: https://github.com/Vonage/vonage-ruby-code-snippets
396
519
 
397
520
  Vonage APIs API reference: https://developer.nexmo.com/api
398
521
 
399
- ## Frequently Asked Questions
400
-
401
522
  ## Supported APIs
402
523
 
403
- The following is a list of Vonage APIs and whether the Ruby SDK provides support for them:
404
-
405
- | API | API Release Status | Supported?
406
- |----------|:---------:|:-------------:|
407
- | Account API | General Availability |✅|
408
- | Alerts API | General Availability |✅|
409
- | Application API | General Availability |✅|
410
- | Audit API | Beta |❌|
411
- | Conversation API | Beta |❌|
412
- | Dispatch API | Beta |❌|
413
- | External Accounts API | Beta |❌|
414
- | Media API | Beta | ❌|
415
- | Messages API | General Availability |✅|
416
- | Number Insight API | General Availability |✅|
417
- | Number Management API | General Availability |✅|
418
- | Pricing API | General Availability |✅|
419
- | Redact API | Developer Preview |✅|
420
- | Reports API | Beta |❌|
421
- | SMS API | General Availability |✅|
422
- | Verify API | General Availability |✅|
423
- | Verify API v2 | General Availability |✅|
424
- | Voice API | General Availability |✅|
524
+ The following is a list of Vonage APIs for which the Ruby SDK currently provides support:
525
+
526
+ * [Account API](https://developer.vonage.com/en/account/overview)
527
+ * [Application API](https://developer.vonage.com/en/application/overview)
528
+ * [Meetings API](https://developer.vonage.com/en/meetings/overview)
529
+ * [Messages API](https://developer.vonage.com/en/messages/overview)
530
+ * [Number Insight API](https://developer.vonage.com/en/number-insight/overview)
531
+ * [Numbers API](https://developer.vonage.com/en/numbers/overview)
532
+ * [Proactive Connect API](https://developer.vonage.com/en/proactive-connect/overview) *
533
+ * [Redact API](https://developer.vonage.com/en/redact/overview)
534
+ * [SMS API](https://developer.vonage.com/en/messaging/sms/overview)
535
+ * [Subaccounts API](https://developer.vonage.com/en/account/subaccounts/overview)
536
+ * [Verify API](https://developer.vonage.com/en/verify/overview)
537
+ * [Voice API](https://developer.vonage.com/en/verify/overview)
538
+
539
+ \* The Proactive Connect API is partially supported in the SDK. Specifically, the Events, Items, and Lists endpoints are supported.
540
+
541
+ ## Other SDKs and Tools
542
+
543
+ You can find information about other Vonage SDKs and Tooling on our [Developer Portal](https://developer.vonage.com/en/tools).
544
+
425
545
 
426
546
  ## License
427
547
 
@@ -429,3 +549,13 @@ This library is released under the [Apache 2.0 License][license]
429
549
 
430
550
  [signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library
431
551
  [license]: LICENSE.txt
552
+
553
+ ## Contribute!
554
+
555
+ _We :heart: contributions to this library!_
556
+
557
+ It is a good idea to [talk to us](https://developer.vonage.com/community/slack)
558
+ first if you plan to add any new functionality.
559
+ Otherwise, [bug reports](https://github.com/Vonage/vonage-ruby-sdk/issues),
560
+ [bug fixes](https://github.com/Vonage/vonage-ruby-sdk/pulls) and feedback on the
561
+ library are always appreciated.
@@ -33,6 +33,8 @@ module Vonage
33
33
  #
34
34
  # response = client.applications.create(params)
35
35
  #
36
+ # @param [Hash] params
37
+ #
36
38
  # @option params [required, String] :name
37
39
  # Application name.
38
40
  #
@@ -44,7 +46,9 @@ module Vonage
44
46
  # This contains the configuration for each product.
45
47
  # This replaces the application `type` from version 1 of the Application API.
46
48
  #
47
- # @param [Hash] params
49
+ # @option params [Hash] :privacy
50
+ # - **:improve_ai** (Boolean) If set to `true``, Vonage may store and use your content and data for the improvement
51
+ # of Vonage's AI based services and technologies.
48
52
  #
49
53
  # @return [Response]
50
54
  #
@@ -73,7 +77,7 @@ module Vonage
73
77
  # Set this to `false` to not auto-advance through all the pages in the record
74
78
  # and collect all the data. The default is `true`.
75
79
  # @param [Hash] params
76
- #
80
+ #
77
81
  # @return [ListResponse]
78
82
  #
79
83
  # @see https://developer.nexmo.com/api/application.v2#listApplication
@@ -109,6 +113,9 @@ module Vonage
109
113
  # @example
110
114
  # response = client.applications.update(id, answer_method: 'POST')
111
115
  #
116
+ # @param [String] id
117
+ # @param [Hash] params
118
+ #
112
119
  # @option params [required, String] :name
113
120
  # Application name.
114
121
  #
@@ -120,8 +127,9 @@ module Vonage
120
127
  # This contains the configuration for each product.
121
128
  # This replaces the application `type` from version 1 of the Application API.
122
129
  #
123
- # @param [String] id
124
- # @param [Hash] params
130
+ # @option params [Hash] :privacy
131
+ # - **:improve_ai** (Boolean) If set to `true``, Vonage may store and use your content and data for the improvement
132
+ # of Vonage's AI based services and technologies.
125
133
  #
126
134
  # @return [Response]
127
135
  #
data/lib/vonage/client.rb CHANGED
@@ -89,6 +89,13 @@ module Vonage
89
89
  @number_insight ||= T.let(NumberInsight.new(config), T.nilable(Vonage::NumberInsight))
90
90
  end
91
91
 
92
+ # @return [NumberInsight2]
93
+ #
94
+ sig { returns(T.nilable(Vonage::NumberInsight2)) }
95
+ def number_insight_2
96
+ @number_insight_2 ||= T.let(NumberInsight2.new(config), T.nilable(Vonage::NumberInsight2))
97
+ end
98
+
92
99
  # @return [Numbers]
93
100
  #
94
101
  sig { returns(T.nilable(Vonage::Numbers)) }
@@ -166,6 +173,13 @@ module Vonage
166
173
  @verify2 ||= T.let(Verify2.new(config), T.nilable(Vonage::Verify2))
167
174
  end
168
175
 
176
+ # @return [Video]
177
+ #
178
+ sig { returns(T.nilable(Vonage::Video)) }
179
+ def video
180
+ @video ||= T.let(Video.new(config), T.nilable(Vonage::Video))
181
+ end
182
+
169
183
  # @return [Voice]
170
184
  #
171
185
  sig { returns(T.nilable(Vonage::Voice)) }
data/lib/vonage/config.rb CHANGED
@@ -18,6 +18,7 @@ module Vonage
18
18
  self.signature_secret = ENV['VONAGE_SIGNATURE_SECRET']
19
19
  self.signature_method = ENV['VONAGE_SIGNATURE_METHOD'] || 'md5hash'
20
20
  self.token = T.let(nil, T.nilable(String))
21
+ self.video_host = 'video.api.vonage.com'
21
22
  self.vonage_host = 'api-eu.vonage.com'
22
23
  end
23
24
 
@@ -203,6 +204,9 @@ module Vonage
203
204
  sig { params(token: T.nilable(String)).returns(T.nilable(String)) }
204
205
  attr_writer :token
205
206
 
207
+ sig { returns(String) }
208
+ attr_accessor :video_host
209
+
206
210
  sig { returns(String) }
207
211
  attr_accessor :vonage_host
208
212
 
data/lib/vonage/jwt.rb CHANGED
@@ -39,5 +39,22 @@ module Vonage
39
39
  payload[:private_key] = private_key if private_key && !payload[:private_key]
40
40
  @token = Vonage::JWTBuilder.new(payload).jwt.generate
41
41
  end
42
+
43
+ # Validate a JSON Web Token from a Vonage Webhook.
44
+ #
45
+ # Certain Vonage APIs include a JWT signed with a user's account signature secret in
46
+ # the Authorization header of Webhook requests. This method can be used to verify that those requests originate
47
+ # from the Vonage API.
48
+ #
49
+ # @param [String, required] :token The JWT from the Webhook's Authorization header
50
+ # @param [String, required] :signature_secret The account signature secret
51
+ #
52
+ # @return [Boolean] true, if the JWT is verified, false otherwise
53
+ #
54
+ # @see https://developer.vonage.com/en/getting-started/concepts/webhooks#decoding-signed-webhooks
55
+ #
56
+ def self.verify_hs256_signature(token:, signature_secret:)
57
+ verify_signature(token, signature_secret, 'HS256')
58
+ end
42
59
  end
43
60
  end
data/lib/vonage/keys.rb CHANGED
@@ -21,7 +21,15 @@ module Vonage
21
21
  'voice_callback_value',
22
22
  'voice_status_callback',
23
23
  'messages_callback_value',
24
- 'messages_callback_type'
24
+ 'messages_callback_type',
25
+ 'add_stream',
26
+ 'has_audio',
27
+ 'has_video',
28
+ 'remove_stream',
29
+ 'screenshare_type',
30
+ 'session_id',
31
+ 'stream_mode',
32
+ 'archive_mode'
25
33
  ]
26
34
  hash.transform_keys do |k|
27
35
  if exceptions.include?(k.to_s)
@@ -89,7 +89,7 @@ module Vonage
89
89
  # @param [optional, Hash] :ui_settings Provides options to customize the user interface
90
90
  # @option :ui_settings [String] :language
91
91
  # The desired language of the UI. The default is `en` (English).
92
- # Must be one of: `en`, `fr`, `de`, `es`, `pt`, `ca`, `he`
92
+ # Must be one of: `ar`, `pt-br`, `ca`, `zh-tw`, `zh-cn`, `en`, `fr`, `de`, `he`, `it`, `es`
93
93
  #
94
94
  # @return [Response]
95
95
  #
@@ -6,6 +6,6 @@ class Vonage::Meetings::Sessions::ListResponse < Vonage::Response
6
6
  def each
7
7
  return enum_for(:each) unless block_given?
8
8
 
9
- @entity._embedded.each { |item| yield item }
9
+ @entity._embedded.recordings.each { |item| yield item }
10
10
  end
11
11
  end
@@ -25,5 +25,16 @@ module Vonage
25
25
  def send(params)
26
26
  request('/v1/messages', params: params, type: Post)
27
27
  end
28
+
29
+ # Validate a JSON Web Token from a Messages API Webhook.
30
+ #
31
+ # @param [String, required] :token The JWT from the Webhook's Authorization header
32
+ # @param [String, optional] :signature_secret The account signature secret. Required, unless `signature_secret`
33
+ # is set in `Config`
34
+ #
35
+ # @return [Boolean] true, if the JWT is verified, false otherwise
36
+ def verify_webhook_token(token:, signature_secret: @config.signature_secret)
37
+ JWT.verify_hs256_signature(token: token, signature_secret: signature_secret)
38
+ end
28
39
  end
29
40
  end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'net/http'
5
+ require 'net/http/persistent'
5
6
  require 'net/http/post/multipart'
6
7
  require 'json'
7
8
 
@@ -12,8 +13,7 @@ module Vonage
12
13
 
13
14
  @host = set_host
14
15
 
15
- @http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
16
- @http.use_ssl = true
16
+ @http = Net::HTTP::Persistent.new
17
17
 
18
18
  @config.http.set(@http) unless @config.http.nil?
19
19
  end
@@ -23,8 +23,7 @@ module Vonage
23
23
  end
24
24
 
25
25
  def self.host=(host)
26
- raise ArgumentError unless %i[rest_host vonage_host].include?(host)
27
-
26
+ raise ArgumentError unless %i[rest_host video_host vonage_host].include?(host)
28
27
  @host = host
29
28
  end
30
29
 
@@ -95,7 +94,8 @@ module Vonage
95
94
  def make_request!(request, &block)
96
95
  logger.log_request_info(request)
97
96
 
98
- response = @http.request(request, &block)
97
+ uri = URI("https://" + @host + request.path)
98
+ response = @http.request(uri, request, &block)
99
99
 
100
100
  logger.log_response_info(response, @host)
101
101
 
@@ -144,7 +144,7 @@ module Vonage
144
144
 
145
145
  uri = override_uri ? URI(override_uri) : URI('https://' + @host + path)
146
146
 
147
- http = override_uri ? Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil) : @http
147
+ http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil)
148
148
  http.use_ssl = true
149
149
  http.set_debug_output($stdout)
150
150
 
@@ -273,7 +273,7 @@ module Vonage
273
273
  when Net::HTTPNoContent
274
274
  response_class.new(nil, response)
275
275
  when Net::HTTPSuccess
276
- if response['Content-Type'] && response['Content-Type'].split(';').first == 'application/json'
276
+ if response['Content-Type'] && response['Content-Type'].split(';').first == 'application/json' && !response.body.empty?
277
277
  entity = ::JSON.parse(response.body, object_class: Vonage::Entity)
278
278
 
279
279
  response_class.new(entity, response)
@@ -295,6 +295,8 @@ module Vonage
295
295
  case self.class.host
296
296
  when :rest_host
297
297
  @config.rest_host
298
+ when :video_host
299
+ @config.video_host
298
300
  when :vonage_host
299
301
  @config.vonage_host
300
302
  else