nexmo 5.9.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -465
  3. data/lib/nexmo.rb +31 -48
  4. data/lib/nexmo/{authentication/abstract.rb → abstract_authentication.rb} +2 -2
  5. data/lib/nexmo/account.rb +4 -2
  6. data/lib/nexmo/alerts.rb +3 -3
  7. data/lib/nexmo/applications.rb +45 -63
  8. data/lib/nexmo/applications/list_response.rb +9 -0
  9. data/lib/nexmo/{errors/authentication_error.rb → authentication_error.rb} +0 -0
  10. data/lib/nexmo/{authentication/basic.rb → basic.rb} +1 -1
  11. data/lib/nexmo/{authentication/bearer_token.rb → bearer_token.rb} +1 -1
  12. data/lib/nexmo/calls.rb +18 -18
  13. data/lib/nexmo/{call_dtmf.rb → calls/dtmf.rb} +2 -2
  14. data/lib/nexmo/calls/list_response.rb +9 -0
  15. data/lib/nexmo/{call_stream.rb → calls/stream.rb} +3 -3
  16. data/lib/nexmo/{call_talk.rb → calls/talk.rb} +3 -3
  17. data/lib/nexmo/client.rb +20 -169
  18. data/lib/nexmo/{errors/client_error.rb → client_error.rb} +0 -0
  19. data/lib/nexmo/config.rb +165 -0
  20. data/lib/nexmo/conversations.rb +44 -13
  21. data/lib/nexmo/{conversation_events.rb → conversations/events.rb} +5 -5
  22. data/lib/nexmo/{conversation_legs.rb → conversations/legs.rb} +3 -3
  23. data/lib/nexmo/{conversation_members.rb → conversations/members.rb} +6 -6
  24. data/lib/nexmo/{conversation_users.rb → conversations/users.rb} +6 -6
  25. data/lib/nexmo/entity.rb +14 -0
  26. data/lib/nexmo/{errors/error.rb → error.rb} +0 -0
  27. data/lib/nexmo/files.rb +1 -2
  28. data/lib/nexmo/gsm7.rb +13 -0
  29. data/lib/nexmo/{authentication/key_secret_params.rb → key_secret_params.rb} +2 -2
  30. data/lib/nexmo/{authentication/key_secret_query.rb → key_secret_query.rb} +2 -2
  31. data/lib/nexmo/keys.rb +4 -22
  32. data/lib/nexmo/namespace.rb +22 -12
  33. data/lib/nexmo/number_insight.rb +6 -4
  34. data/lib/nexmo/number_insight/response.rb +5 -0
  35. data/lib/nexmo/numbers.rb +20 -12
  36. data/lib/nexmo/numbers/list_response.rb +9 -0
  37. data/lib/nexmo/numbers/response.rb +7 -0
  38. data/lib/nexmo/pricing.rb +2 -2
  39. data/lib/nexmo/pricing_types.rb +4 -4
  40. data/lib/nexmo/redact.rb +1 -1
  41. data/lib/nexmo/response.rb +23 -0
  42. data/lib/nexmo/secrets.rb +7 -7
  43. data/lib/nexmo/secrets/list_response.rb +9 -0
  44. data/lib/nexmo/{errors/server_error.rb → server_error.rb} +0 -0
  45. data/lib/nexmo/sms.rb +17 -3
  46. data/lib/nexmo/sms/response.rb +7 -0
  47. data/lib/nexmo/verify.rb +10 -8
  48. data/lib/nexmo/verify/response.rb +5 -0
  49. data/lib/nexmo/version.rb +1 -1
  50. data/nexmo.gemspec +4 -2
  51. metadata +45 -20
  52. data/lib/nexmo/applications_v2.rb +0 -102
@@ -1,48 +1,31 @@
1
- require 'nexmo/version'
2
- require 'nexmo/params'
3
- require 'nexmo/form_data'
4
- require 'nexmo/http'
5
- require 'nexmo/json'
6
- require 'nexmo/jwt'
7
- require 'nexmo/signature'
8
- require 'nexmo/user_agent'
9
- require 'nexmo/keys'
10
- require 'nexmo/entity'
11
- require 'nexmo/errors'
12
- require 'nexmo/errors/error'
13
- require 'nexmo/errors/client_error'
14
- require 'nexmo/errors/server_error'
15
- require 'nexmo/errors/authentication_error'
16
- require 'nexmo/authentication/abstract'
17
- require 'nexmo/authentication/basic'
18
- require 'nexmo/authentication/bearer_token'
19
- require 'nexmo/authentication/key_secret_params'
20
- require 'nexmo/authentication/key_secret_query'
21
- require 'nexmo/logger'
22
- require 'nexmo/namespace'
23
- require 'nexmo/client'
24
- require 'nexmo/account'
25
- require 'nexmo/alerts'
26
- require 'nexmo/applications'
27
- require 'nexmo/applications_v2'
28
- require 'nexmo/call_dtmf'
29
- require 'nexmo/call_stream'
30
- require 'nexmo/call_talk'
31
- require 'nexmo/calls'
32
- require 'nexmo/conversation_events'
33
- require 'nexmo/conversation_legs'
34
- require 'nexmo/conversation_members'
35
- require 'nexmo/conversation_users'
36
- require 'nexmo/conversations'
37
- require 'nexmo/conversions'
38
- require 'nexmo/files'
39
- require 'nexmo/messages'
40
- require 'nexmo/number_insight'
41
- require 'nexmo/numbers'
42
- require 'nexmo/pricing_types'
43
- require 'nexmo/pricing'
44
- require 'nexmo/redact'
45
- require 'nexmo/secrets'
46
- require 'nexmo/sms'
47
- require 'nexmo/tfa'
48
- require 'nexmo/verify'
1
+ # frozen_string_literal: true
2
+ require 'zeitwerk'
3
+
4
+ module Nexmo
5
+ class ZeitwerkInflector < Zeitwerk::Inflector
6
+ def camelize(basename, _abspath)
7
+ case basename
8
+ when 'http', 'json', 'jwt', 'sms', 'tfa', 'gsm7', 'dtmf', 'version'
9
+ basename.upcase
10
+ else
11
+ super
12
+ end
13
+ end
14
+ end
15
+
16
+ private_constant :ZeitwerkInflector
17
+
18
+ loader = Zeitwerk::Loader.new
19
+ loader.tag = File.basename(__FILE__, '.rb')
20
+ loader.inflector = ZeitwerkInflector.new
21
+ loader.push_dir(__dir__)
22
+ loader.setup
23
+
24
+ def self.config
25
+ @config ||= Config.new
26
+ end
27
+
28
+ def self.configure(&block)
29
+ block.call(config)
30
+ end
31
+ end
@@ -1,7 +1,7 @@
1
1
  module Nexmo
2
2
  class AbstractAuthentication
3
- def initialize(client)
4
- @client = client
3
+ def initialize(config)
4
+ @config = config
5
5
  end
6
6
  end
7
7
 
@@ -8,7 +8,7 @@ module Nexmo
8
8
 
9
9
  # Retrieve your account balance.
10
10
  #
11
- # @return [Entity]
11
+ # @return [Response]
12
12
  #
13
13
  # @see https://developer.nexmo.com/api/developer/account#get-balance
14
14
  #
@@ -30,7 +30,7 @@ module Nexmo
30
30
  #
31
31
  # @param [Hash] params
32
32
  #
33
- # @return [Entity]
33
+ # @return [Response]
34
34
  #
35
35
  # @see https://developer.nexmo.com/api/developer/account#settings
36
36
  #
@@ -45,6 +45,8 @@ module Nexmo
45
45
  #
46
46
  # @param [Hash] params
47
47
  #
48
+ # @return [Response]
49
+ #
48
50
  # @see https://developer.nexmo.com/api/developer/account#top-up
49
51
  #
50
52
  def topup(params)
@@ -8,7 +8,7 @@ module Nexmo
8
8
  #
9
9
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/subscription
10
10
  #
11
- # @return [Entity]
11
+ # @return [Response]
12
12
  #
13
13
  def list
14
14
  request('/sc/us/alert/opt-in/query/json')
@@ -21,7 +21,7 @@ module Nexmo
21
21
  #
22
22
  # @param [Hash] params
23
23
  #
24
- # @return [Entity]
24
+ # @return [Response]
25
25
  #
26
26
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/subscription
27
27
  #
@@ -56,7 +56,7 @@ module Nexmo
56
56
  #
57
57
  # @param [Hash] params
58
58
  #
59
- # @return [Entity]
59
+ # @return [Response]
60
60
  #
61
61
  # @see https://developer.nexmo.com/api/sms/us-short-codes/alerts/sending
62
62
  #
@@ -2,9 +2,13 @@
2
2
 
3
3
  module Nexmo
4
4
  class Applications < Namespace
5
+ self.authentication = Basic
6
+
5
7
  self.request_body = JSON
6
8
 
7
- # Create a new application.
9
+ self.request_headers['Content-Type'] = 'application/json'
10
+
11
+ # Create an application.
8
12
  #
9
13
  # @example
10
14
  # params = {
@@ -17,129 +21,107 @@ module Nexmo
17
21
  # response = client.applications.create(params)
18
22
  #
19
23
  # @option params [required, String] :name
20
- # The name of your application.
21
- #
22
- # @option params [required, String] :type
23
- # The Nexmo product or products that you access with this application.
24
- # Currently only `voice` and `messages` are supported.
25
- #
26
- # @option params [required, String] :answer_url
27
- # The URL where your webhook delivers the Nexmo Call Control Object that governs this call.
28
- # As soon as your user answers a call Nexmo makes a request to answer_url.
29
- #
30
- # @option params [String] :answer_method
31
- # The HTTP method used to make the request to answer_url.
32
- # The default value is GET.
24
+ # Application name.
33
25
  #
34
- # @option params [required, String] :event_url
35
- # Nexmo sends event information asynchronously to this URL when status changes.
26
+ # @option params [Hash] :keys
27
+ # - **:public_key** (String) Public key
36
28
  #
37
- # @option params [String] :event_method
38
- # The HTTP method used to send event information to event_url.
39
- # The default value is POST.
29
+ # @option params [Hash] :capabilities
30
+ # Your application can use multiple products.
31
+ # This contains the configuration for each product.
32
+ # This replaces the application `type` from version 1 of the Application API.
40
33
  #
41
34
  # @param [Hash] params
42
35
  #
43
- # @return [Entity]
36
+ # @return [Response]
44
37
  #
45
- # @see https://developer.nexmo.com/api/application#create-an-application
38
+ # @see https://developer.nexmo.com/api/application.v2#createApplication
46
39
  #
47
40
  def create(params)
48
- request('/v1/applications', params: params, type: Post)
41
+ request('/v2/applications', params: params, type: Post)
49
42
  end
50
43
 
51
- # Retrieve details of all applications associated with your account.
44
+ # List available applications.
52
45
  #
53
46
  # @example
54
47
  # response = client.applications.list
55
- # response._embedded.applications.each do |item|
48
+ # response.each do |item|
56
49
  # puts "#{item.id} #{item.name}"
57
50
  # end
58
51
  #
59
52
  # @option params [Integer] :page_size
60
- # Set the number of items returned on each call to this endpoint.
61
- # The default is 10 records.
53
+ # The number of applications per page.
62
54
  #
63
- # @option params [Integer] :page_index
64
- # Set the offset from the first page.
65
- # The default value is 0.
55
+ # @option params [Integer] :page
56
+ # The current page number (starts at 1).
66
57
  #
67
- # @param [Hash, nil] params
58
+ # @param [Hash] params
68
59
  #
69
- # @return [Entity]
60
+ # @return [ListResponse]
70
61
  #
71
- # @see https://developer.nexmo.com/api/application#retrieve-your-applications
62
+ # @see https://developer.nexmo.com/api/application.v2#listApplication
72
63
  #
73
64
  def list(params = nil)
74
- request('/v1/applications', params: params)
65
+ request('/v2/applications', params: params, response_class: ListResponse)
75
66
  end
76
67
 
77
- # Retrieve details about a single application.
68
+ # Get an application.
78
69
  #
79
70
  # @example
80
71
  # response = client.applications.get(id)
81
72
  #
82
73
  # @param [String] id
83
74
  #
84
- # @return [Entity]
75
+ # @return [Response]
85
76
  #
86
- # @see https://developer.nexmo.com/api/application#retrieve-an-application
77
+ # @see https://developer.nexmo.com/api/application.v2#getApplication
87
78
  #
88
79
  def get(id)
89
- request('/v1/applications/' + id)
80
+ request('/v2/applications/' + id)
90
81
  end
91
82
 
92
- # Update an existing application.
83
+ # Update an application.
93
84
  #
94
85
  # @example
95
86
  # response = client.applications.update(id, answer_method: 'POST')
96
87
  #
97
88
  # @option params [required, String] :name
98
- # The name of your application.
99
- #
100
- # @option params [required, String] :type
101
- # The Nexmo product or products that you access with this application.
102
- # Currently only `voice` and `messages` are supported.
103
- #
104
- # @option params [required, String] :answer_url
105
- # The URL where your webhook delivers the Nexmo Call Control Object that governs this call.
106
- # As soon as your user answers a call Nexmo makes a request to answer_url.
89
+ # Application name.
107
90
  #
108
- # @option params [String] :answer_method
109
- # The HTTP method used to make the request to answer_url.
110
- # The default value is GET.
91
+ # @option params [Hash] :keys
92
+ # - **:public_key** (String) Public key
111
93
  #
112
- # @option params [required, String] :event_url
113
- # Nexmo sends event information asynchronously to this URL when status changes.
114
- #
115
- # @option params [String] :event_method
116
- # The HTTP method used to send event information to event_url.
117
- # The default value is POST.
94
+ # @option params [Hash] :capabilities
95
+ # Your application can use multiple products.
96
+ # This contains the configuration for each product.
97
+ # This replaces the application `type` from version 1 of the Application API.
118
98
  #
119
99
  # @param [String] id
120
100
  # @param [Hash] params
121
101
  #
122
- # @return [Entity]
102
+ # @return [Response]
123
103
  #
124
- # @see https://developer.nexmo.com/api/application#update-an-application
104
+ # @see https://developer.nexmo.com/api/application.v2#updateApplication
125
105
  #
126
106
  def update(id, params)
127
- request('/v1/applications/' + id, params: params, type: Put)
107
+ request('/v2/applications/' + id, params: params, type: Put)
128
108
  end
129
109
 
130
- # Delete a single application.
110
+ # Delete an application.
131
111
  #
132
112
  # @example
133
113
  # response = client.applications.delete(id)
134
114
  #
115
+ # @note Deleting an application cannot be undone.
116
+ #
135
117
  # @param [String] id
136
118
  #
137
- # @return [:no_content]
119
+ # @return [Response]
138
120
  #
139
- # @see https://developer.nexmo.com/api/application#destroy-an-application
121
+ # @see https://developer.nexmo.com/api/application.v2#deleteApplication
140
122
  #
141
123
  def delete(id)
142
- request('/v1/applications/' + id, type: Delete)
124
+ request('/v2/applications/' + id, type: Delete)
143
125
  end
144
126
  end
145
127
  end
@@ -0,0 +1,9 @@
1
+ class Nexmo::Applications::ListResponse < Nexmo::Response
2
+ include Enumerable
3
+
4
+ def each
5
+ return enum_for(:each) unless block_given?
6
+
7
+ @entity._embedded.applications.each { |item| yield item }
8
+ end
9
+ end
@@ -3,7 +3,7 @@ module Nexmo
3
3
  def update(object)
4
4
  return unless object.is_a?(Net::HTTPRequest)
5
5
 
6
- object.basic_auth(@client.api_key, @client.api_secret)
6
+ object.basic_auth(@config.api_key, @config.api_secret)
7
7
  end
8
8
  end
9
9
 
@@ -5,7 +5,7 @@ module Nexmo
5
5
  def update(object)
6
6
  return unless object.is_a?(Net::HTTPRequest)
7
7
 
8
- object['Authorization'] = 'Bearer ' + @client.token
8
+ object['Authorization'] = 'Bearer ' + @config.token
9
9
  end
10
10
  end
11
11
 
@@ -49,7 +49,7 @@ module Nexmo
49
49
  #
50
50
  # @param [Hash] params
51
51
  #
52
- # @return [Entity]
52
+ # @return [Response]
53
53
  #
54
54
  # @see https://developer.nexmo.com/api/voice#createCall
55
55
  #
@@ -61,7 +61,7 @@ module Nexmo
61
61
  #
62
62
  # @example
63
63
  # response = client.calls.list
64
- # response._embedded.calls.each do |item|
64
+ # response.each do |item|
65
65
  # puts "#{item.uuid} #{item.direction} #{item.status}"
66
66
  # end
67
67
  #
@@ -88,12 +88,12 @@ module Nexmo
88
88
  #
89
89
  # @param [Hash] params
90
90
  #
91
- # @return [Entity]
91
+ # @return [ListResponse]
92
92
  #
93
93
  # @see https://developer.nexmo.com/api/voice#getCalls
94
94
  #
95
95
  def list(params = nil)
96
- request('/v1/calls', params: params)
96
+ request('/v1/calls', params: params, response_class: ListResponse)
97
97
  end
98
98
 
99
99
  # Get detail of a specific call.
@@ -103,7 +103,7 @@ module Nexmo
103
103
  #
104
104
  # @param [String] id
105
105
  #
106
- # @return [Entity]
106
+ # @return [Response]
107
107
  #
108
108
  # @see https://developer.nexmo.com/api/voice#getCall
109
109
  #
@@ -124,7 +124,7 @@ module Nexmo
124
124
  # @param [String] id
125
125
  # @param [Hash] params
126
126
  #
127
- # @return [Entity]
127
+ # @return [Response]
128
128
  #
129
129
  # @see https://developer.nexmo.com/api/voice#updateCall
130
130
  #
@@ -139,7 +139,7 @@ module Nexmo
139
139
  #
140
140
  # @param [String] id
141
141
  #
142
- # @return [Entity]
142
+ # @return [Response]
143
143
  #
144
144
  # @see https://developer.nexmo.com/api/voice#updateCall
145
145
  #
@@ -154,7 +154,7 @@ module Nexmo
154
154
  #
155
155
  # @param [String] id
156
156
  #
157
- # @return [Entity]
157
+ # @return [Response]
158
158
  #
159
159
  # @see https://developer.nexmo.com/api/voice#updateCall
160
160
  #
@@ -169,7 +169,7 @@ module Nexmo
169
169
  #
170
170
  # @param [String] id
171
171
  #
172
- # @return [Entity]
172
+ # @return [Response]
173
173
  #
174
174
  # @see https://developer.nexmo.com/api/voice#updateCall
175
175
  #
@@ -184,7 +184,7 @@ module Nexmo
184
184
  #
185
185
  # @param [String] id
186
186
  #
187
- # @return [Entity]
187
+ # @return [Response]
188
188
  #
189
189
  # @see https://developer.nexmo.com/api/voice#updateCall
190
190
  #
@@ -199,7 +199,7 @@ module Nexmo
199
199
  #
200
200
  # @param [String] id
201
201
  #
202
- # @return [Entity]
202
+ # @return [Response]
203
203
  #
204
204
  # @see https://developer.nexmo.com/api/voice#updateCall
205
205
  #
@@ -220,7 +220,7 @@ module Nexmo
220
220
  # @param [String] id
221
221
  # @param [Hash] destination
222
222
  #
223
- # @return [Entity]
223
+ # @return [Response]
224
224
  #
225
225
  # @see https://developer.nexmo.com/api/voice#updateCall
226
226
  #
@@ -228,22 +228,22 @@ module Nexmo
228
228
  update(id, action: 'transfer', destination: destination)
229
229
  end
230
230
 
231
- # @return [CallStream]
231
+ # @return [Stream]
232
232
  #
233
233
  def stream
234
- @stream ||= CallStream.new(@client)
234
+ @stream ||= Stream.new(@config)
235
235
  end
236
236
 
237
- # @return [CallTalk]
237
+ # @return [Talk]
238
238
  #
239
239
  def talk
240
- @talk ||= CallTalk.new(@client)
240
+ @talk ||= Talk.new(@config)
241
241
  end
242
242
 
243
- # @return [CallDTMF]
243
+ # @return [DTMF]
244
244
  #
245
245
  def dtmf
246
- @dtmf ||= CallDTMF.new(@client)
246
+ @dtmf ||= DTMF.new(@config)
247
247
  end
248
248
  end
249
249
  end