vonage 7.33.0 → 7.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +304 -24
- data/lib/vonage/basic_and_bearer_token.rb +18 -0
- data/lib/vonage/basic_and_signature.rb +1 -1
- data/lib/vonage/client.rb +7 -0
- data/lib/vonage/identity_insights/insights_builder.rb +75 -0
- data/lib/vonage/identity_insights.rb +75 -0
- data/lib/vonage/messaging.rb +1 -1
- data/lib/vonage/verify2/channels/silent_auth.rb +1 -0
- data/lib/vonage/verify2/template_fragments.rb +1 -1
- data/lib/vonage/verify2/templates.rb +1 -1
- data/lib/vonage/verify2.rb +1 -1
- data/lib/vonage/version.rb +1 -1
- data/lib/vonage/voice/actions/connect.rb +2 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abee836fd492dfd3f67911f146aa67f9908e0e588c4346181792027dcdadf766
|
|
4
|
+
data.tar.gz: 41cde40bde80157f25db813173a6883b13a9212ba9c79ec18321d62474fd6380
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44fb7fc3f4165562ee599b9e56845b34687a2e0068e8e569ceaa4ae4c2215cd04561078904be22aef273836974a9a81c688e7404e0c557692b411c29526e2b73
|
|
7
|
+
data.tar.gz: 7fefb05eb9397b4927f5052d25df5e12f46a2b9be666ce52b0557119d34ce15040b951c4622dfc86c3373258a3a59f2a1433515853302b7daaa823e13695aea0
|
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)
|
|
@@ -56,7 +61,7 @@ require 'vonage'
|
|
|
56
61
|
Then construct a client object with your key and secret:
|
|
57
62
|
|
|
58
63
|
```ruby
|
|
59
|
-
client = Vonage::Client.new
|
|
64
|
+
client = Vonage::Client.new
|
|
60
65
|
```
|
|
61
66
|
|
|
62
67
|
You can now use the client object to call Vonage APIs. For example, to send an SMS:
|
|
@@ -65,39 +70,161 @@ You can now use the client object to call Vonage APIs. For example, to send an S
|
|
|
65
70
|
client.sms.send(from: 'Ruby', to: '447700900000', text: 'Hello world')
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
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).
|
|
74
|
+
|
|
75
|
+
### Authentication
|
|
76
|
+
|
|
77
|
+
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).
|
|
78
|
+
|
|
79
|
+
Currently, all Vonage API products support one or more of the following authentication methods:
|
|
80
|
+
|
|
81
|
+
- [Basic Authentication](#basic-authentication)
|
|
82
|
+
- [JWT Authentication](#jwt-authentication)
|
|
83
|
+
- [Signature Authentication](#signature-authentication)
|
|
84
|
+
|
|
85
|
+
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).
|
|
86
|
+
|
|
87
|
+
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:
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
client = Vonage::Client.new(api_key: 'abc123', api_secret: 'abc123456789')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
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
94
|
|
|
72
|
-
|
|
73
|
-
|
|
95
|
+
> [!CAUTION]
|
|
96
|
+
> 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
97
|
|
|
75
|
-
|
|
98
|
+
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
99
|
|
|
77
|
-
|
|
100
|
+
```ruby
|
|
101
|
+
client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_API_SECRET'])
|
|
102
|
+
```
|
|
78
103
|
|
|
79
|
-
|
|
80
|
-
also need to specify the `application_id` and `private_key` options. For example:
|
|
104
|
+
A less verbose approach is to instantiate the client *without* passing in keyword arguments for the authentication credentials.
|
|
81
105
|
|
|
82
106
|
```ruby
|
|
83
|
-
client = Vonage::Client.new
|
|
107
|
+
client = Vonage::Client.new
|
|
84
108
|
```
|
|
85
109
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
110
|
+
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.
|
|
111
|
+
|
|
112
|
+
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).
|
|
113
|
+
|
|
114
|
+
#### Basic Authentication
|
|
115
|
+
|
|
116
|
+
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).
|
|
117
|
+
|
|
118
|
+
To set the header the SDK requires access to your API Key and API Secret. You can either:
|
|
119
|
+
|
|
120
|
+
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:
|
|
121
|
+
```ruby
|
|
122
|
+
client = Vonage::Client.new(api_key: 'abc123', api_secret: 'abc123456789')
|
|
123
|
+
```
|
|
124
|
+
or
|
|
125
|
+
```
|
|
126
|
+
# .env
|
|
127
|
+
MY_API_KEY=abc123
|
|
128
|
+
MY_API_SECRET=abc123456789
|
|
129
|
+
```
|
|
130
|
+
```ruby
|
|
131
|
+
client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_API_SECRET'])
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
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:
|
|
135
|
+
```
|
|
136
|
+
# .env
|
|
137
|
+
VONAGE_API_KEY=abc123
|
|
138
|
+
VONAGE_API_SECRET=abc123456789
|
|
139
|
+
```
|
|
140
|
+
```ruby
|
|
141
|
+
client = Vonage::Client.new
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### JWT Authentication
|
|
145
|
+
|
|
146
|
+
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.
|
|
147
|
+
|
|
148
|
+
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:
|
|
149
|
+
|
|
150
|
+
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:
|
|
151
|
+
```ruby
|
|
152
|
+
client = Vonage::Client.new(
|
|
153
|
+
application_id: '78d335fa-323d-0114-9c3d-d6f0d48968cf',
|
|
154
|
+
private_key: '-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........'
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
or
|
|
158
|
+
```
|
|
159
|
+
# .env
|
|
160
|
+
MY_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
|
|
161
|
+
MY_PRIVATE_KEY=-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........
|
|
162
|
+
```
|
|
163
|
+
```ruby
|
|
164
|
+
client = Vonage::Client.new(application_id: ENV['MY_APPLICATION_ID'], private_key: ENV['MY_PRIVATE_KEY'])
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
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:
|
|
168
|
+
```
|
|
169
|
+
# .env
|
|
170
|
+
VONAGE_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
|
|
171
|
+
VONAGE_PRIVATE_KEY=-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFA........
|
|
172
|
+
```
|
|
173
|
+
```ruby
|
|
174
|
+
client = Vonage::Client.new
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
##### Using a Private Key File
|
|
178
|
+
|
|
179
|
+
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.
|
|
180
|
+
|
|
181
|
+
> [!CAUTION]
|
|
182
|
+
> 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
183
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
the
|
|
184
|
+
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:
|
|
185
|
+
|
|
186
|
+
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:
|
|
187
|
+
```ruby
|
|
188
|
+
client = Vonage::Client.new(
|
|
189
|
+
application_id: '78d335fa-323d-0114-9c3d-d6f0d48968cf',
|
|
190
|
+
private_key: File.read('/private.key)
|
|
191
|
+
)
|
|
192
|
+
```
|
|
193
|
+
or
|
|
194
|
+
```
|
|
195
|
+
# .env
|
|
196
|
+
MY_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
|
|
197
|
+
MY_PRIVATE_KEY_PATH=/private.key
|
|
198
|
+
```
|
|
199
|
+
```ruby
|
|
200
|
+
client = Vonage::Client.new(application_id: ENV['MY_APPLICATION_ID'], private_key: File.read(ENV['MY_PRIVATE_KEY_PATH']))
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
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:
|
|
204
|
+
```
|
|
205
|
+
# .env
|
|
206
|
+
VONAGE_APPLICATION_ID=78d335fa-323d-0114-9c3d-d6f0d48968cf
|
|
207
|
+
VONAGE_PRIVATE_KEY_PATH=/private.key
|
|
208
|
+
```
|
|
209
|
+
```ruby
|
|
210
|
+
client = Vonage::Client.new
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
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.
|
|
214
|
+
|
|
215
|
+
> [!TIP]
|
|
216
|
+
> 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).
|
|
217
|
+
|
|
218
|
+
##### Custom JWTs
|
|
219
|
+
|
|
220
|
+
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
221
|
|
|
95
222
|
```ruby
|
|
96
223
|
claims = {
|
|
97
|
-
application_id:
|
|
98
|
-
private_key:
|
|
224
|
+
application_id: ENV['VONAGE_APPLICATION_ID'],
|
|
225
|
+
private_key: File.read(ENV['VONAGE_PRIVATE_KEY_PATH']),
|
|
99
226
|
nbf: 1483315200,
|
|
100
|
-
ttl:
|
|
227
|
+
ttl: 3600
|
|
101
228
|
}
|
|
102
229
|
|
|
103
230
|
token = Vonage::JWT.generate(claims)
|
|
@@ -105,10 +232,100 @@ token = Vonage::JWT.generate(claims)
|
|
|
105
232
|
client = Vonage::Client.new(token: token)
|
|
106
233
|
```
|
|
107
234
|
|
|
235
|
+
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.
|
|
236
|
+
|
|
237
|
+
> [!NOTE]
|
|
238
|
+
> 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.
|
|
239
|
+
> 2. You can choose to set *either* `ttl` *or* `exp` in the `claims`:
|
|
240
|
+
> - If you set *both* `ttl` is ignored and `exp` is used
|
|
241
|
+
> - 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)
|
|
242
|
+
|
|
108
243
|
Documentation for the Vonage Ruby JWT generator gem can be found at: https://www.rubydoc.info/gems/vonage-jwt
|
|
109
244
|
|
|
110
245
|
The documentation outlines all the possible parameters you can use to customize and build a token with.
|
|
111
246
|
|
|
247
|
+
#### Signature Authentication
|
|
248
|
+
|
|
249
|
+
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).
|
|
250
|
+
|
|
251
|
+
To create the signature the SDK requires access to your API Key and Signature Secret. You can either:
|
|
252
|
+
|
|
253
|
+
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:
|
|
254
|
+
```ruby
|
|
255
|
+
client = Vonage::Client.new(api_key: 'abc123', signature_secret: 'hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71')
|
|
256
|
+
```
|
|
257
|
+
or
|
|
258
|
+
```
|
|
259
|
+
# .env
|
|
260
|
+
MY_API_KEY=abc123
|
|
261
|
+
MY_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
|
|
262
|
+
```
|
|
263
|
+
```ruby
|
|
264
|
+
client = Vonage::Client.new(api_key: ENV['MY_API_KEY'], api_secret: ENV['MY_SIGNATURE_SECRET'])
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
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:
|
|
268
|
+
```
|
|
269
|
+
# .env
|
|
270
|
+
VONAGE_API_KEY=abc123
|
|
271
|
+
VONAGE_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
|
|
272
|
+
```
|
|
273
|
+
```ruby
|
|
274
|
+
client = Vonage::Client.new
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
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:
|
|
278
|
+
|
|
279
|
+
```ruby
|
|
280
|
+
client = Vonage::Client.new(
|
|
281
|
+
api_key: 'abc123',
|
|
282
|
+
signature_secret: 'hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71',
|
|
283
|
+
signature_method: 'sha512'
|
|
284
|
+
)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
You can also set the Signature Method as the `VONAGE_SIGNATURE_METHOD` environment variable, for example:
|
|
288
|
+
|
|
289
|
+
```
|
|
290
|
+
# .env
|
|
291
|
+
VONAGE_API_KEY=abc123
|
|
292
|
+
VONAGE_SIGNATURE_SECRET=hdEooIhQYgo5XAcmbfLfpy5ROcEwGbjcwj6EvywwvYNOxKWj71
|
|
293
|
+
VONAGE_SIGNATURE_METHOD=sha512
|
|
294
|
+
```
|
|
295
|
+
```ruby
|
|
296
|
+
client = Vonage::Client.new
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Supported algorithms are:
|
|
300
|
+
|
|
301
|
+
- `md5hash`
|
|
302
|
+
- `md5` (HMAC)
|
|
303
|
+
- `sha1`
|
|
304
|
+
- `sha256`
|
|
305
|
+
- `sha512`
|
|
306
|
+
|
|
307
|
+
#### Products with Multiple Authentication Methods
|
|
308
|
+
|
|
309
|
+
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:
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
# .env
|
|
313
|
+
VONAGE_API_KEY=abc123
|
|
314
|
+
VONAGE_API_SECRET=abc123456789
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
```ruby
|
|
318
|
+
client = Vonage::Client.new(authentication_preference: :basic)
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Below is a list of Vonage API products currently implemented in the Ruby SDK that support more than one authentication method.
|
|
322
|
+
|
|
323
|
+
| Product | Authentication Methods | Default | Over-ride Key |
|
|
324
|
+
|---|---|---|---|
|
|
325
|
+
| Messages API | JWT, Basic | JWT | `:basic` |
|
|
326
|
+
| Verify API v2 | JWT, Basic | JWT | `:basic` |
|
|
327
|
+
| SMS API | Basic, Signature | Basic | `:signature` |
|
|
328
|
+
|
|
112
329
|
### Logging
|
|
113
330
|
|
|
114
331
|
Use the logger option to specify a logger. For example:
|
|
@@ -721,6 +938,68 @@ response = client.voice.create({
|
|
|
721
938
|
})
|
|
722
939
|
```
|
|
723
940
|
|
|
941
|
+
## Identity Insights API
|
|
942
|
+
|
|
943
|
+
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.
|
|
944
|
+
|
|
945
|
+
> [!NOTE]
|
|
946
|
+
> The Vonage Ruby SDK currently supports the following insight types:
|
|
947
|
+
> - Format
|
|
948
|
+
> - Current Carrier
|
|
949
|
+
> - Original Carrier
|
|
950
|
+
> - SIM Swap
|
|
951
|
+
|
|
952
|
+
Calling `identity_insights` on an instance of `Client` returns an `IdentityInsights` object which provides methods for interacting with the Identity Insights API.
|
|
953
|
+
|
|
954
|
+
```ruby
|
|
955
|
+
client.identity_insights # => #<Vonage::IdentityInsights>
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
### Making an Insights Request
|
|
959
|
+
|
|
960
|
+
You can make an Identity Insights request by calling the `IdentityInsights#requests` method, for example:
|
|
961
|
+
|
|
962
|
+
```ruby
|
|
963
|
+
response = client.identity_insights.requests(phone_number: '447900000000', insights: { format: {} })
|
|
964
|
+
```
|
|
965
|
+
|
|
966
|
+
### Using the Insights Builder
|
|
967
|
+
|
|
968
|
+
The `IdentityInsights` object implements a `insights_builder` method. This method returns an `InsightsBuilder` object:
|
|
969
|
+
|
|
970
|
+
```ruby
|
|
971
|
+
insights_builder = client.identity_insights.insights_builder # => #<Vonage::IdentityInsights::InsightsBuilder @insights={}>
|
|
972
|
+
```
|
|
973
|
+
|
|
974
|
+
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:
|
|
975
|
+
|
|
976
|
+
```ruby
|
|
977
|
+
insights_builder.add_format.add_current_carrier
|
|
978
|
+
# => #<Vonage::IdentityInsights::InsightsBuilder @insights={:format=>{}, :current_carrier=>{}}>
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
The builder object can be passed into the `IdentityInsights#requests` method invocation as the value of the `insights` keyword argument:
|
|
982
|
+
|
|
983
|
+
```ruby
|
|
984
|
+
response = client.identity_insights.requests(phone_number: '447900000000', insights: insights_builder)
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
### Calling the Method with a Block
|
|
988
|
+
|
|
989
|
+
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.
|
|
990
|
+
|
|
991
|
+
```ruby
|
|
992
|
+
response = client.identity_insights.requests(phone_number: '447900000000', purpose: "FraudPreventionAndDetection") do |builder|
|
|
993
|
+
builder.add_format
|
|
994
|
+
.add_original_carrier
|
|
995
|
+
.add_current_carrier
|
|
996
|
+
.add_sim_swap(period: 2400)
|
|
997
|
+
end
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
> [!NOTE]
|
|
1001
|
+
> When requesting the SIM Swap insight, you should pass the `purpose` keyword argument to the `IdentityInsights#requests` method invocation with a value of `'FraudPreventionAndDetection'`.
|
|
1002
|
+
|
|
724
1003
|
## Documentation
|
|
725
1004
|
|
|
726
1005
|
Vonage Ruby SDK documentation: https://www.rubydoc.info/gems/vonage
|
|
@@ -736,10 +1015,11 @@ The following is a list of Vonage APIs for which the Ruby SDK currently provides
|
|
|
736
1015
|
* [Account API](https://developer.vonage.com/en/account/overview)
|
|
737
1016
|
* [Application API](https://developer.vonage.com/en/application/overview)
|
|
738
1017
|
* [Conversation API](https://developer.vonage.com/en/conversation/overview)
|
|
739
|
-
* [
|
|
1018
|
+
* [Identity Insights API](https://developer.vonage.com/en/identity-insights/overview)
|
|
1019
|
+
* [Meetings API](https://developer.vonage.com/en/meetings/overview) (deprecated)
|
|
740
1020
|
* [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)
|
|
1021
|
+
* [Network Number Verification API](https://developer.vonage.com/en/number-verification/overview) (deprecated)
|
|
1022
|
+
* [Network SIM Swap API](https://developer.vonage.com/en/sim-swap/overview) (deprecated)
|
|
743
1023
|
* [Number Insight API](https://developer.vonage.com/en/number-insight/overview)
|
|
744
1024
|
* [Numbers API](https://developer.vonage.com/en/numbers/overview)
|
|
745
1025
|
* [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
|
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
|
data/lib/vonage/messaging.rb
CHANGED
|
@@ -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
|
data/lib/vonage/verify2.rb
CHANGED
data/lib/vonage/version.rb
CHANGED
|
@@ -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
|
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.
|
|
4
|
+
version: 7.34.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
|