nexmo 5.8.0 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/nexmo.rb +1 -1
  4. data/lib/nexmo/account.rb +36 -1
  5. data/lib/nexmo/alerts.rb +46 -0
  6. data/lib/nexmo/applications.rb +118 -0
  7. data/lib/nexmo/applications_v2.rb +71 -0
  8. data/lib/nexmo/authentication/abstract.rb +3 -1
  9. data/lib/nexmo/authentication/basic.rb +3 -1
  10. data/lib/nexmo/authentication/bearer_token.rb +3 -1
  11. data/lib/nexmo/authentication/key_secret_params.rb +3 -1
  12. data/lib/nexmo/authentication/key_secret_query.rb +3 -1
  13. data/lib/nexmo/call_dtmf.rb +12 -0
  14. data/lib/nexmo/call_stream.rb +26 -0
  15. data/lib/nexmo/call_talk.rb +30 -0
  16. data/lib/nexmo/calls.rb +188 -0
  17. data/lib/nexmo/client.rb +77 -1
  18. data/lib/nexmo/conversation_events.rb +47 -0
  19. data/lib/nexmo/conversation_legs.rb +14 -0
  20. data/lib/nexmo/conversation_members.rb +74 -0
  21. data/lib/nexmo/conversation_users.rb +63 -0
  22. data/lib/nexmo/conversations.rb +110 -0
  23. data/lib/nexmo/errors.rb +41 -0
  24. data/lib/nexmo/errors/error.rb +0 -27
  25. data/lib/nexmo/form_data.rb +3 -1
  26. data/lib/nexmo/http.rb +3 -1
  27. data/lib/nexmo/json.rb +3 -1
  28. data/lib/nexmo/jwt.rb +25 -0
  29. data/lib/nexmo/keys.rb +3 -1
  30. data/lib/nexmo/logger.rb +3 -1
  31. data/lib/nexmo/namespace.rb +4 -2
  32. data/lib/nexmo/number_insight.rb +102 -0
  33. data/lib/nexmo/numbers.rb +155 -0
  34. data/lib/nexmo/params.rb +3 -1
  35. data/lib/nexmo/redact.rb +20 -0
  36. data/lib/nexmo/secrets.rb +53 -0
  37. data/lib/nexmo/signature.rb +24 -13
  38. data/lib/nexmo/sms.rb +88 -0
  39. data/lib/nexmo/user_agent.rb +3 -1
  40. data/lib/nexmo/verify.rb +144 -0
  41. data/lib/nexmo/version.rb +1 -1
  42. data/nexmo.gemspec +2 -0
  43. metadata +31 -3
  44. data/lib/nexmo/problem.rb +0 -20
@@ -6,6 +6,18 @@ module Nexmo
6
6
 
7
7
  self.request_body = JSON
8
8
 
9
+ # Play DTMF tones into a call.
10
+ #
11
+ # @option params [String] :digits
12
+ # The digits to send.
13
+ #
14
+ # @param [String] id
15
+ # @param [Hash] params
16
+ #
17
+ # @return [Entity]
18
+ #
19
+ # @see https://developer.nexmo.com/api/voice#startDTMF
20
+ #
9
21
  def send(id, params)
10
22
  request('/v1/calls/' + id + '/dtmf', params: params, type: Put)
11
23
  end
@@ -6,10 +6,36 @@ module Nexmo
6
6
 
7
7
  self.request_body = JSON
8
8
 
9
+ # Play an audio file into a call.
10
+ #
11
+ # @option params [required, Array<String>] :stream_url
12
+ # URL of the audio file.
13
+ #
14
+ # @option params [Integer] :loop
15
+ # The number of times to play the file, 0 for infinite.
16
+ #
17
+ # @option params [String] :level
18
+ # Set the audio level of the stream in the range -1 >= level <= 1 with a precision of 0.1. The default value is 0.
19
+ #
20
+ # @param [String] id
21
+ # @param [Hash] params
22
+ #
23
+ # @return [Entity]
24
+ #
25
+ # @see https://developer.nexmo.com/api/voice#startStream
26
+ #
9
27
  def start(id, params)
10
28
  request('/v1/calls/' + id + '/stream', params: params, type: Put)
11
29
  end
12
30
 
31
+ # Stop playing an audio file into a call.
32
+ #
33
+ # @param [String] id
34
+ #
35
+ # @return [Entity]
36
+ #
37
+ # @see https://developer.nexmo.com/api/voice#stopStream
38
+ #
13
39
  def stop(id)
14
40
  request('/v1/calls/' + id + '/stream', type: Delete)
15
41
  end
@@ -6,10 +6,40 @@ module Nexmo
6
6
 
7
7
  self.request_body = JSON
8
8
 
9
+ # Play text to speech into a call.
10
+ #
11
+ # @option params [required, String] :text
12
+ # The text to read.
13
+ #
14
+ # @option params [String] :voice_name
15
+ # The voice & language to use.
16
+ #
17
+ # @option params [Integer] :loop
18
+ # The number of times to repeat the text the file, 0 for infinite.
19
+ #
20
+ # @option params [String] :level
21
+ # The volume level that the speech is played.
22
+ # This can be any value between `-1` to `1` in `0.1` increments, with `0` being the default.
23
+ #
24
+ # @param [String] id
25
+ # @param [Hash] params
26
+ #
27
+ # @return [Entity]
28
+ #
29
+ # @see https://developer.nexmo.com/api/voice#startTalk
30
+ #
9
31
  def start(id, params)
10
32
  request('/v1/calls/' + id + '/talk', params: params, type: Put)
11
33
  end
12
34
 
35
+ # Stop text to speech in a call.
36
+ #
37
+ # @param [String] id
38
+ #
39
+ # @return [Entity]
40
+ #
41
+ # @see https://developer.nexmo.com/api/voice#stopTalk
42
+ #
13
43
  def stop(id)
14
44
  request('/v1/calls/' + id + '/talk', type: Delete)
15
45
  end
data/lib/nexmo/calls.rb CHANGED
@@ -6,54 +6,242 @@ module Nexmo
6
6
 
7
7
  self.request_body = JSON
8
8
 
9
+ # Create an outbound Call.
10
+ #
11
+ # @example
12
+ # response = client.calls.create({
13
+ # to: [{type: 'phone', number: '14843331234'}],
14
+ # from: {type: 'phone', number: '14843335555'},
15
+ # answer_url: ['https://example.com/answer']
16
+ # })
17
+ #
18
+ # @option params [required, Array<Hash>] :to
19
+ # Connect to a Phone (PSTN) number, SIP Endpoint, Websocket, or VBC extension.
20
+ #
21
+ # @option params [required, Hash] :from
22
+ # Connect to a Phone (PSTN) number.
23
+ #
24
+ # @option params [Array<String>] :ncco
25
+ # The Nexmo Call Control Object to use for this call.
26
+ # Required unless **:answer_url** is provided.
27
+ #
28
+ # @option params [Array<String>] :answer_url
29
+ # The webhook endpoint where you provide the Nexmo Call Control Object that governs this call.
30
+ # Required unless **:ncco** is provided.
31
+ #
32
+ # @option params [String] :answer_method
33
+ # The HTTP method used to send event information to answer_url.
34
+ #
35
+ # @option params [required, Array<String>] :event_url
36
+ # The webhook endpoint where call progress events are sent to.
37
+ #
38
+ # @option params [String] :event_method
39
+ # The HTTP method used to send event information to event_url.
40
+ #
41
+ # @option params [String] :machine_detection
42
+ # Configure the behavior when Nexmo detects that the call is answered by voicemail.
43
+ #
44
+ # @option params [Integer] :length_timer
45
+ # Set the number of seconds that elapse before Nexmo hangs up after the call state changes to in_progress.
46
+ #
47
+ # @option params [Integer] :ringing_timer
48
+ # Set the number of seconds that elapse before Nexmo hangs up after the call state changes to `ringing`.
49
+ #
50
+ # @param [Hash] params
51
+ #
52
+ # @return [Entity]
53
+ #
54
+ # @see https://developer.nexmo.com/api/voice#createCall
55
+ #
9
56
  def create(params)
10
57
  request('/v1/calls', params: params, type: Post)
11
58
  end
12
59
 
60
+ # Get details of your calls.
61
+ #
62
+ # @example
63
+ # response = client.calls.list
64
+ # response._embedded.calls.each do |item|
65
+ # puts "#{item.uuid} #{item.direction} #{item.status}"
66
+ # end
67
+ #
68
+ # @option params [String] :status
69
+ # Filter by call status.
70
+ #
71
+ # @option params [String] :date_start
72
+ # Return the records that occurred after this point in time.
73
+ #
74
+ # @option params [String] :date_end
75
+ # Return the records that occurred before this point in time.
76
+ #
77
+ # @option params [Integer] :page_size
78
+ # Return this amount of records in the response.
79
+ #
80
+ # @option params [Integer] :record_index
81
+ # Return calls from this index in the response.
82
+ #
83
+ # @option params [String] :order
84
+ # Either `ascending` or `descending` order.
85
+ #
86
+ # @option params [String] :conversation_uuid
87
+ # Return all the records associated with a specific conversation.
88
+ #
89
+ # @param [Hash] params
90
+ #
91
+ # @return [Entity]
92
+ #
93
+ # @see https://developer.nexmo.com/api/voice#getCalls
94
+ #
13
95
  def list(params = nil)
14
96
  request('/v1/calls', params: params)
15
97
  end
16
98
 
99
+ # Get detail of a specific call.
100
+ #
101
+ # @example
102
+ # response = client.calls.get(id)
103
+ #
104
+ # @param [String] id
105
+ #
106
+ # @return [Entity]
107
+ #
108
+ # @see https://developer.nexmo.com/api/voice#getCall
109
+ #
17
110
  def get(id)
18
111
  request('/v1/calls/' + id)
19
112
  end
20
113
 
114
+ # Modify an in progress call.
115
+ #
116
+ # @example
117
+ # response = client.calls.update(id, action: 'hangup')
118
+ #
119
+ # @option params [required, String] :action
120
+ #
121
+ # @option params [Hash] :destination
122
+ # Required when **:action** is `transfer`.
123
+ #
124
+ # @param [String] id
125
+ # @param [Hash] params
126
+ #
127
+ # @return [Entity]
128
+ #
129
+ # @see https://developer.nexmo.com/api/voice#updateCall
130
+ #
21
131
  def update(id, params)
22
132
  request('/v1/calls/' + id, params: params, type: Put)
23
133
  end
24
134
 
135
+ # Hangup an in progress call.
136
+ #
137
+ # @example
138
+ # response = client.calls.hangup(id)
139
+ #
140
+ # @param [String] id
141
+ #
142
+ # @return [Entity]
143
+ #
144
+ # @see https://developer.nexmo.com/api/voice#updateCall
145
+ #
25
146
  def hangup(id)
26
147
  update(id, action: 'hangup')
27
148
  end
28
149
 
150
+ # Mute an in progress call.
151
+ #
152
+ # @example
153
+ # response = client.calls.mute(id)
154
+ #
155
+ # @param [String] id
156
+ #
157
+ # @return [Entity]
158
+ #
159
+ # @see https://developer.nexmo.com/api/voice#updateCall
160
+ #
29
161
  def mute(id)
30
162
  update(id, action: 'mute')
31
163
  end
32
164
 
165
+ # Unmute an in progress call.
166
+ #
167
+ # @example
168
+ # response = client.calls.unmute(id)
169
+ #
170
+ # @param [String] id
171
+ #
172
+ # @return [Entity]
173
+ #
174
+ # @see https://developer.nexmo.com/api/voice#updateCall
175
+ #
33
176
  def unmute(id)
34
177
  update(id, action: 'unmute')
35
178
  end
36
179
 
180
+ # Earmuff an in progress call.
181
+ #
182
+ # @example
183
+ # response = client.calls.earmuff(id)
184
+ #
185
+ # @param [String] id
186
+ #
187
+ # @return [Entity]
188
+ #
189
+ # @see https://developer.nexmo.com/api/voice#updateCall
190
+ #
37
191
  def earmuff(id)
38
192
  update(id, action: 'earmuff')
39
193
  end
40
194
 
195
+ # Unearmuff an in progress call.
196
+ #
197
+ # @example
198
+ # response = client.calls.unearmuff(id)
199
+ #
200
+ # @param [String] id
201
+ #
202
+ # @return [Entity]
203
+ #
204
+ # @see https://developer.nexmo.com/api/voice#updateCall
205
+ #
41
206
  def unearmuff(id)
42
207
  update(id, action: 'unearmuff')
43
208
  end
44
209
 
210
+ # Transfer an in progress call.
211
+ #
212
+ # @example
213
+ # destination = {
214
+ # type: 'ncco',
215
+ # url: ['https://example.com/ncco.json']
216
+ # }
217
+ #
218
+ # response = client.calls.transfer(id, destination: destination)
219
+ #
220
+ # @param [String] id
221
+ # @param [Hash] destination
222
+ #
223
+ # @return [Entity]
224
+ #
225
+ # @see https://developer.nexmo.com/api/voice#updateCall
226
+ #
45
227
  def transfer(id, destination:)
46
228
  update(id, action: 'transfer', destination: destination)
47
229
  end
48
230
 
231
+ # @return [CallStream]
232
+ #
49
233
  def stream
50
234
  @stream ||= CallStream.new(@client)
51
235
  end
52
236
 
237
+ # @return [CallTalk]
238
+ #
53
239
  def talk
54
240
  @talk ||= CallTalk.new(@client)
55
241
  end
56
242
 
243
+ # @return [CallDTMF]
244
+ #
57
245
  def dtmf
58
246
  @dtmf ||= CallDTMF.new(@client)
59
247
  end
data/lib/nexmo/client.rb CHANGED
@@ -36,24 +36,40 @@ module Nexmo
36
36
  @http_options = HTTP::Options.new(hash)
37
37
  end
38
38
 
39
+ # @return [Nexmo::Logger]
40
+ #
39
41
  def logger
40
42
  @logger
41
43
  end
42
44
 
45
+ # @return [Nexmo::Logger]
46
+ #
43
47
  def logger=(logger)
44
48
  @logger = Logger.new(logger)
45
49
  end
46
50
 
51
+ # Returns the value of attribute token, or a temporary short lived token.
52
+ #
53
+ # @return [String]
54
+ #
47
55
  def token
48
56
  @token || JWT.generate({application_id: application_id}, private_key)
49
57
  end
50
58
 
59
+ # @deprecated Use {#token=} instead.
60
+ #
51
61
  def auth_token=(auth_token)
52
62
  Kernel.warn "#{self.class}##{__method__} is deprecated (use #token= instead)"
53
63
 
54
64
  @token = auth_token
55
65
  end
56
66
 
67
+ # Returns the value of attribute api_key.
68
+ #
69
+ # @return [String]
70
+ #
71
+ # @raise [AuthenticationError]
72
+ #
57
73
  def api_key
58
74
  unless @api_key
59
75
  raise AuthenticationError.new('No API key provided. ' \
@@ -64,6 +80,12 @@ module Nexmo
64
80
  @api_key
65
81
  end
66
82
 
83
+ # Returns the value of attribute api_secret.
84
+ #
85
+ # @return [String]
86
+ #
87
+ # @raise [AuthenticationError]
88
+ #
67
89
  def api_secret
68
90
  unless @api_secret
69
91
  raise AuthenticationError.new('No API secret provided. ' \
@@ -74,6 +96,12 @@ module Nexmo
74
96
  @api_secret
75
97
  end
76
98
 
99
+ # Returns the value of attribute signature_secret.
100
+ #
101
+ # @return [String]
102
+ #
103
+ # @raise [AuthenticationError]
104
+ #
77
105
  def signature_secret
78
106
  unless @signature_secret
79
107
  raise AuthenticationError.new('No signature_secret provided. ' \
@@ -85,6 +113,12 @@ module Nexmo
85
113
  @signature_secret
86
114
  end
87
115
 
116
+ # Returns the value of attribute application_id.
117
+ #
118
+ # @return [String]
119
+ #
120
+ # @raise [AuthenticationError]
121
+ #
88
122
  def application_id
89
123
  unless @application_id
90
124
  raise AuthenticationError.new('No application_id provided. ' \
@@ -97,6 +131,12 @@ module Nexmo
97
131
  @application_id
98
132
  end
99
133
 
134
+ # Returns the value of attribute private_key.
135
+ #
136
+ # @return [String]
137
+ #
138
+ # @raise [AuthenticationError]
139
+ #
100
140
  def private_key
101
141
  unless @private_key
102
142
  raise AuthenticationError.new('No private_key provided. ' \
@@ -109,74 +149,110 @@ module Nexmo
109
149
  @private_key
110
150
  end
111
151
 
152
+ # @return [Signature]
153
+ #
112
154
  def signature
113
- @signature ||= Signature.new(self)
155
+ @signature ||= Signature.new(signature_secret)
114
156
  end
115
157
 
158
+ # @return [Account]
159
+ #
116
160
  def account
117
161
  @account ||= Account.new(self)
118
162
  end
119
163
 
164
+ # @return [Alerts]
165
+ #
120
166
  def alerts
121
167
  @alerts ||= Alerts.new(self)
122
168
  end
123
169
 
170
+ # @return [Applications]
171
+ #
124
172
  def applications
125
173
  @applications ||= Applications.new(self)
126
174
  end
127
175
 
176
+ # @return [ApplicationsV2]
177
+ #
128
178
  def applications_v2
129
179
  @applications_v2 ||= ApplicationsV2.new(self)
130
180
  end
131
181
 
182
+ # @return [Calls]
183
+ #
132
184
  def calls
133
185
  @calls ||= Calls.new(self)
134
186
  end
135
187
 
188
+ # @return [Conversations]
189
+ #
136
190
  def conversations
137
191
  @conversations ||= Conversations.new(self)
138
192
  end
139
193
 
194
+ # @return [Conversions]
195
+ #
140
196
  def conversions
141
197
  @conversions ||= Conversions.new(self)
142
198
  end
143
199
 
200
+ # @return [Files]
201
+ #
144
202
  def files
145
203
  @files ||= Files.new(self)
146
204
  end
147
205
 
206
+ # @return [Messages]
207
+ #
148
208
  def messages
149
209
  @messages ||= Messages.new(self)
150
210
  end
151
211
 
212
+ # @return [NumberInsight]
213
+ #
152
214
  def number_insight
153
215
  @number_insight ||= NumberInsight.new(self)
154
216
  end
155
217
 
218
+ # @return [Numbers]
219
+ #
156
220
  def numbers
157
221
  @numbers ||= Numbers.new(self)
158
222
  end
159
223
 
224
+ # @return [PricingTypes]
225
+ #
160
226
  def pricing
161
227
  @pricing ||= PricingTypes.new(self)
162
228
  end
163
229
 
230
+ # @return [Redact]
231
+ #
164
232
  def redact
165
233
  @redact ||= Redact.new(self)
166
234
  end
167
235
 
236
+ # @return [Secrets]
237
+ #
168
238
  def secrets
169
239
  @secrets ||= Secrets.new(self)
170
240
  end
171
241
 
242
+ # @return [SMS]
243
+ #
172
244
  def sms
173
245
  @sms ||= SMS.new(self)
174
246
  end
175
247
 
248
+ # @return [TFA]
249
+ #
176
250
  def tfa
177
251
  @tfa ||= TFA.new(self)
178
252
  end
179
253
 
254
+ # @return [Verify]
255
+ #
180
256
  def verify
181
257
  @verify ||= Verify.new(self)
182
258
  end