vonage 7.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +190 -0
  3. data/README.md +191 -0
  4. data/lib/vonage.rb +29 -0
  5. data/lib/vonage/abstract_authentication.rb +9 -0
  6. data/lib/vonage/account.rb +61 -0
  7. data/lib/vonage/alerts.rb +72 -0
  8. data/lib/vonage/applications.rb +148 -0
  9. data/lib/vonage/applications/list_response.rb +11 -0
  10. data/lib/vonage/authentication_error.rb +6 -0
  11. data/lib/vonage/basic.rb +13 -0
  12. data/lib/vonage/bearer_token.rb +14 -0
  13. data/lib/vonage/client.rb +134 -0
  14. data/lib/vonage/client_error.rb +6 -0
  15. data/lib/vonage/config.rb +208 -0
  16. data/lib/vonage/conversations.rb +210 -0
  17. data/lib/vonage/conversations/events.rb +73 -0
  18. data/lib/vonage/conversations/legs.rb +30 -0
  19. data/lib/vonage/conversations/members.rb +104 -0
  20. data/lib/vonage/conversations/users.rb +93 -0
  21. data/lib/vonage/conversions.rb +19 -0
  22. data/lib/vonage/entity.rb +51 -0
  23. data/lib/vonage/error.rb +6 -0
  24. data/lib/vonage/errors.rb +51 -0
  25. data/lib/vonage/files.rb +26 -0
  26. data/lib/vonage/form_data.rb +11 -0
  27. data/lib/vonage/gsm7.rb +13 -0
  28. data/lib/vonage/http.rb +43 -0
  29. data/lib/vonage/json.rb +17 -0
  30. data/lib/vonage/jwt.rb +43 -0
  31. data/lib/vonage/key_secret_params.rb +20 -0
  32. data/lib/vonage/keys.rb +51 -0
  33. data/lib/vonage/logger.rb +60 -0
  34. data/lib/vonage/messages.rb +25 -0
  35. data/lib/vonage/namespace.rb +118 -0
  36. data/lib/vonage/number_insight.rb +140 -0
  37. data/lib/vonage/numbers.rb +196 -0
  38. data/lib/vonage/numbers/list_response.rb +11 -0
  39. data/lib/vonage/numbers/response.rb +8 -0
  40. data/lib/vonage/params.rb +27 -0
  41. data/lib/vonage/pricing.rb +30 -0
  42. data/lib/vonage/pricing_types.rb +18 -0
  43. data/lib/vonage/redact.rb +37 -0
  44. data/lib/vonage/response.rb +25 -0
  45. data/lib/vonage/secrets.rb +85 -0
  46. data/lib/vonage/secrets/list_response.rb +11 -0
  47. data/lib/vonage/server_error.rb +6 -0
  48. data/lib/vonage/signature.rb +53 -0
  49. data/lib/vonage/sms.rb +121 -0
  50. data/lib/vonage/tfa.rb +14 -0
  51. data/lib/vonage/user_agent.rb +16 -0
  52. data/lib/vonage/verify.rb +253 -0
  53. data/lib/vonage/version.rb +5 -0
  54. data/lib/vonage/voice.rb +250 -0
  55. data/lib/vonage/voice/dtmf.rb +26 -0
  56. data/lib/vonage/voice/list_response.rb +11 -0
  57. data/lib/vonage/voice/stream.rb +44 -0
  58. data/lib/vonage/voice/talk.rb +48 -0
  59. data/vonage.gemspec +26 -0
  60. metadata +155 -0
@@ -0,0 +1,14 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class TFA < Namespace
6
+ include Keys
7
+
8
+ self.host = :rest_host
9
+
10
+ def send(params)
11
+ request('/sc/us/2fa/json', params: hyphenate(params), type: Post)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # typed: ignore
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ module UserAgent
6
+ def self.string(app_name, app_version)
7
+ identifiers = []
8
+ identifiers << 'vonage-ruby/' + VERSION
9
+ identifiers << 'ruby/' + RUBY_VERSION
10
+ identifiers << app_name + '/' + app_version if app_name && app_version
11
+ identifiers.join(' ')
12
+ end
13
+ end
14
+
15
+ private_constant :UserAgent
16
+ end
@@ -0,0 +1,253 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Verify < Namespace
6
+ extend T::Sig
7
+ alias_method :http_request, :request
8
+
9
+ private :http_request
10
+
11
+ # Generate and send a PIN to your user.
12
+ #
13
+ # @note You can make a maximum of one Verify request per second.
14
+ #
15
+ # @example
16
+ # response = client.verify.request(number: '447700900000', brand: 'Acme Inc')
17
+ #
18
+ # puts "Started verification request_id=#{response.request_id}"
19
+ #
20
+ # @option params [required, String] :number
21
+ # The mobile or landline phone number to verify.
22
+ # Unless you are setting **:country** explicitly, this number must be in E.164 format.
23
+ #
24
+ # @option params [String] :country
25
+ # If you do not provide **:number** in international format or you are not sure if **:number** is correctly formatted, specify the two-character country code in **:country**.
26
+ # Verify will then format the number for you.
27
+ #
28
+ # @option params [required, String] :brand
29
+ # An 18-character alphanumeric string you can use to personalize the verification request SMS body, to help users identify your company or application name.
30
+ # For example: "Your `Acme Inc` PIN is ..."
31
+ #
32
+ # @option params [String] :sender_id
33
+ # An 11-character alphanumeric string that represents the [identity of the sender](https://developer.nexmo.com/messaging/sms/guides/custom-sender-id) of the verification request.
34
+ # Depending on the destination of the phone number you are sending the verification SMS to, restrictions might apply.
35
+ #
36
+ # @option params [Integer] :code_length
37
+ # The length of the verification code.
38
+ #
39
+ # @option params [String] :lg
40
+ # By default, the SMS or text-to-speech (TTS) message is generated in the locale that matches the **:number**.
41
+ # For example, the text message or TTS message for a `33*` number is sent in French.
42
+ # Use this parameter to explicitly control the language, accent and gender used for the Verify request.
43
+ #
44
+ # @option params [Integer] :pin_expiry
45
+ # How log the generated verification code is valid for, in seconds.
46
+ # When you specify both **:pin_expiry** and **:next_event_wait** then **:pin_expiry** must be an integer multiple of **:next_event_wait** otherwise **:pin_expiry** is defaulted to equal **:next_event_wait**.
47
+ # See [changing the event timings](https://developer.nexmo.com/verify/guides/changing-default-timings).
48
+ #
49
+ # @option params [Integer] :next_event_wait
50
+ # Specifies the wait time in seconds between attempts to deliver the verification code.
51
+ #
52
+ # @option params [Integer] :workflow_id
53
+ # Selects the predefined sequence of SMS and TTS (Text To Speech) actions to use in order to convey the PIN to your user.
54
+ # For example, an id of 1 identifies the workflow SMS - TTS - TTS.
55
+ # For a list of all workflows and their associated ids, please visit the [developer portal](https://developer.nexmo.com/verify/guides/workflows-and-events).
56
+ #
57
+ # @param [Hash] params
58
+ #
59
+ # @return [Response]
60
+ #
61
+ # @see https://developer.nexmo.com/api/verify#verifyRequest
62
+ #
63
+ sig { params(params: T.untyped, uri: T.untyped).returns(T.untyped) }
64
+ def request(params, uri = '/verify/json')
65
+ response = http_request(uri, params: params, type: Post)
66
+
67
+ raise Error, response[:error_text] if error?(response)
68
+
69
+ response
70
+ end
71
+
72
+ # Confirm that the PIN you received from your user matches the one sent by Vonage in your verification request.
73
+ #
74
+ # @example
75
+ # response = client.verify.check(request_id: request_id, code: '1234')
76
+ #
77
+ # puts "Verification complete, event_id=#{response.event_id}"
78
+ #
79
+ # @option params [required, String] :request_id
80
+ # The Verify request to check.
81
+ # This is the `request_id` you received in the response to the Verify request.
82
+ #
83
+ # @option params [required, String] :code
84
+ # The verification code entered by your user.
85
+ #
86
+ # @option params [String] :ip_address
87
+ # The IP address used by your user when they entered the verification code.
88
+ # Vonage uses this information to identify fraud and spam. This ultimately benefits all Vonage customers.
89
+ #
90
+ # @param [Hash] params
91
+ #
92
+ # @return [Response]
93
+ #
94
+ # @see https://developer.nexmo.com/api/verify#verifyCheck
95
+ #
96
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(Vonage::Response) }
97
+ def check(params)
98
+ response = http_request('/verify/check/json', params: params, type: Post)
99
+
100
+ raise Error, response[:error_text] if error?(response)
101
+
102
+ response
103
+ end
104
+
105
+ # Check the status of past or current verification requests.
106
+ #
107
+ # @example
108
+ # response = client.verify.search(request_id: request_id)
109
+ #
110
+ # @option params [String] :request_id
111
+ # The `request_id` you received in the Verify Request Response.
112
+ #
113
+ # @option params [Array<string>] :request_ids
114
+ # More than one `request_id`.
115
+ # Each `request_id` is a new parameter in the Verify Search request.
116
+ #
117
+ # @param [Hash] params
118
+ #
119
+ # @return [Response]
120
+ #
121
+ # @see https://developer.nexmo.com/api/verify#verifySearch
122
+ #
123
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.any(T::Hash[Symbol, T.untyped], Vonage::Response)) }
124
+ def search(params)
125
+ response = http_request('/verify/search/json', params: params)
126
+
127
+ raise Error, response[:error_text] if error?(response)
128
+
129
+ response
130
+ end
131
+
132
+ # Control the progress of your verification requests.
133
+ #
134
+ # @example
135
+ # response = client.verify.control(request_id: request_id, cmd: 'cancel')
136
+ #
137
+ # @option params [required, String] :request_id
138
+ # The `request_id` you received in the response to the Verify request.
139
+ #
140
+ # @option params [required, String] :cmd
141
+ # The command to execute, depending on whether you want to cancel the verification process, or advance to the next verification event.
142
+ # You must wait at least 30 seconds before cancelling a Verify request.
143
+ #
144
+ # @param [Hash] params
145
+ #
146
+ # @return [Response]
147
+ #
148
+ # @see https://developer.nexmo.com/api/verify#verifyControl
149
+ #
150
+ sig { params(params: T::Hash[Symbol, T.untyped]).returns(T.untyped) }
151
+ def control(params)
152
+ response = http_request('/verify/control/json', params: params, type: Post)
153
+
154
+ raise Error, response[:error_text] if error?(response)
155
+
156
+ response
157
+ end
158
+
159
+ # Cancel an existing verification request.
160
+ #
161
+ # @example
162
+ # response = client.verify.cancel(request_id)
163
+ #
164
+ # @param [String] id
165
+ #
166
+ # @return [Response]
167
+ #
168
+ # @see https://developer.nexmo.com/api/verify#verifyControl
169
+ #
170
+ sig { params(id: String).returns(Vonage::Response) }
171
+ def cancel(id)
172
+ control(request_id: id, cmd: 'cancel')
173
+ end
174
+
175
+ # Trigger the next verification event for an existing verification request.
176
+ #
177
+ # @example
178
+ # response = client.verify.trigger_next_event(request_id)
179
+ #
180
+ # @param [String] id
181
+ #
182
+ # @return [Response]
183
+ #
184
+ # @see https://developer.nexmo.com/api/verify#verifyControl
185
+ #
186
+ sig { params(id: String).returns(Vonage::Response) }
187
+ def trigger_next_event(id)
188
+ control(request_id: id, cmd: 'trigger_next_event')
189
+ end
190
+
191
+ # Send a PSD2-compliant payment token to a user for payment authorization
192
+ #
193
+ # @example
194
+ # response = client.verify.psd2(number: '447700900000', payee: 'Acme Inc', amount: 48.00)
195
+ #
196
+ # @option params [required, String] :number
197
+ # The mobile or landline phone number to verify.
198
+ # Unless you are setting **:country** explicitly, this number must be in E.164 format.
199
+ #
200
+ # @option params [String] :country
201
+ # If you do not provide **:number** in international format or you are not sure if **:number** is correctly formatted, specify the two-character country code in **:country**.
202
+ # Verify will then format the number for you.
203
+ #
204
+ # @option params [required, String] :payee
205
+ # An alphanumeric string to indicate to the user the name of the recipient that they are confirming a payment to.
206
+ #
207
+ # @option params [required, Float] :amount
208
+ # The decimal amount of the payment to be confirmed, in Euros
209
+ #
210
+ # @option params [Integer] :code_length
211
+ # The length of the verification code.
212
+ #
213
+ # @option params [String] :lg
214
+ # By default, the SMS or text-to-speech (TTS) message is generated in the locale that matches the **:number**.
215
+ # For example, the text message or TTS message for a `33*` number is sent in French.
216
+ # Use this parameter to explicitly control the language, accent and gender used for the Verify request.
217
+ #
218
+ # @option params [Integer] :pin_expiry
219
+ # How log the generated verification code is valid for, in seconds.
220
+ # When you specify both **:pin_expiry** and **:next_event_wait** then **:pin_expiry** must be an integer multiple of **:next_event_wait** otherwise **:pin_expiry** is defaulted to equal **:next_event_wait**.
221
+ # See [changing the event timings](https://developer.nexmo.com/verify/guides/changing-default-timings).
222
+ #
223
+ # @option params [Integer] :next_event_wait
224
+ # Specifies the wait time in seconds between attempts to deliver the verification code.
225
+ #
226
+ # @option params [Integer] :workflow_id
227
+ # Selects the predefined sequence of SMS and TTS (Text To Speech) actions to use in order to convey the PIN to your user.
228
+ # For example, an id of 1 identifies the workflow SMS - TTS - TTS.
229
+ # For a list of all workflows and their associated ids, please visit the [developer portal](https://developer.nexmo.com/verify/guides/workflows-and-events).
230
+ #
231
+ # @param [Hash] params
232
+ #
233
+ # @return [Response]
234
+ #
235
+ # @see https://developer.nexmo.com/api/verify#verifyRequestWithPSD2
236
+ #
237
+ sig { params(params: T.untyped, uri: T.untyped).returns(T.any(Vonage::Error, Vonage::Response)) }
238
+ def psd2(params, uri = '/verify/psd2/json')
239
+ response = http_request(uri, params: params, type: Post)
240
+
241
+ raise Error, response[:error_text] if error?(response)
242
+
243
+ response
244
+ end
245
+
246
+ private
247
+
248
+ sig { params(response: T.untyped).returns(T::Boolean) }
249
+ def error?(response)
250
+ response.respond_to?(:error_text)
251
+ end
252
+ end
253
+ end
@@ -0,0 +1,5 @@
1
+ # typed: strong
2
+
3
+ module Vonage
4
+ VERSION = '7.2.0'
5
+ end
@@ -0,0 +1,250 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Voice < Namespace
6
+ self.authentication = BearerToken
7
+
8
+ self.request_body = JSON
9
+
10
+ # Create an outbound Call.
11
+ #
12
+ # @example
13
+ # response = client.voice.create({
14
+ # to: [{type: 'phone', number: '14843331234'}],
15
+ # from: {type: 'phone', number: '14843335555'},
16
+ # answer_url: ['https://example.com/answer']
17
+ # })
18
+ #
19
+ # @option params [required, Array<Hash>] :to
20
+ # Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.
21
+ #
22
+ # @option params [required, Hash] :from
23
+ # Connect to a Phone (PSTN) number.
24
+ #
25
+ # @option params [Array<String>] :ncco
26
+ # The Vonage Call Control Object to use for this call.
27
+ # Required unless **:answer_url** is provided.
28
+ #
29
+ # @option params [Array<String>] :answer_url
30
+ # The webhook endpoint where you provide the Vonage Call Control Object that governs this call.
31
+ # Required unless **:ncco** is provided.
32
+ #
33
+ # @option params [String] :answer_method
34
+ # The HTTP method used to send event information to answer_url.
35
+ #
36
+ # @option params [required, Array<String>] :event_url
37
+ # The webhook endpoint where call progress events are sent to.
38
+ #
39
+ # @option params [String] :event_method
40
+ # The HTTP method used to send event information to event_url.
41
+ #
42
+ # @option params [String] :machine_detection
43
+ # Configure the behavior when Vonage detects that the call is answered by voicemail.
44
+ #
45
+ # @option params [Integer] :length_timer
46
+ # Set the number of seconds that elapse before Vonage hangs up after the call state changes to in_progress.
47
+ #
48
+ # @option params [Integer] :ringing_timer
49
+ # Set the number of seconds that elapse before Vonage hangs up after the call state changes to `ringing`.
50
+ #
51
+ # @param [Hash] params
52
+ #
53
+ # @return [Response]
54
+ #
55
+ # @see https://developer.nexmo.com/api/voice#createCall
56
+ #
57
+ def create(params)
58
+ request('/v1/calls', params: params, type: Post)
59
+ end
60
+
61
+ # Get details of your calls.
62
+ #
63
+ # @example
64
+ # response = client.voice.list
65
+ # response.each do |item|
66
+ # puts "#{item.uuid} #{item.direction} #{item.status}"
67
+ # end
68
+ #
69
+ # @option params [String] :status
70
+ # Filter by call status.
71
+ #
72
+ # @option params [String] :date_start
73
+ # Return the records that occurred after this point in time.
74
+ #
75
+ # @option params [String] :date_end
76
+ # Return the records that occurred before this point in time.
77
+ #
78
+ # @option params [Integer] :page_size
79
+ # Return this amount of records in the response.
80
+ #
81
+ # @option params [Integer] :record_index
82
+ # Return calls from this index in the response.
83
+ #
84
+ # @option params [String] :order
85
+ # Either `ascending` or `descending` order.
86
+ #
87
+ # @option params [String] :conversation_uuid
88
+ # Return all the records associated with a specific conversation.
89
+ #
90
+ # @param [Hash] params
91
+ #
92
+ # @return [ListResponse]
93
+ #
94
+ # @see https://developer.nexmo.com/api/voice#getCalls
95
+ #
96
+ def list(params = nil)
97
+ request('/v1/calls', params: params, response_class: ListResponse)
98
+ end
99
+
100
+ # Get detail of a specific call.
101
+ #
102
+ # @example
103
+ # response = client.voice.get(id)
104
+ #
105
+ # @param [String] id
106
+ #
107
+ # @return [Response]
108
+ #
109
+ # @see https://developer.nexmo.com/api/voice#getCall
110
+ #
111
+ def get(id)
112
+ request('/v1/calls/' + id)
113
+ end
114
+
115
+ # Modify an in progress call.
116
+ #
117
+ # @example
118
+ # response = client.voice.update(id, action: 'hangup')
119
+ #
120
+ # @option params [required, String] :action
121
+ #
122
+ # @option params [Hash] :destination
123
+ # Required when **:action** is `transfer`.
124
+ #
125
+ # @param [String] id
126
+ # @param [Hash] params
127
+ #
128
+ # @return [Response]
129
+ #
130
+ # @see https://developer.nexmo.com/api/voice#updateCall
131
+ #
132
+ def update(id, params)
133
+ request('/v1/calls/' + id, params: params, type: Put)
134
+ end
135
+
136
+ # Hangup an in progress call.
137
+ #
138
+ # @example
139
+ # response = client.voice.hangup(id)
140
+ #
141
+ # @param [String] id
142
+ #
143
+ # @return [Response]
144
+ #
145
+ # @see https://developer.nexmo.com/api/voice#updateCall
146
+ #
147
+ def hangup(id)
148
+ update(id, action: 'hangup')
149
+ end
150
+
151
+ # Mute an in progress call.
152
+ #
153
+ # @example
154
+ # response = client.voice.mute(id)
155
+ #
156
+ # @param [String] id
157
+ #
158
+ # @return [Response]
159
+ #
160
+ # @see https://developer.nexmo.com/api/voice#updateCall
161
+ #
162
+ def mute(id)
163
+ update(id, action: 'mute')
164
+ end
165
+
166
+ # Unmute an in progress call.
167
+ #
168
+ # @example
169
+ # response = client.voice.unmute(id)
170
+ #
171
+ # @param [String] id
172
+ #
173
+ # @return [Response]
174
+ #
175
+ # @see https://developer.nexmo.com/api/voice#updateCall
176
+ #
177
+ def unmute(id)
178
+ update(id, action: 'unmute')
179
+ end
180
+
181
+ # Earmuff an in progress call.
182
+ #
183
+ # @example
184
+ # response = client.voice.earmuff(id)
185
+ #
186
+ # @param [String] id
187
+ #
188
+ # @return [Response]
189
+ #
190
+ # @see https://developer.nexmo.com/api/voice#updateCall
191
+ #
192
+ def earmuff(id)
193
+ update(id, action: 'earmuff')
194
+ end
195
+
196
+ # Unearmuff an in progress call.
197
+ #
198
+ # @example
199
+ # response = client.voice.unearmuff(id)
200
+ #
201
+ # @param [String] id
202
+ #
203
+ # @return [Response]
204
+ #
205
+ # @see https://developer.nexmo.com/api/voice#updateCall
206
+ #
207
+ def unearmuff(id)
208
+ update(id, action: 'unearmuff')
209
+ end
210
+
211
+ # Transfer an in progress call.
212
+ #
213
+ # @example
214
+ # destination = {
215
+ # type: 'ncco',
216
+ # url: ['https://example.com/ncco.json']
217
+ # }
218
+ #
219
+ # response = client.voice.transfer(id, destination: destination)
220
+ #
221
+ # @param [String] id
222
+ # @param [Hash] destination
223
+ #
224
+ # @return [Response]
225
+ #
226
+ # @see https://developer.nexmo.com/api/voice#updateCall
227
+ #
228
+ def transfer(id, destination:)
229
+ update(id, action: 'transfer', destination: destination)
230
+ end
231
+
232
+ # @return [Stream]
233
+ #
234
+ def stream
235
+ @stream ||= Stream.new(@config)
236
+ end
237
+
238
+ # @return [Talk]
239
+ #
240
+ def talk
241
+ @talk ||= Talk.new(@config)
242
+ end
243
+
244
+ # @return [DTMF]
245
+ #
246
+ def dtmf
247
+ @dtmf ||= DTMF.new(@config)
248
+ end
249
+ end
250
+ end