vonage 7.18.0 → 7.19.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: 1efb8423ce5ccb2549f6f3d65ddc659ab8c28a965888372b06845911b3e598ff
4
- data.tar.gz: 4bc50573bada4e41fa89bb63ea02633435426f482722caafd10a904ca7a6b3ea
3
+ metadata.gz: 748a3a579f5c7c4a263b7b840234b0489e7b895e63d43d939f01bdc177616a53
4
+ data.tar.gz: 6e2b5d3d0a8135aff72a1314c33a833c1a77384f7a6047e6147c013e29e6ea45
5
5
  SHA512:
6
- metadata.gz: 296c28e8d4a3f469f938ee2b5cad316a6e3a08696fbce2d17b8afcc3abac5a6d135be9acdb589f3ca4ab73d3ff25d77d37d1457d774bc1149043c6684c0387a4
7
- data.tar.gz: 2cea85e954c16bd217efad49454183a68aac48aabb4d995eb1db5376902ff1fe13e296867ffadea0695c8586b6bc06e953004894e35cb487701a8327073315ec
6
+ metadata.gz: 913f6f7f81f667513740f61849db751dfdd9dc60ca6366c81b6e621564e53719f3503a5085ed38f7c48570dd55a33a26b5037af136387aa2226ed7c8a4542b2c
7
+ data.tar.gz: 636e92166449f951489340b2cb00a00c7f72225fd2239f4ba9faba6919e72bd17ba24454f8a2be9ed2be8c6f76382045490a2d24b13e09bb1323dbb5dbadcb81
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,46 +180,13 @@ 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
-
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
-
147
- ```ruby
148
- client = Vonage::Client.new(application_id: application_id, private_key: private_key)
149
- ```
150
183
 
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.
155
-
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:
159
-
160
- ```ruby
161
- claims = {
162
- application_id: application_id,
163
- private_key: 'path/to/private.key',
164
- nbf: 1483315200,
165
- ttl: 800
166
- }
167
-
168
- token = Vonage::JWT.generate(claims)
169
-
170
- client = Vonage::Client.new(token: token)
171
- ```
172
-
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.
176
184
 
177
- ## Webhook signatures
185
+ ### Webhook signatures
178
186
 
179
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.
180
188
 
181
- ### Signature in Request Body
189
+ #### Signature in Request Body
182
190
 
183
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.
184
192
 
@@ -229,7 +237,7 @@ client.sms.verify_webhook_sig(webhook_params: params) # => returns true if the s
229
237
 
230
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.
231
239
 
232
- ### Signed JWT in Header
240
+ #### Signed JWT in Header
233
241
 
234
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.
235
243
 
@@ -286,7 +294,7 @@ client = Vonage::Client.new
286
294
  client.voice.verify_webhook_token(token: extracted_token) # => returns true if the token is valid, false otherwise
287
295
  ```
288
296
 
289
- ## Pagination
297
+ ### Pagination
290
298
 
291
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.
292
300
 
@@ -303,31 +311,6 @@ To modify the `auto_advance` behavior you can specify it in your method:
303
311
  client.applications.list(auto_advance: false)
304
312
  ```
305
313
 
306
- ## NCCO Builder
307
-
308
- 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.
309
-
310
- The SDK includes an NCCO builder that you can use to build NCCOs for your Voice API methods.
311
-
312
- For example, to build `talk` and `input` NCCO actions and then combine them into a single NCCO you would do the following:
313
-
314
- ```ruby
315
- talk = Vonage::Voice::Ncco.talk(text: 'Hello World!')
316
- input = Vonage::Voice::Ncco.input(type: ['dtmf'], dtmf: { bargeIn: true })
317
- ncco = Vonage::Voice::Ncco.build(talk, input)
318
-
319
- # => [{:action=>"talk", :text=>"Hello World!"}, {:action=>"input", :type=>["dtmf"], :dtmf=>{:bargeIn=>true}}]
320
- ```
321
-
322
- Once you have the constructed NCCO you can then use it in a Voice API request:
323
-
324
- ```ruby
325
- response = client.voice.create({
326
- to: [{type: 'phone', number: '14843331234'}],
327
- from: {type: 'phone', number: '14843335555'},
328
- ncco: ncco
329
- })
330
- ```
331
314
 
332
315
  ## Messages API
333
316
 
@@ -480,40 +463,85 @@ if code_check.http_response.code == '200'
480
463
  end
481
464
  ```
482
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
+
483
514
  ## Documentation
484
515
 
485
- 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
486
517
 
487
- 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
488
519
 
489
520
  Vonage APIs API reference: https://developer.nexmo.com/api
490
521
 
491
- ## Frequently Asked Questions
492
-
493
522
  ## Supported APIs
494
523
 
495
- The following is a list of Vonage APIs and whether the Ruby SDK provides support for them:
496
-
497
- | API | API Release Status | Supported?
498
- |----------|:---------:|:-------------:|
499
- | Account API | General Availability |✅|
500
- | Alerts API | General Availability |✅|
501
- | Application API | General Availability |✅|
502
- | Audit API | Beta |❌|
503
- | Conversation API | Beta |❌|
504
- | Dispatch API | Beta |❌|
505
- | External Accounts API | Beta |❌|
506
- | Media API | Beta | ❌|
507
- | Messages API | General Availability |✅|
508
- | Number Insight API | General Availability |✅|
509
- | Number Management API | General Availability |✅|
510
- | Pricing API | General Availability |✅|
511
- | Redact API | Developer Preview |✅|
512
- | Reports API | Beta |❌|
513
- | SMS API | General Availability |✅|
514
- | Verify API | General Availability |✅|
515
- | Verify API v2 | General Availability |✅|
516
- | 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
+
517
545
 
518
546
  ## License
519
547
 
@@ -521,3 +549,13 @@ This library is released under the [Apache 2.0 License][license]
521
549
 
522
550
  [signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=ruby-client-library
523
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.
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/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)
@@ -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
 
@@ -273,7 +272,7 @@ module Vonage
273
272
  when Net::HTTPNoContent
274
273
  response_class.new(nil, response)
275
274
  when Net::HTTPSuccess
276
- if response['Content-Type'] && response['Content-Type'].split(';').first == 'application/json'
275
+ if response['Content-Type'] && response['Content-Type'].split(';').first == 'application/json' && !response.body.empty?
277
276
  entity = ::JSON.parse(response.body, object_class: Vonage::Entity)
278
277
 
279
278
  response_class.new(entity, response)
@@ -295,6 +294,8 @@ module Vonage
295
294
  case self.class.host
296
295
  when :rest_host
297
296
  @config.rest_host
297
+ when :video_host
298
+ @config.video_host
298
299
  when :vonage_host
299
300
  @config.vonage_host
300
301
  else
@@ -0,0 +1,36 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class NumberInsight2 < Namespace
6
+ extend T::Sig
7
+
8
+ self.authentication = Basic
9
+
10
+ self.request_body = JSON
11
+
12
+ # Make fraud check requests with a phone number by looking up fraud score and/or by checking sim swap status.
13
+ #
14
+ # @example
15
+ # response = client.number_insight_2.fraud_check(type: 'phone', phone: '447900000000', insights: ['fraud_score'])
16
+ #
17
+ # @param [required, String] :type The type of number to check.
18
+ # Accepted value is “phone” when a phone number is provided.
19
+ #
20
+ # @param [required, String] :phone A single phone number that you need insight about in the E.164 format.
21
+ #
22
+ # @param [required, Array] :insights An array of strings indicating the fraud check insights required for the number.
23
+ # Must be least one of: `fraud_score`, `sim_swap`
24
+ #
25
+ # @return [Response]
26
+ #
27
+ # @see https://developer.vonage.com/en/api/number-insight.v2#fraud_check
28
+ #
29
+ sig { params(type: String, phone: String, insights: T::Array[String]).returns(Vonage::Response) }
30
+ def fraud_check(type:, phone:, insights:)
31
+ raise ArgumentError.new("`insights` must not be an empty") if insights.empty?
32
+
33
+ request('/v2/ni', params: {type: type, phone: phone, insights: insights}, type: Post)
34
+ end
35
+ end
36
+ end
@@ -10,16 +10,14 @@ module Vonage
10
10
  def initialize(to:, from: nil)
11
11
  self.channel = 'email'
12
12
  self.to = to
13
- self.from = from if from
13
+ self.from = from unless from.nil?
14
14
  end
15
15
 
16
16
  def to=(to)
17
- # TODO: add validation
18
17
  @to = to
19
18
  end
20
19
 
21
20
  def from=(from)
22
- # TODO: add validation
23
21
  @from = from
24
22
  end
25
23
 
@@ -1,15 +1,18 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
  require 'phonelib'
4
+ require 'uri'
4
5
 
5
6
  module Vonage
6
7
  class Verify2::Channels::SilentAuth
7
8
 
8
- attr_reader :channel, :to
9
+ attr_reader :channel, :to, :sandbox, :redirect_url
9
10
 
10
- def initialize(to:)
11
+ def initialize(to:, redirect_url: nil, sandbox: nil)
11
12
  self.channel = 'silent_auth'
12
13
  self.to = to
14
+ self.redirect_url = redirect_url unless redirect_url.nil?
15
+ self.sandbox = sandbox unless sandbox.nil?
13
16
  end
14
17
 
15
18
  def to=(to)
@@ -17,6 +20,16 @@ module Vonage
17
20
  @to = to
18
21
  end
19
22
 
23
+ def redirect_url=(redirect_url)
24
+ raise ArgumentError, "Invalid 'to' value #{redirect_url}. Expected to be a valid URL" unless URI.parse(redirect_url).is_a?(URI::HTTP)
25
+ @redirect_url = redirect_url
26
+ end
27
+
28
+ def sandbox=(sandbox)
29
+ raise ArgumentError, "Invalid 'sandbox' value #{sandbox}. Expected to be boolean value" unless [true, false].include? sandbox
30
+ @sandbox = sandbox
31
+ end
32
+
20
33
  def to_h
21
34
  hash = Hash.new
22
35
  self.instance_variables.each do |ivar|
@@ -11,7 +11,7 @@ module Vonage
11
11
  def initialize(to:, app_hash: nil)
12
12
  self.channel = 'sms'
13
13
  self.to = to
14
- self.app_hash = app_hash if app_hash
14
+ self.app_hash = app_hash unless app_hash.nil?
15
15
  end
16
16
 
17
17
  def to=(to)
@@ -10,7 +10,7 @@ module Vonage
10
10
  def initialize(to:, from: nil)
11
11
  self.channel = 'whatsapp'
12
12
  self.to = to
13
- self.from = from if from
13
+ self.from = from unless from.nil?
14
14
  end
15
15
 
16
16
  def to=(to)
@@ -10,7 +10,7 @@ module Vonage
10
10
  # Request a verification be sent to a user.
11
11
  #
12
12
  # @example
13
- # verification_request = verify.start_verification(
13
+ # verification_request = client.verify2.start_verification(
14
14
  # brand: 'Acme',
15
15
  # workflow: [{channel: 'sms', to: '447000000000'}],
16
16
  # code_length: 6
@@ -41,7 +41,7 @@ module Vonage
41
41
  # Check a supplied code against a request to see if it is valid.
42
42
  #
43
43
  # @example
44
- # code_check = verify.check_code(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2', code: '1234')
44
+ # code_check = client.verify2.check_code(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2', code: '1234')
45
45
  #
46
46
  # @param [required, String] :request_id The request_id of the verification request being checked
47
47
  #
@@ -56,7 +56,7 @@ module Vonage
56
56
  # Cancel a verifiction. If a verification request is still active, calling this method aborts the workflow.
57
57
  #
58
58
  # @example
59
- # verify.cancel_verification_request(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2')
59
+ # client.verify2.cancel_verification_request(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2')
60
60
  #
61
61
  # @param [required, String] :request_id The request_id of the verification request to be cancelled
62
62
  #
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = "7.18.0"
4
+ VERSION = '7.19.0'
5
5
  end
@@ -0,0 +1,11 @@
1
+ # typed: true
2
+
3
+ class Vonage::Video::Archives::ListResponse < Vonage::Response
4
+ include Enumerable
5
+
6
+ def each
7
+ return enum_for(:each) unless block_given?
8
+
9
+ @entity.items.each { |item| yield item }
10
+ end
11
+ end
@@ -0,0 +1,152 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::Archives < Namespace
6
+ include Keys
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.request_body = JSON
11
+
12
+ self.host = :video_host
13
+
14
+ # Get a list of archives for a specified Vonage application.
15
+ #
16
+ # @param [optional, Integer] :offset
17
+ #
18
+ # @param [optional, Integer] :count
19
+ #
20
+ # @param [optional, String] :session_id
21
+ #
22
+ # TODO: add auto_advance option
23
+ #
24
+ # @return [ListResponse]
25
+ #
26
+ # @see TODO: add docs link
27
+ #
28
+ def list(**params)
29
+ request('/v2/project/' + @config.application_id + '/archive', params: params, response_class: ListResponse)
30
+ end
31
+
32
+ # Return information for specified archive.
33
+ #
34
+ # @param [required, String] archive_id
35
+ #
36
+ # @return [Response]
37
+ #
38
+ # @see TODO: add docs link
39
+ #
40
+ def info(archive_id:)
41
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id)
42
+ end
43
+
44
+ # Create a new archive.
45
+ #
46
+ # @param [required, String] :session_id
47
+ #
48
+ # @param [optional, String] :hasAudio
49
+ #
50
+ # @param [optional, String] :hasVideo
51
+ #
52
+ # @param [optional, String] :name
53
+ #
54
+ # @param [optional, String] :outputMode
55
+ #
56
+ # @param [optional, String] :resolution
57
+ #
58
+ # @param [optional, String] :streamMode
59
+ #
60
+ # @param [optional, String] :multiArchiveTag
61
+ #
62
+ # @param [optional, Hash] :layout
63
+ #
64
+ # @option layout [optional, String] :type
65
+ #
66
+ # @option layout [optional, String] :stylesheet
67
+ #
68
+ # @option layout [optional, String] :screenshareType
69
+ #
70
+ # @return [Response]
71
+ #
72
+ # @see TODO: add docs link
73
+ #
74
+ def start(session_id:, **params)
75
+ request('/v2/project/' + @config.application_id + '/archive', params: camelcase(params.merge(session_id: session_id)), type: Post)
76
+ end
77
+
78
+ # Stop recording a specified archive.
79
+ #
80
+ # @param [required, String] archive_id
81
+ #
82
+ # @return [Response]
83
+ #
84
+ # @see TODO: add docs link
85
+ #
86
+ def stop(archive_id:)
87
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id + '/stop', type: Post)
88
+ end
89
+
90
+ # Delete a specified archive.
91
+ #
92
+ # @param [required, String] archive_id
93
+ #
94
+ # @return [Response]
95
+ #
96
+ # @see TODO: add docs link
97
+ #
98
+ def delete(archive_id:)
99
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id, type: Delete)
100
+ end
101
+
102
+ # Add a stream to a composed archive that was started with the streamMode set to "manual".
103
+ #
104
+ # @param [required, String] archive_id
105
+ #
106
+ # @param [required, String] stream_id The ID of the stream to be added
107
+ #
108
+ # @param [optional, Boolean] has_audio
109
+ #
110
+ # @param [optional, Boolean] has_video
111
+ #
112
+ # @return [Response]
113
+ #
114
+ # @see TODO: add docs link
115
+ #
116
+ def add_stream(archive_id:, stream_id:, **params)
117
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id + '/streams', params: camelcase(params.merge(addStream: stream_id)), type: Patch)
118
+ end
119
+
120
+ # Remove a stream from a composed archive that was started with the streamMode set to "manual".
121
+ #
122
+ # @param [required, String] archive_id
123
+ #
124
+ # @param [required, String] stream_id The ID of the stream to be removed
125
+ #
126
+ # @return [Response]
127
+ #
128
+ # @see TODO: add docs link
129
+ #
130
+ def remove_stream(archive_id:, stream_id:)
131
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id + '/streams', params: {removeStream: stream_id}, type: Patch)
132
+ end
133
+
134
+ # Change the layout of a composed archive while it is being recorded.
135
+ #
136
+ # @param [required, String] archive_id
137
+ #
138
+ # @param [optional, String] type
139
+ #
140
+ # @param [optional, String] stylesheet
141
+ #
142
+ # @param [optional, String] screenshare_type
143
+ #
144
+ # @return [Response]
145
+ #
146
+ # @see TODO: add docs link
147
+ #
148
+ def change_layout(archive_id:, **params)
149
+ request('/v2/project/' + @config.application_id + '/archive/' + archive_id + '/layout', params: camelcase(params), type: Put)
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,11 @@
1
+ # typed: true
2
+
3
+ class Vonage::Video::Broadcasts::ListResponse < Vonage::Response
4
+ include Enumerable
5
+
6
+ def each
7
+ return enum_for(:each) unless block_given?
8
+
9
+ @entity.items.each { |item| yield item }
10
+ end
11
+ end
@@ -0,0 +1,75 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::Broadcasts < Namespace
6
+ include Keys
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.request_body = JSON
11
+
12
+ self.host = :video_host
13
+
14
+ # Get a list of live streaming broadcasts for a specified Vonage application.
15
+ #
16
+ def list(**params)
17
+ path = '/v2/project/' + @config.application_id + '/broadcast'
18
+ path += "?#{Params.encode(camelcase(params))}" unless params.empty?
19
+
20
+ request(path, response_class: ListResponse)
21
+ end
22
+
23
+ # Return information for specified broadcast.
24
+ #
25
+ def info(broadcast_id:)
26
+ request('/v2/project/' + @config.application_id + '/broadcast/' + broadcast_id)
27
+ end
28
+
29
+ # Start a new live streaming broadcast.
30
+ #
31
+ def start(session_id:, **params)
32
+ request(
33
+ '/v2/project/' + @config.application_id + '/broadcast',
34
+ params: camelcase(params.merge(session_id: session_id)),
35
+ type: Post
36
+ )
37
+ end
38
+
39
+ # Stop a specified broadcast.
40
+ #
41
+ def stop(broadcast_id:)
42
+ request('/v2/project/' + @config.application_id + '/broadcast/' + broadcast_id + '/stop', type: Post)
43
+ end
44
+
45
+ # Add a stream to a live streaming broadcast.
46
+ #
47
+
48
+ def add_stream(broadcast_id:, stream_id:, **params)
49
+ request(
50
+ '/v2/project/' + @config.application_id + '/broadcast/' + broadcast_id + '/streams',
51
+ params: camelcase(params.merge(addStream: stream_id)),
52
+ type: Patch
53
+ )
54
+ end
55
+
56
+ # Remove a stream from a live streaming broadcast.
57
+ #
58
+ def remove_stream(broadcast_id:, stream_id:)
59
+ request(
60
+ '/v2/project/' + @config.application_id + '/broadcast/' + broadcast_id + '/streams',
61
+ params: {removeStream: stream_id},
62
+ type: Patch
63
+ )
64
+ end
65
+
66
+ # Dynamically change layout of a broadcast.
67
+ #
68
+ def change_layout(broadcast_id:, **params)
69
+ request(
70
+ '/v2/project/' + @config.application_id + '/broadcast/' + broadcast_id + '/layout',
71
+ params: camelcase(params),
72
+ type: Put)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,58 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::Moderation < Namespace
6
+ self.authentication = BearerToken
7
+
8
+ self.request_body = JSON
9
+
10
+ self.host = :video_host
11
+
12
+ # Force a client to disconnect from a session.
13
+ #
14
+ # @param [required, String] :session_id
15
+ #
16
+ # @param [required, String] :connection_id The connection ID of the specific participant to be disconnected from the session.
17
+ #
18
+ # @return [Response]
19
+ #
20
+ # @see TODO: add docs link
21
+ #
22
+ def force_disconnect(session_id:, connection_id:)
23
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/connection/' + connection_id, type: Delete)
24
+ end
25
+
26
+ # Force mute a specific publisher stream in a session.
27
+ #
28
+ # @param [required, String] :session_id
29
+ #
30
+ # @param [required, String] :stream_id The stream ID of the specific stream to be muted.
31
+ #
32
+ # @return [Response]
33
+ #
34
+ # @see TODO: add docs link
35
+ #
36
+ def mute_single_stream(session_id:, stream_id:)
37
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/stream/' + stream_id + '/mute', type: Post)
38
+ end
39
+
40
+ # Force mute all publisher stream for a specific session.
41
+ #
42
+ # @param [required, String] :session_id
43
+ #
44
+ # @param [required, String] :active
45
+ #
46
+ # @param [required, Array<String>] :excludedStreamIds
47
+ #
48
+ # @return [Response]
49
+ #
50
+ # @see TODO: add docs link
51
+ #
52
+ def mute_multiple_streams(session_id:, **params)
53
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/mute', params: params, type: Post)
54
+ end
55
+
56
+ # TODO: add disable_force_mute ??
57
+ end
58
+ end
@@ -0,0 +1,50 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::Signals < Namespace
6
+ self.authentication = BearerToken
7
+
8
+ self.request_body = JSON
9
+
10
+ self.host = :video_host
11
+
12
+ # Send a signal to a specific participant in an active Vonage Video session.
13
+ #
14
+ # @param [optional, String] :application_id (Required unless already set at Client instantiation or set in ENV)
15
+ #
16
+ # @param [required, String] :session_id
17
+ #
18
+ # @param [required, String] :connection_id The connection ID of the specific participant.
19
+ #
20
+ # @param [required, String] :type Type of data that is being sent to the client.
21
+ #
22
+ # @param [required, String] :data Payload that is being sent to the client.
23
+ #
24
+ # @return [Response]
25
+ #
26
+ # @see TODO: add docs link
27
+ #
28
+ def send_to_one(session_id:, connection_id:, **params)
29
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/connection/' + connection_id + '/signal', params: params, type: Post)
30
+ end
31
+
32
+ # Send a signal to all participants in an active Vonage Video session.
33
+ #
34
+ # @param [optional, String] :application_id (Required unless already set at Client instantiation or set in ENV)
35
+ #
36
+ # @param [required, String] :session_id
37
+ #
38
+ # @param [required, String] :type Type of data that is being sent to the client.
39
+ #
40
+ # @param [required, String] :data Payload that is being sent to the client.
41
+ #
42
+ # @return [Response]
43
+ #
44
+ # @see TODO: add docs link
45
+ #
46
+ def send_to_all(session_id:, **params)
47
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/signal', params: params, type: Post)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::SIP < Namespace
6
+ include Keys
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.request_body = JSON
11
+
12
+ self.host = :video_host
13
+
14
+ # Initiate an outbound SIP call.
15
+ #
16
+ def dial(session_id:, token:, sip_uri:, **params)
17
+ request(
18
+ '/v2/project/' + @config.application_id + '/dial',
19
+ params: camelcase({
20
+ session_id: session_id,
21
+ token: token,
22
+ sip: params.merge({uri: sip_uri})
23
+ }),
24
+ type: Post
25
+ )
26
+ end
27
+
28
+ # Play DTMF tones into a SIP call.
29
+ #
30
+ def play_dtmf_to_session(session_id:, dtmf_digits:)
31
+ request(
32
+ '/v2/project/' + @config.application_id + '/session/' + session_id + '/play-dtmf',
33
+ params: {digits: dtmf_digits},
34
+ type: Post
35
+ )
36
+ end
37
+
38
+ # Play DMTF tones into a specific connection.
39
+ #
40
+ def play_dtmf_to_connection(session_id:, connection_id:, dtmf_digits:)
41
+ request(
42
+ '/v2/project/' + @config.application_id + '/session/' + session_id + '/connection/' + connection_id + '/play-dtmf',
43
+ params: {digits: dtmf_digits},
44
+ type: Post
45
+ )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ # typed: true
2
+
3
+ class Vonage::Video::Streams::ListResponse < Vonage::Response
4
+ include Enumerable
5
+
6
+ def each
7
+ return enum_for(:each) unless block_given?
8
+
9
+ @entity.items.each { |item| yield item }
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video::Streams < Namespace
6
+
7
+ self.authentication = BearerToken
8
+
9
+ self.request_body = JSON
10
+
11
+ self.host = :video_host
12
+
13
+ # Get a list of streams for a specified session.
14
+ #
15
+ # @param [optional, String] :application_id (Required unless already set at Client instantiation or set in ENV)
16
+ #
17
+ # @param [required, String] :session_id
18
+ #
19
+ # TODO: add auto_advance option
20
+ #
21
+ # @return [ListResponse]
22
+ #
23
+ # @see TODO: add docs link
24
+ #
25
+ def list(session_id:)
26
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/stream', response_class: ListResponse)
27
+ end
28
+
29
+ # Get information about a specified stream.
30
+ #
31
+ # @param [optional, String] :application_id (Required unless already set at Client instantiation or set in ENV)
32
+ #
33
+ # @param [required, String] :session_id
34
+ #
35
+ # @param [required, String] :stream_id
36
+ #
37
+ # @return [Response]
38
+ #
39
+ # @see TODO: add docs link
40
+ #
41
+ def info(session_id:, stream_id:)
42
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/stream/' + stream_id)
43
+ end
44
+
45
+ # Change the layout for a list of specified streams.
46
+ #
47
+ # @param [optional, String] :application_id (Required unless already set at Client instantiation or set in ENV)
48
+ #
49
+ # @param [required, String] :session_id
50
+ #
51
+ # @param [optional, Array<Hash>] :items An array of hashes representing streams and the layout classes for those streams
52
+ #
53
+ # @option items [required, String] :id The stream ID
54
+ #
55
+ # @option items [required, Array<String>] :layoutClassList Array of CSS class names as strings
56
+ #
57
+ # @return [Response]
58
+ #
59
+ # @see TODO: add docs link
60
+ #
61
+ def change_layout(session_id:, **params)
62
+ # TODO camelcase layout_class_list
63
+ # if params[:items]
64
+ # params[:items] = params[:items].map {|item| camelcase(item)}
65
+ # end
66
+
67
+ request('/v2/project/' + @config.application_id + '/session/' + session_id + '/stream', params: params, type: Put)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,109 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Video < Namespace
6
+ include Keys
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.host = :video_host
11
+
12
+ # Generate a new session.
13
+ #
14
+ # @example
15
+ # session = client.video.create_session({
16
+ # archive_mode: 'always',
17
+ # location: '10.1.200.30',
18
+ # media_mode: 'routed'
19
+ # })
20
+ #
21
+ # @params [optional, String] :archive_mode (either 'always' or 'manual')
22
+ #
23
+ # @param [optional, String] :location
24
+ #
25
+ # @params [optional, String] :media_mode (either 'routed' or 'relayed')
26
+ #
27
+ # @return [Response]
28
+ #
29
+ # @see TODO: Add document link here
30
+ #
31
+ def create_session(**params)
32
+ request_params = params.clone
33
+ request_params[:archive_mode] ||= 'manual'
34
+ media_mode = request_params.delete(:media_mode) || 'routed'
35
+
36
+ if media_mode == 'relayed' && request_params[:archive_mode] == 'manual'
37
+ request_params['p2p.preference'] = 'enabled'
38
+ else
39
+ request_params['p2p.preference'] = 'disabled'
40
+ end
41
+
42
+ response = request('/session/create', params: camelcase(request_params), type: Post)
43
+
44
+ public_response_data = {
45
+ session_id: response.entity.first.session_id,
46
+ archive_mode: request_params[:archive_mode],
47
+ media_mode: media_mode,
48
+ location: request_params[:location]
49
+ }
50
+
51
+ entity = Entity.new(public_response_data)
52
+
53
+ response.class.new(entity, response.http_response)
54
+ end
55
+
56
+ def generate_client_token(session_id:, scope: 'session.connect', role: 'publisher', **params)
57
+ claims = {
58
+ application_id: @config.application_id,
59
+ scope: scope,
60
+ session_id: session_id,
61
+ role: role,
62
+ initial_layout_class_list: '',
63
+ sub: 'video',
64
+ acl: {
65
+ paths: {'/session/**' => {}}
66
+ }
67
+ }
68
+
69
+
70
+ claims[:data] = params[:data] if params[:data]
71
+ claims[:initial_layout_class_list] = params[:initial_layout_class_list].join(' ') if params[:initial_layout_class_list]
72
+ claims[:exp] = params[:expire_time].to_i if params[:expire_time]
73
+
74
+ JWT.generate(claims, @config.private_key)
75
+ end
76
+
77
+ # @return [Archives]
78
+ #
79
+ def archives
80
+ @archives ||= Archives.new(@config)
81
+ end
82
+
83
+ # @return [Broadcasts]
84
+ #
85
+ def broadcasts
86
+ @broadcasts ||= Broadcasts.new(@config)
87
+ end
88
+
89
+ # @return [Moderation]
90
+ #
91
+ def moderation
92
+ @moderation ||= Moderation.new(@config)
93
+ end
94
+
95
+ # @return [Signals]
96
+ #
97
+ def signals
98
+ @signals ||= Signals.new(@config)
99
+ end
100
+
101
+ # @return [Streams]
102
+ #
103
+ def streams
104
+ @streams ||= Streams.new(@config)
105
+ end
106
+
107
+
108
+ end
109
+ end
@@ -1,7 +1,7 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
-
4
- module Vonage
3
+
4
+ module Vonage
5
5
  class Voice::Actions::Conversation
6
6
  attr_accessor :name, :musicOnHoldUrl, :startOnEnter, :endOnExit, :record, :canSpeak, :canHear, :mute
7
7
 
data/lib/vonage.rb CHANGED
@@ -13,6 +13,7 @@ module Vonage
13
13
  'http' => 'HTTP',
14
14
  'json' => 'JSON',
15
15
  'jwt' => 'JWT',
16
+ 'sip' => 'SIP',
16
17
  'sms' => 'SMS',
17
18
  'mms' => 'MMS',
18
19
  'tfa' => 'TFA',
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.18.0
4
+ version: 7.19.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-11-01 00:00:00.000000000 Z
11
+ date: 2023-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vonage-jwt
@@ -161,6 +161,7 @@ files:
161
161
  - lib/vonage/messaging/message.rb
162
162
  - lib/vonage/namespace.rb
163
163
  - lib/vonage/number_insight.rb
164
+ - lib/vonage/number_insight_2.rb
164
165
  - lib/vonage/numbers.rb
165
166
  - lib/vonage/numbers/list_response.rb
166
167
  - lib/vonage/numbers/response.rb
@@ -205,6 +206,16 @@ files:
205
206
  - lib/vonage/verify2/workflow.rb
206
207
  - lib/vonage/verify2/workflow_builder.rb
207
208
  - lib/vonage/version.rb
209
+ - lib/vonage/video.rb
210
+ - lib/vonage/video/archives.rb
211
+ - lib/vonage/video/archives/list_response.rb
212
+ - lib/vonage/video/broadcasts.rb
213
+ - lib/vonage/video/broadcasts/list_response.rb
214
+ - lib/vonage/video/moderation.rb
215
+ - lib/vonage/video/signals.rb
216
+ - lib/vonage/video/sip.rb
217
+ - lib/vonage/video/streams.rb
218
+ - lib/vonage/video/streams/list_response.rb
208
219
  - lib/vonage/voice.rb
209
220
  - lib/vonage/voice/actions/connect.rb
210
221
  - lib/vonage/voice/actions/conversation.rb