vonage 7.33.0 → 7.35.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a5b786bdfd6a5142be34fe1400d4e1914b6d6d9ef4b7e15d10a56e88f9bb5250
4
- data.tar.gz: 5768855f0b0d03e66222694234f257600fa65a4eaf07dc4c0b9ce36471b87807
3
+ metadata.gz: d8bd108a273a45332c5313bec61c2d5237f00d7e1f3c430c6cd057d8e8f13ece
4
+ data.tar.gz: bb19a42705afd74c9fdd435fbb56da73ad978924dc170d86dbf285c22a7887b5
5
5
  SHA512:
6
- metadata.gz: 3596b7759e7dc20c08ea1a127d97519aff481011134db294ac81b01452700757055813b2905d32144ae1977d8daa1d7d391ef1378763360ca3443b117caf7e05
7
- data.tar.gz: e4a089e502ded233cbfbc0c07a60ae5dffceae4e5c550556f377202b7a4cef3b1e42806c3901b81c1c9763a7dd884ae82e9e80e0ecb016e56d0e9bbaeadf7e3d
6
+ metadata.gz: d74a13f6912927c92abea793e544e54089cf7d0679d8e7653e3887e0af913de0c00c255aacdd17711ec6f79b01f7cb5d0a677028385835d6265aae4bfc01bfdb
7
+ data.tar.gz: 33beaadea6c871bc040741962cb6ee2bf05853d7d3b1bbdca5d2ea0281cd10fb2d3189e87f3ba45c64acc4e04338de2fa1905f03f6814b189180755218f3993d
data/README.md CHANGED
@@ -11,6 +11,10 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
11
11
  * [Requirements](#requirements)
12
12
  * [Installation](#installation)
13
13
  * [Usage](#usage)
14
+ * [Authentication](#authentication)
15
+ * [Basic Authentication](#basic-authentication)
16
+ * [JWT Authentication](#jwt-authentication)
17
+ * [Signature Authentication](#signature-authentication)
14
18
  * [Logging](#logging)
15
19
  * [Exceptions](#exceptions)
16
20
  * [Overriding the default hosts](#overriding-the-default-hosts)
@@ -22,6 +26,7 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
22
26
  * [Verify API v2](#verify-api-v2)
23
27
  * [Voice API](#voice-api)
24
28
  * [NCCO Builder](#ncco-builder)
29
+ * [Identity Insights API](#identity-insights-api)
25
30
  * [Documentation](#documentation)
26
31
  * [Supported APIs](#supported-apis)
27
32
  * [Other SDKs and Tools](#other-sdks-and-tools)
@@ -31,8 +36,9 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
31
36
 
32
37
  ## Requirements
33
38
 
34
- Vonage Ruby supports MRI/CRuby (2.5 or newer), JRuby (9.2.x), and Truffleruby.
39
+ Vonage Ruby supports MRI/CRuby (tests in CI are run against 3.3 and newer, but the library will likely still work with any 2.x or newer version).
35
40
 
41
+ JRuby and Truffleruby are supported in theory, but aren't tested against as part of the CI pipeline.
36
42
 
37
43
  ## Installation
38
44
 
@@ -56,7 +62,7 @@ require 'vonage'
56
62
  Then construct a client object with your key and secret:
57
63
 
58
64
  ```ruby
59
- client = Vonage::Client.new(api_key: 'YOUR-API-KEY', api_secret: 'YOUR-API-SECRET')
65
+ client = Vonage::Client.new
60
66
  ```
61
67
 
62
68
  You can now use the client object to call Vonage APIs. For example, to send an SMS:
@@ -65,39 +71,161 @@ You can now use the client object to call Vonage APIs. For example, to send an S
65
71
  client.sms.send(from: 'Ruby', to: '447700900000', text: 'Hello world')
66
72
  ```
67
73
 
68
- For production you can specify the `VONAGE_API_KEY` and `VONAGE_API_SECRET`
69
- environment variables instead of specifying the key and secret explicitly,
70
- keeping your credentials out of source control.
74
+ When instantiating the `Client` object you can pass in various arguments to configure it such as credentials for [authentication](#authentication), values for [overriding the default hosts](overriding-the-default-hosts), or [configuration options for the HTTP client](#http-client-configuration).
75
+
76
+ ### Authentication
77
+
78
+ All requests to the Vonage APIs are authenticated, so the `Client` object will need access to your Vonage credentials. Different Vonage API products support different authenitcations methods, so the credentials required will depend on the authenticaton method used. A few API products also support [multiple authentication methods](#products-with-multiple-authentication-methods).
79
+
80
+ Currently, all Vonage API products support one or more of the following authentication methods:
81
+
82
+ - [Basic Authentication](#basic-authentication)
83
+ - [JWT Authentication](#jwt-authentication)
84
+ - [Signature Authentication](#signature-authentication)
85
+
86
+ For a complete list of which products support which authentication methods, please refer to the [Vonage documentation on this topic](https://developer.vonage.com/en/getting-started/concepts/authentication).
87
+
88
+ Providing the necessary credentials to the client can be done in a number of ways. You can pass the credentials as keyword arguments when calling `Client.new`, for example in order to provide you API Key and API Secret you could use the `api_key` and `api_secret` keyword arguments respectively. You can pass the value for these arguments directly in the method call like so:
89
+
90
+ ```ruby
91
+ client = Vonage::Client.new(api_key: 'abc123', api_secret: 'abc123456789')
92
+ ```
93
+
94
+ Generally though, and especially for production code or any code that you plan to push up to source control, you will want to avoid exposing your credentials directly in this way and instead use environment variables to define your credentials.
71
95
 
72
- For APIs which use a JWT for authentication you'll need to pass `application_id` and `private_key` arguments to the
73
- `Client` constructor as well as or instead of `api_key` and `api_secret`. See [JWT Authentication](#jwt-authentication).
96
+ > [!CAUTION]
97
+ > When setting environment variables locally, if using a file to do this (such as in an `.env` file), you should include the name of that file in a `.gitignore` file if you are intending to push your code up to source control.
74
98
 
75
- It is also possible to over-ride the default hosts at `Client` instantiation. See [Overriding the default hosts](overriding-the-default-hosts).
99
+ You can choose to define your own custom environment variables and then use Ruby's `ENV` hash to pass them in as the values for your keyword arguments, for example:
76
100
 
77
- ### JWT authentication
101
+ ```ruby
102
+ client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_API_SECRET'])
103
+ ```
78
104
 
79
- To call newer endpoints that support JWT authentication such as the Voice API and Messages API you'll
80
- also need to specify the `application_id` and `private_key` options. For example:
105
+ A less verbose approach is to instantiate the client *without* passing in keyword arguments for the authentication credentials.
81
106
 
82
107
  ```ruby
83
- client = Vonage::Client.new(application_id: application_id, private_key: private_key)
108
+ client = Vonage::Client.new
84
109
  ```
85
110
 
86
- Both arguments should have string values corresponding to the `id` and `private_key`
87
- values returned in a ["create an application"](https://developer.vonage.com/api/application.v2#createApplication)
88
- response. These credentials can be stored in a datastore, in environment variables,
89
- on disk outside of source control, or in some kind of key management infrastructure.
111
+ In this case the `Config` object used by the `Client` will search your environment for some pre-defined environment variables and use the values of those variables if defined. The names of these pre-defined environment variables are outlined in the sections below on the specific authentication methods.
112
+
113
+ Note that some Vonage API products support multiple authentication methods. In these cases the Ruby SDK sets a default authentication method for that product, which can be over-ridden with a configuration setting. You can learn more about this in the section on [Products with Multiple Authentication Methods](#products-with-multiple-authentication-methods).
114
+
115
+ #### Basic Authentication
116
+
117
+ For products that use Basic Authentication, the Ruby SDK sets an `Authorization` header on the HTTP request with a value containing a Base64 encoded version of your API key and secret. You can read more about this authentication method in the [Vonage documentation](https://developer.vonage.com/en/getting-started/concepts/authentication?source=getting-started#basic-authentication).
118
+
119
+ To set the header the SDK requires access to your API Key and API Secret. You can either:
120
+
121
+ 1. Pass them in to the `Client` constructor as `api_key` and `api_secret` keyword arguments, either passing in the values directly or as environement variables with custom keys:
122
+ ```ruby
123
+ client = Vonage::Client.new(api_key: 'abc123', api_secret: 'abc123456789')
124
+ ```
125
+ or
126
+ ```
127
+ # .env
128
+ MY_API_KEY=abc123
129
+ MY_API_SECRET=abc123456789
130
+ ```
131
+ ```ruby
132
+ client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_API_SECRET'])
133
+ ```
134
+
135
+ 2. Set them as environment variables with the `VONAGE_API_KEY` and `VONAGE_API_SECRET` keys and then call the constructor without the keyword arguments:
136
+ ```
137
+ # .env
138
+ VONAGE_API_KEY=abc123
139
+ VONAGE_API_SECRET=abc123456789
140
+ ```
141
+ ```ruby
142
+ client = Vonage::Client.new
143
+ ```
144
+
145
+ #### JWT Authentication
146
+
147
+ For products that use Bearer (JWT) Authentication, the Ruby SDK sets an `Authorization` header on the HTTP request with a value containing a JSON Web Token (JWT) derived from an Application ID and Private Key. You can read more about this authentication method in the [Vonage documentation](https://developer.vonage.com/en/getting-started/concepts/authentication#json-web-tokens), but in brief you will need to create a Vonage Application (for example via the [Vonage Developer Dashboard](https://dashboard.vonage.com/applications), [Application API](https://developer.vonage.com/en/application/overview), or [Vonage CLI](https://github.com/vonage/vonage-cli)). This Application will be assigned a unique ID upon creation. You can then generate a public and private key pair specific to this Application.
148
+
149
+ The Ruby SDK automatically generates the JWT and sets the `Authorization` header for you. To do this it requires access to an Application ID and assocaited Private Key. You can either:
150
+
151
+ 1. Pass them in to the `Client` constructor as `application_id` and `private_key` keyword arguments, either passing in the values directly or as environement variables with custom keys:
152
+ ```ruby
153
+ client = Vonage::Client.new(
154
+ application_id: '78d335fa-323d-0114-9c3d-d6f0d48968cf',
155
+ private_key: '-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........'
156
+ )
157
+ ```
158
+ or
159
+ ```
160
+ # .env
161
+ MY_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
162
+ MY_PRIVATE_KEY=-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........
163
+ ```
164
+ ```ruby
165
+ client = Vonage::Client.new(application_id: ENV['MY_APPLICATION_ID'], private_key: ENV['MY_PRIVATE_KEY'])
166
+ ```
167
+
168
+ 2. Set them as environment variables with the `VONAGE_APPLICATION_ID` and `VONAGE_PRIVATE_KEY` keys and then call the constructor without the keyword arguments:
169
+ ```
170
+ # .env
171
+ VONAGE_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
172
+ VONAGE_PRIVATE_KEY=-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........
173
+ ```
174
+ ```ruby
175
+ client = Vonage::Client.new
176
+ ```
177
+
178
+ ##### Using a Private Key File
179
+
180
+ Using the private key directly, whether to pass it in as a keyword argument or set it as an environment variable, can be a litle bit unweildy. Another option is to store it in a `.key` file and then read the contents of that file in as necessary.
181
+
182
+ > [!CAUTION]
183
+ > You should include the name of your Private Key file in a `.gitignore` file if you are intending to push your code up to source control.
90
184
 
91
- By default the library generates a short lived JWT per request. To generate a long lived
92
- JWT for multiple requests or to specify JWT claims directly use `Vonage::JWT.generate` and
93
- the token option. For example:
185
+ For example, if you had your private key stored in a file called `private.key` in the root directory of your Ruby application, you could:
186
+
187
+ 1. Read the contents of the file in using Ruby's `File.read` method when passing the `private_key` keyword argument to the `Client` constructor, either by passing the filepath directly or as an environement variables with a custom key:
188
+ ```ruby
189
+ client = Vonage::Client.new(
190
+ application_id: '78d335fa-323d-0114-9c3d-d6f0d48968cf',
191
+ private_key: File.read('/private.key)
192
+ )
193
+ ```
194
+ or
195
+ ```
196
+ # .env
197
+ MY_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
198
+ MY_PRIVATE_KEY_PATH=/private.key
199
+ ```
200
+ ```ruby
201
+ client = Vonage::Client.new(application_id: ENV['MY_APPLICATION_ID'], private_key: File.read(ENV['MY_PRIVATE_KEY_PATH']))
202
+ ```
203
+
204
+ 2. Set the path as an environment variable with the `VONAGE_PRIVATE_KEY_PATH` key (note: this is used in place of the `VONAGE_PRIVATE_KEY` key) and then call the constructor without the keyword arguments:
205
+ ```
206
+ # .env
207
+ VONAGE_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
208
+ VONAGE_PRIVATE_KEY_PATH=/private.key
209
+ ```
210
+ ```ruby
211
+ client = Vonage::Client.new
212
+ ```
213
+
214
+ If `VONAGE_PRIVATE_KEY_PATH` is set, then the Ruby SDK will attempt to read in the contents of the file at the path provided and use those contents as the Private Key.
215
+
216
+ > [!TIP]
217
+ > You can download your Private Key file when creating or updating a Vonage Application in the [Vonage Developer Dashboard](https://dashboard.vonage.com/applications), or creating a Vonage Application with the [Vonage CLI](https://github.com/vonage/vonage-cli). You can also create your own file using the value of the `keys.private_key` param provided in the HTTP response when creating a Vonage Application using the [Application API](https://developer.vonage.com/en/application/overview).
218
+
219
+ ##### Custom JWTs
220
+
221
+ By default the library generates a short lived JWT per request (the default `ttl` is `900` seconds). If you need to generate a long lived JWT for multiple requests or specify JWT claims directly use `Vonage::JWT.generate` to generate a custom JWT and then pass that in to the `Client` constructor using the `token` option. For example:
94
222
 
95
223
  ```ruby
96
224
  claims = {
97
- application_id: application_id,
98
- private_key: 'path/to/private.key',
225
+ application_id: ENV['VONAGE_APPLICATION_ID'],
226
+ private_key: File.read(ENV['VONAGE_PRIVATE_KEY_PATH']),
99
227
  nbf: 1483315200,
100
- ttl: 800
228
+ ttl: 3600
101
229
  }
102
230
 
103
231
  token = Vonage::JWT.generate(claims)
@@ -105,10 +233,100 @@ token = Vonage::JWT.generate(claims)
105
233
  client = Vonage::Client.new(token: token)
106
234
  ```
107
235
 
236
+ The `Client` object will then use the JWT that you passed in for any API requests rather than generating one on-the-fly for each request.
237
+
238
+ > [!NOTE]
239
+ > 1. Unlike with the `Client` constructor, you **must** set `application_id` and `private_key` as key-value pairs in the `claims` Hash when generating a custom JWT.
240
+ > 2. You can choose to set *either* `ttl` *or* `exp` in the `claims`:
241
+ > - If you set *both* `ttl` is ignored and `exp` is used
242
+ > - If you choose to set `exp` this must be set as the number of seconds since the UNIX epoch (if using `ttl` the generator calculates this for you)
243
+
108
244
  Documentation for the Vonage Ruby JWT generator gem can be found at: https://www.rubydoc.info/gems/vonage-jwt
109
245
 
110
246
  The documentation outlines all the possible parameters you can use to customize and build a token with.
111
247
 
248
+ #### Signature Authentication
249
+
250
+ Signature authentication signs the request using a signature created via a signing algorithm and using your Vonage Signature Secret. You can read more about this authentication method in the [Vonage documentation](https://developer.vonage.com/en/getting-started/concepts/signing-messages).
251
+
252
+ To create the signature the SDK requires access to your API Key and Signature Secret. You can either:
253
+
254
+ 1. Pass them in to the `Client` constructor as `api_key` and `signature_secret` keyword arguments, either passing in the values directly or as environement variables with custom keys:
255
+ ```ruby
256
+ client = Vonage::Client.new(api_key: 'abc123', signature_secret: 'hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71')
257
+ ```
258
+ or
259
+ ```
260
+ # .env
261
+ MY_API_KEY=abc123
262
+ MY_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
263
+ ```
264
+ ```ruby
265
+ client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_SIGNATURE_SECRET'])
266
+ ```
267
+
268
+ 2. Set them as environment variables with the `VONAGE_API_KEY` and `VONAGE_SIGNATURE_SECRET` keys and then call the constructor without the keyword arguments:
269
+ ```
270
+ # .env
271
+ VONAGE_API_KEY=abc123
272
+ VONAGE_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
273
+ ```
274
+ ```ruby
275
+ client = Vonage::Client.new
276
+ ```
277
+
278
+ By default, the Ruby SDK uses the MD5 HASH algorithm to generate the signature. If you've set a different algorithm in your [Vonage API Settings](https://dashboard.vonage.com/settings), you'll need to over-ride the default when instantiating the `Client` object, for example:
279
+
280
+ ```ruby
281
+ client = Vonage::Client.new(
282
+ api_key: 'abc123',
283
+ signature_secret: 'hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71',
284
+ signature_method: 'sha512'
285
+ )
286
+ ```
287
+
288
+ You can also set the Signature Method as the `VONAGE_SIGNATURE_METHOD` environment variable, for example:
289
+
290
+ ```
291
+ # .env
292
+ VONAGE_API_KEY=abc123
293
+ VONAGE_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
294
+ VONAGE_SIGNATURE_METHOD=sha512
295
+ ```
296
+ ```ruby
297
+ client = Vonage::Client.new
298
+ ```
299
+
300
+ Supported algorithms are:
301
+
302
+ - `md5hash`
303
+ - `md5` (HMAC)
304
+ - `sha1`
305
+ - `sha256`
306
+ - `sha512`
307
+
308
+ #### Products with Multiple Authentication Methods
309
+
310
+ Some Vonage API products support more than one authentication method. For these products the Ruby SDK sets a default authentication method, but this default can be over-ridden in the `Client` configuration using the `authentication_preference` setting. For example, the Messages API supports both Basic Authentication and Bearer Token (JWT) Authentication. For its Messages API implementation the Ruby SDK defaults to Bearer Token (JWT) Authentication and so you would normally need to provide a Vonage Application ID and Private Key as credentials in order to authenticate when using the Messages API via the Ruby SDK. However, you can instead provide your Vonage API Key and API Secret and set the `Client` object to use Basic Authentication instead:
311
+
312
+ ```
313
+ # .env
314
+ VONAGE_API_KEY=abc123
315
+ VONAGE_API_SECRET=abc123456789
316
+ ```
317
+
318
+ ```ruby
319
+ client = Vonage::Client.new(authentication_preference: :basic)
320
+ ```
321
+
322
+ Below is a list of Vonage API products currently implemented in the Ruby SDK that support more than one authentication method.
323
+
324
+ | Product | Authentication Methods | Default | Over-ride Key |
325
+ |---|---|---|---|
326
+ | Messages API | JWT, Basic | JWT | `:basic` |
327
+ | Verify API v2 | JWT, Basic | JWT | `:basic` |
328
+ | SMS API | Basic, Signature | Basic | `:signature` |
329
+
112
330
  ### Logging
113
331
 
114
332
  Use the logger option to specify a logger. For example:
@@ -721,6 +939,68 @@ response = client.voice.create({
721
939
  })
722
940
  ```
723
941
 
942
+ ## Identity Insights API
943
+
944
+ The [Vonage Identity Insights API](https://developer.vonage.com/en/identity-insights/overview) provides real-time access to a broad range of attributes related to the carrier, subscriber, or device associated with a phone number. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/identity-insights) listing all available insight types.
945
+
946
+ > [!NOTE]
947
+ > The Vonage Ruby SDK currently supports the following insight types:
948
+ > - Format
949
+ > - Current Carrier
950
+ > - Original Carrier
951
+ > - SIM Swap
952
+
953
+ Calling `identity_insights` on an instance of `Client` returns an `IdentityInsights` object which provides methods for interacting with the Identity Insights API.
954
+
955
+ ```ruby
956
+ client.identity_insights # => #<Vonage::IdentityInsights>
957
+ ```
958
+
959
+ ### Making an Insights Request
960
+
961
+ You can make an Identity Insights request by calling the `IdentityInsights#requests` method, for example:
962
+
963
+ ```ruby
964
+ response = client.identity_insights.requests(phone_number: '447900000000', insights: { format: {} })
965
+ ```
966
+
967
+ ### Using the Insights Builder
968
+
969
+ The `IdentityInsights` object implements a `insights_builder` method. This method returns an `InsightsBuilder` object:
970
+
971
+ ```ruby
972
+ insights_builder = client.identity_insights.insights_builder # => #<Vonage::IdentityInsights::InsightsBuilder @insights={}>
973
+ ```
974
+
975
+ You can then call various methods on the builder in order to add the insights that you require. Each of these methods returns the calling object, so the method invocations can be chained:
976
+
977
+ ```ruby
978
+ insights_builder.add_format.add_current_carrier
979
+ # => #<Vonage::IdentityInsights::InsightsBuilder @insights={:format=>{}, :current_carrier=>{}}>
980
+ ```
981
+
982
+ The builder object can be passed into the `IdentityInsights#requests` method invocation as the value of the `insights` keyword argument:
983
+
984
+ ```ruby
985
+ response = client.identity_insights.requests(phone_number: '447900000000', insights: insights_builder)
986
+ ```
987
+
988
+ ### Calling the Method with a Block
989
+
990
+ The `IdentityInsights#requests` method can also be called with a block. The method yields an `InsightsBuilder` object to the block and expects an `InsightsBuilder` object to be returned by the block.
991
+
992
+ ```ruby
993
+ response = client.identity_insights.requests(phone_number: '447900000000', purpose: "FraudPreventionAndDetection") do |builder|
994
+ builder.add_format
995
+ .add_original_carrier
996
+ .add_current_carrier
997
+ .add_sim_swap(period: 2400)
998
+ end
999
+ ```
1000
+
1001
+ > [!NOTE]
1002
+ > When requesting the SIM Swap insight, you should pass the `purpose` keyword argument to the `IdentityInsights#requests` method invocation with a value of `'FraudPreventionAndDetection'`.
1003
+
724
1004
  ## Documentation
725
1005
 
726
1006
  Vonage Ruby SDK documentation: https://www.rubydoc.info/gems/vonage
@@ -736,10 +1016,11 @@ The following is a list of Vonage APIs for which the Ruby SDK currently provides
736
1016
  * [Account API](https://developer.vonage.com/en/account/overview)
737
1017
  * [Application API](https://developer.vonage.com/en/application/overview)
738
1018
  * [Conversation API](https://developer.vonage.com/en/conversation/overview)
739
- * [Meetings API](https://developer.vonage.com/en/meetings/overview)
1019
+ * [Identity Insights API](https://developer.vonage.com/en/identity-insights/overview)
1020
+ * [Meetings API](https://developer.vonage.com/en/meetings/overview) (deprecated)
740
1021
  * [Messages API](https://developer.vonage.com/en/messages/overview)
741
- * [Network Number Verification API](https://developer.vonage.com/en/number-verification/overview)
742
- * [Network SIM Swap API](https://developer.vonage.com/en/sim-swap/overview)
1022
+ * [Network Number Verification API](https://developer.vonage.com/en/number-verification/overview) (deprecated)
1023
+ * [Network SIM Swap API](https://developer.vonage.com/en/sim-swap/overview) (deprecated)
743
1024
  * [Number Insight API](https://developer.vonage.com/en/number-insight/overview)
744
1025
  * [Numbers API](https://developer.vonage.com/en/numbers/overview)
745
1026
  * [Proactive Connect API](https://developer.vonage.com/en/proactive-connect/overview) *
@@ -0,0 +1,18 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class BasicAndBearerToken < AbstractAuthentication
6
+ def update(object, data)
7
+ return unless object.is_a?(Net::HTTPRequest)
8
+
9
+ if @config.authentication_preference == :basic
10
+ object.basic_auth(@config.api_key, @config.api_secret)
11
+ else
12
+ object['Authorization'] = 'Bearer ' + @config.token
13
+ end
14
+ end
15
+ end
16
+
17
+ private_constant :BasicAndBearerToken
18
+ end
@@ -18,5 +18,5 @@ module Vonage
18
18
  end
19
19
  end
20
20
 
21
- private_constant :Basic
21
+ private_constant :BasicAndSignature
22
22
  end
data/lib/vonage/client.rb CHANGED
@@ -70,6 +70,13 @@ module Vonage
70
70
  @files ||= T.let(Files.new(config), T.nilable(Vonage::Files))
71
71
  end
72
72
 
73
+ # @return [IdentityInsights]
74
+ #
75
+ sig { returns(T.nilable(Vonage::IdentityInsights)) }
76
+ def identity_insights
77
+ @identity_insights ||= T.let(IdentityInsights.new(config), T.nilable(Vonage::IdentityInsights))
78
+ end
79
+
73
80
  # @return [Meetings]
74
81
  # @deprecated
75
82
  sig { returns(T.nilable(Vonage::Meetings)) }
@@ -0,0 +1,75 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class IdentityInsights::InsightsBuilder
6
+ def initialize
7
+ @insights = {}
8
+ end
9
+
10
+ # Add a Format insight.
11
+ # @example
12
+ # builder = Vonage::IdentityInsights::InsightsBuilder.new
13
+ # builder.add_format
14
+ # @return [InsightsBuilder] The InsightsBuilder instance.
15
+ #
16
+ def add_format
17
+ @insights[:format] = {}
18
+ self
19
+ end
20
+
21
+ # Add a Sim Swap insight.
22
+ # @example
23
+ # builder = Vonage::IdentityInsights::InsightsBuilder.new
24
+ # builder.add_sim_swap(period: 180)
25
+ # @param period [Integer] The period for the sim swap insight.
26
+ # - Optional. If provided, must be between 1 and 2400.
27
+ # @return [InsightsBuilder] The InsightsBuilder instance.
28
+ #
29
+ def add_sim_swap(period: nil)
30
+ params = {}
31
+ if period
32
+ validate_sim_swap_period(period)
33
+ params[:period] = period
34
+ end
35
+ @insights[:sim_swap] = params
36
+ self
37
+ end
38
+
39
+ # Add a Current Carrier insight.
40
+ # @example
41
+ # builder = Vonage::IdentityInsights::InsightsBuilder.new
42
+ # builder.add_current_carrier
43
+ # @return [InsightsBuilder] The InsightsBuilder instance.
44
+ #
45
+ def add_current_carrier
46
+ @insights[:current_carrier] = {}
47
+ self
48
+ end
49
+
50
+ # Add an Original Carrier insight.
51
+ # @example
52
+ # builder = Vonage::IdentityInsights::InsightsBuilder.new
53
+ # builder.add_original_carrier
54
+ # @return [InsightsBuilder] The InsightsBuilder instance.
55
+ #
56
+ def add_original_carrier
57
+ @insights[:original_carrier] = {}
58
+ self
59
+ end
60
+
61
+ # Convert the InsightsBuilder to a Hash.
62
+ # @return [Hash] The insights as a Hash.
63
+ #
64
+ def to_h
65
+ @insights
66
+ end
67
+
68
+ private
69
+
70
+ def validate_sim_swap_period(period)
71
+ raise ArgumentError, 'Period must be an Integer' unless period.is_a?(Integer)
72
+ raise ArgumentError, 'Period must be between 1 and 2400' unless period.between?(1, 2400)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,75 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class IdentityInsights < Namespace
6
+ VALID_INSIGHT_TYPES = %i[format sim_swap original_carrier current_carrier].freeze
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.host = :vonage_host
11
+
12
+ self.request_body = JSON
13
+
14
+ # Submit an Identity Insights request.
15
+ # The SDK currently supports the following insight types: `format`, `sim_swap`, `current_carrier`, and `original_carrier`.
16
+ #
17
+ # @example with `insights` as a Hash
18
+ # response = client.identity_insights.requests(phone_number: '447900000000', insights: { format: {} })
19
+ #
20
+ # @example with `insights` as an InsightsBuilder
21
+ # insights = client.identity_insights.insights_builder.add_format.add_sim_swap(period: 180)
22
+ # response = client.identity_insights.requests(phone_number: '447900000000', insights: insights)
23
+ #
24
+ # @example with a block to build `insights`
25
+ # response = client.identity_insights.requests(phone_number: '447900000000') do |builder|
26
+ # builder.add_format
27
+ # builder.add_sim_swap(period: 180)
28
+ # end
29
+ #
30
+ # @option params [required, String] :phone_number The phone number to request insights for.
31
+ #
32
+ # @option params [String] :purpose The purpose for requesting the insights.
33
+ #
34
+ # @option params [Hash, InsightsBuilder] :insights
35
+ # A Hash or InsightsBuilder instance specifying the types of insights to request.
36
+ # See the Vonage developer documentation for any parameters supported by each insight type.
37
+ #
38
+ # for block {|builder| ... }
39
+ # @yield [builder] passes a InsightsBuilder instance to the block
40
+ # @yieldreturn [required, InsightsBuilder] expects the block to return a InsightsBuilder instance
41
+ #
42
+ # @return [Vonage::Response] The API response.
43
+ #
44
+ # @see https://developer.vonage.com/en/api/identity-insights#getInsights
45
+ #
46
+ def requests(phone_number:, insights: {}, **options)
47
+ insights = yield insights_builder if block_given?
48
+ validate_insights(insights)
49
+
50
+ params = {
51
+ phone_number: phone_number,
52
+ insights: insights.to_h
53
+ }.merge(options)
54
+
55
+ request('/identity-insights/v1/requests', params: params, type: Post)
56
+ end
57
+
58
+ # Instantiate an InsightsBuilder.
59
+ # @return [InsightsBuilder] A new InsightsBuilder instance.
60
+ #
61
+ def insights_builder
62
+ InsightsBuilder.new
63
+ end
64
+
65
+ private
66
+
67
+ def validate_insights(insights)
68
+ raise ArgumentError.new("`insights` must be a Hash or instance of InsightsBuilder") unless insights.is_a?(Hash) || insights.is_a?(InsightsBuilder)
69
+ raise ArgumentError.new("`insights` cannot be empty") if insights.to_h.empty?
70
+
71
+ invalid_insights = insights.to_h.keys - VALID_INSIGHT_TYPES
72
+ raise ArgumentError.new("`insights` contains the following invalid or unsupported insight types: #{invalid_insights.join(', ')}") unless invalid_insights.empty?
73
+ end
74
+ end
75
+ end
@@ -6,7 +6,7 @@ module Vonage
6
6
  class Messaging < Namespace
7
7
  extend Forwardable
8
8
 
9
- self.authentication = BearerToken
9
+ self.authentication = BasicAndBearerToken
10
10
 
11
11
  self.request_body = JSON
12
12
 
@@ -25,6 +25,7 @@ module Vonage
25
25
  @redirect_url = redirect_url
26
26
  end
27
27
 
28
+ # @deprecated: This method is deprecated and will be removed in a future release.
28
29
  def sandbox=(sandbox)
29
30
  raise ArgumentError, "Invalid 'sandbox' value #{sandbox}. Expected to be boolean value" unless [true, false].include? sandbox
30
31
  @sandbox = sandbox
@@ -24,6 +24,12 @@ module Vonage
24
24
  @from = from
25
25
  end
26
26
 
27
+ def mode=(mode)
28
+ valid_modes = ['otp_code', 'zero_tap']
29
+ raise ArgumentError, "Invalid 'mode' value #{mode}. Expected to be one of #{valid_modes.join(', ')}" unless valid_modes.include?(mode)
30
+ @mode = mode
31
+ end
32
+
27
33
  def to_h
28
34
  hash = Hash.new
29
35
  self.instance_variables.each do |ivar|
@@ -5,7 +5,7 @@ module Vonage
5
5
  class Verify2::TemplateFragments < Namespace
6
6
  CHANNELS = ['sms', 'voice'].freeze
7
7
 
8
- self.authentication = BearerToken
8
+ self.authentication = BasicAndBearerToken
9
9
 
10
10
  self.request_body = JSON
11
11
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Vonage
5
5
  class Verify2::Templates < Namespace
6
- self.authentication = BearerToken
6
+ self.authentication = BasicAndBearerToken
7
7
 
8
8
  self.request_body = JSON
9
9
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Vonage
5
5
  class Verify2 < Namespace
6
- self.authentication = BearerToken
6
+ self.authentication = BasicAndBearerToken
7
7
 
8
8
  self.request_body = JSON
9
9
 
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = '7.33.0'
4
+ VERSION = '7.35.0'
5
5
  end
@@ -37,7 +37,7 @@ module Vonage
37
37
  # - If you omit this property, all streams in the session will be included.
38
38
  # @option websocket [optional, Hash] :headers An object of key-value pairs of headers to be sent to your WebSocket server with each message, with a maximum length of 512 bytes.
39
39
  # @option websocket [optional, Integer] :audio_rate A number representing the audio sampling rate in Hz
40
- # - Must be one of: 8000, 16000
40
+ # - Must be one of: 8000, 16000, 24000
41
41
  # @option websocket [optional, Boolean] :bidirectional Whether to send audio data from the WebSocket connection to a stream published in the session.
42
42
  #
43
43
  # @return [Response]
@@ -153,6 +153,7 @@ module Vonage
153
153
  ncco[0].merge!(timeout: builder.timeout) if builder.timeout
154
154
  ncco[0].merge!(limit: builder.limit) if builder.limit
155
155
  ncco[0].merge!(machineDetection: builder.machineDetection) if builder.machineDetection
156
+ ncco[0].merge!(advanced_machine_detection: builder.advanced_machine_detection) if builder.advanced_machine_detection
156
157
  ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
157
158
  ncco[0].merge!(eventMethod: builder.eventMethod) if builder.eventMethod
158
159
  ncco[0].merge!(ringbackTone: builder.ringbackTone) if builder.ringbackTone
@@ -185,6 +186,7 @@ module Vonage
185
186
 
186
187
  hash.merge!(dtmfAnswer: endpoint_attrs[:dtmfAnswer]) if endpoint_attrs[:dtmfAnswer]
187
188
  hash.merge!(onAnswer: endpoint_attrs[:onAnswer]) if endpoint_attrs[:onAnswer]
189
+ hash.merge!(shaken: endpoint_attrs[:shaken]) if endpoint_attrs[:shaken]
188
190
 
189
191
  hash
190
192
  end
@@ -204,6 +206,7 @@ module Vonage
204
206
  }
205
207
 
206
208
  hash.merge!(headers: endpoint_attrs[:headers]) if endpoint_attrs[:headers]
209
+ hash.merge!(authorization: endpoint_attrs[:authorization]) if endpoint_attrs[:authorization]
207
210
 
208
211
  hash
209
212
  end
@@ -85,6 +85,13 @@ module Vonage
85
85
  if self.speech[:maxDuration]
86
86
  raise ClientError.new("Expected 'maxDuration' to not be more than 60 seconds") unless self.speech[:maxDuration] <= 60 && self.speech[:maxDuration] >= 0
87
87
  end
88
+
89
+ if self.speech[:provider]
90
+ valid_providers = ['google']
91
+
92
+ raise ClientError.new("Invalid 'provider' value, must be one of: #{valid_providers.join(', ')}") unless valid_providers.include?(self.speech[:provider])
93
+ raise ClientError.new("The `providerOptions` parameter is required when specifying a `provider`") unless self.speech[:providerOptions]
94
+ end
88
95
  end
89
96
 
90
97
  def validate_event_url
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
  module Vonage
4
4
  class Voice::Actions::Talk
5
- attr_accessor :text, :bargeIn, :loop, :level, :language, :style, :premium
5
+ attr_accessor :text, :bargeIn, :loop, :level, :language, :style, :premium, :provider, :providerOptions
6
6
 
7
7
  def initialize(attributes= {})
8
8
  @text = attributes.fetch(:text)
@@ -12,6 +12,8 @@ module Vonage
12
12
  @language = attributes.fetch(:language, nil)
13
13
  @style = attributes.fetch(:style, nil)
14
14
  @premium = attributes.fetch(:premium, nil)
15
+ @provider = attributes.fetch(:provider, nil)
16
+ @providerOptions = attributes.fetch(:providerOptions, nil)
15
17
 
16
18
  after_initialize!
17
19
  end
@@ -36,6 +38,10 @@ module Vonage
36
38
  if self.premium || self.premium == false
37
39
  verify_premium
38
40
  end
41
+
42
+ if self.provider
43
+ verify_provider
44
+ end
39
45
  end
40
46
 
41
47
  def verify_barge_in
@@ -58,6 +64,13 @@ module Vonage
58
64
  raise ClientError.new("Expected 'premium' value to be a Boolean") unless self.premium == true || self.premium == false
59
65
  end
60
66
 
67
+ def verify_provider
68
+ valid_providers = ['google']
69
+
70
+ raise ClientError.new("Invalid 'provider' value, must be one of: #{valid_providers.join(', ')}") unless valid_providers.include?(self.provider)
71
+ raise ClientError.new("The `providerOptions` parameter is required when specifying a `provider`") unless self.providerOptions
72
+ end
73
+
61
74
  def action
62
75
  create_talk!(self)
63
76
  end
@@ -75,7 +88,9 @@ module Vonage
75
88
  ncco[0].merge!(level: builder.level) if builder.level
76
89
  ncco[0].merge!(language: builder.language) if builder.language
77
90
  ncco[0].merge!(style: builder.style) if builder.style
78
- ncco[0].merge!(premium: builder.premium) if (builder.bargeIn || builder.bargeIn == false)
91
+ ncco[0].merge!(premium: builder.premium) if (builder.premium || builder.premium == false)
92
+ ncco[0].merge!(provider: builder.provider) if builder.provider
93
+ ncco[0].merge!(providerOptions: builder.providerOptions) if builder.providerOptions
79
94
 
80
95
  ncco
81
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vonage
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.33.0
4
+ version: 7.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vonage
@@ -137,6 +137,7 @@ files:
137
137
  - lib/vonage/applications/list_response.rb
138
138
  - lib/vonage/authentication_error.rb
139
139
  - lib/vonage/basic.rb
140
+ - lib/vonage/basic_and_bearer_token.rb
140
141
  - lib/vonage/basic_and_signature.rb
141
142
  - lib/vonage/bearer_token.rb
142
143
  - lib/vonage/client.rb
@@ -164,6 +165,8 @@ files:
164
165
  - lib/vonage/form_data.rb
165
166
  - lib/vonage/gsm7.rb
166
167
  - lib/vonage/http.rb
168
+ - lib/vonage/identity_insights.rb
169
+ - lib/vonage/identity_insights/insights_builder.rb
167
170
  - lib/vonage/json.rb
168
171
  - lib/vonage/jwt.rb
169
172
  - lib/vonage/key_secret_params.rb