nexmo 5.9.0 → 6.0.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.
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
@@ -28,7 +28,7 @@ module Nexmo
28
28
  # @option params [Hash] :properties
29
29
  # - **:ttl** (Integer) After how many seconds an empty conversation is deleted
30
30
  #
31
- # @return [Entity]
31
+ # @return [Response]
32
32
  #
33
33
  # @see https://developer.nexmo.com/api/conversation#createConversation
34
34
  #
@@ -58,7 +58,7 @@ module Nexmo
58
58
  #
59
59
  # @param [Hash, nil] params
60
60
  #
61
- # @return [Entity]
61
+ # @return [Response]
62
62
  #
63
63
  # @see https://developer.nexmo.com/api/conversation#replaceConversation
64
64
  #
@@ -73,7 +73,7 @@ module Nexmo
73
73
  #
74
74
  # @param [String] id
75
75
  #
76
- # @return [Entity]
76
+ # @return [Response]
77
77
  #
78
78
  # @see https://developer.nexmo.com/api/conversation#retrieveConversation
79
79
  #
@@ -105,7 +105,7 @@ module Nexmo
105
105
  # @param [String] id
106
106
  # @param [Hash] params
107
107
  #
108
- # @return [Entity]
108
+ # @return [Response]
109
109
  #
110
110
  # @see https://developer.nexmo.com/api/conversation#replaceConversation
111
111
  #
@@ -120,7 +120,7 @@ module Nexmo
120
120
  #
121
121
  # @param [String] id
122
122
  #
123
- # @return [Entity]
123
+ # @return [Response]
124
124
  #
125
125
  # @see https://developer.nexmo.com/api/conversation#deleteConversation
126
126
  #
@@ -128,28 +128,59 @@ module Nexmo
128
128
  request('/beta/conversations/' + id, type: Delete)
129
129
  end
130
130
 
131
- # @return [ConversationEvents]
131
+ # Record a conversation.
132
+ #
133
+ # @example
134
+ # response = client.conversations.record(id, action: 'start')
135
+ #
136
+ # @option params [String] :action
137
+ # Recording action. Must be one of `start` or `stop`.
138
+ #
139
+ # @option params [String] :event_url
140
+ # The webhook endpoint where recording progress events are sent to.
141
+ #
142
+ # @option params [String] :event_method
143
+ # The HTTP method used to send event information to **:event_url**.
144
+ #
145
+ # @option params [String] :split
146
+ # Record the sent and received audio in separate channels of a stereo recording.
147
+ #
148
+ # @option params [String] :format
149
+ # Record the conversation in a specific format.
150
+ #
151
+ # @param [String] id
152
+ # @param [Hash] params
153
+ #
154
+ # @return [Response]
155
+ #
156
+ # @see https://developer.nexmo.com/api/conversation#recordConversation
157
+ #
158
+ def record(id, params)
159
+ request('/beta/conversations/' + id + '/record', params: params, type: Put)
160
+ end
161
+
162
+ # @return [Events]
132
163
  #
133
164
  def events
134
- @events ||= ConversationEvents.new(@client)
165
+ @events ||= Events.new(@config)
135
166
  end
136
167
 
137
- # @return [ConversationLegs]
168
+ # @return [Legs]
138
169
  #
139
170
  def legs
140
- @legs ||= ConversationLegs.new(@client)
171
+ @legs ||= Legs.new(@config)
141
172
  end
142
173
 
143
- # @return [ConversationMembers]
174
+ # @return [Members]
144
175
  #
145
176
  def members
146
- @members ||= ConversationMembers.new(@client)
177
+ @members ||= Members.new(@config)
147
178
  end
148
179
 
149
- # @return [ConversationUsers]
180
+ # @return [Users]
150
181
  #
151
182
  def users
152
- @users ||= ConversationUsers.new(@client)
183
+ @users ||= Users.new(@config)
153
184
  end
154
185
  end
155
186
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- class ConversationEvents < Namespace
4
+ class Conversations::Events < Namespace
5
5
  self.authentication = BearerToken
6
6
 
7
7
  self.request_body = JSON
@@ -23,7 +23,7 @@ module Nexmo
23
23
  # @param [String] conversation_id
24
24
  # @param [Hash] params
25
25
  #
26
- # @return [Entity]
26
+ # @return [Response]
27
27
  #
28
28
  # @see https://developer.nexmo.com/api/conversation#createEvent
29
29
  #
@@ -35,7 +35,7 @@ module Nexmo
35
35
  #
36
36
  # @param [String] conversation_id
37
37
  #
38
- # @return [Entity]
38
+ # @return [Response]
39
39
  #
40
40
  # @see https://developer.nexmo.com/api/conversation#getEvents
41
41
  #
@@ -48,7 +48,7 @@ module Nexmo
48
48
  # @param [String] conversation_id
49
49
  # @param [String] event_id
50
50
  #
51
- # @return [Entity]
51
+ # @return [Response]
52
52
  #
53
53
  # @see https://developer.nexmo.com/api/conversation#getEvent
54
54
  #
@@ -61,7 +61,7 @@ module Nexmo
61
61
  # @param [String] conversation_id
62
62
  # @param [String] event_id
63
63
  #
64
- # @return [Entity]
64
+ # @return [Response]
65
65
  #
66
66
  # @see https://developer.nexmo.com/api/conversation#deleteEvent
67
67
  #
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- class ConversationLegs < Namespace
4
+ class Conversations::Legs < Namespace
5
5
  self.authentication = BearerToken
6
6
 
7
7
  # List legs.
8
8
  #
9
- # @return [Entity]
9
+ # @return [Response]
10
10
  #
11
11
  # @see https://developer.nexmo.com/api/conversation#listLegs
12
12
  #
@@ -18,7 +18,7 @@ module Nexmo
18
18
  #
19
19
  # @param [String] leg_id
20
20
  #
21
- # @return [Entity]
21
+ # @return [Response]
22
22
  #
23
23
  # @see https://developer.nexmo.com/api/conversation#deleteLeg
24
24
  #
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- class ConversationMembers < Namespace
4
+ class Conversations::Members < Namespace
5
5
  self.authentication = BearerToken
6
6
 
7
7
  self.request_body = JSON
@@ -34,7 +34,7 @@ module Nexmo
34
34
  # @param [String] conversation_id
35
35
  # @param [Hash] params
36
36
  #
37
- # @return [Entity]
37
+ # @return [Response]
38
38
  #
39
39
  # @see https://developer.nexmo.com/api/conversation#createMember
40
40
  #
@@ -46,7 +46,7 @@ module Nexmo
46
46
  #
47
47
  # @param [String] conversation_id
48
48
  #
49
- # @return [Entity]
49
+ # @return [Response]
50
50
  #
51
51
  # @see https://developer.nexmo.com/api/conversation#getMembers
52
52
  #
@@ -59,7 +59,7 @@ module Nexmo
59
59
  # @param [String] conversation_id
60
60
  # @param [String] member_id
61
61
  #
62
- # @return [Entity]
62
+ # @return [Response]
63
63
  #
64
64
  # @see https://developer.nexmo.com/api/conversation#getMember
65
65
  #
@@ -79,7 +79,7 @@ module Nexmo
79
79
  # @param [String] member_id
80
80
  # @param [Hash] params
81
81
  #
82
- # @return [Entity]
82
+ # @return [Response]
83
83
  #
84
84
  # @see https://developer.nexmo.com/api/conversation#updateMember
85
85
  #
@@ -92,7 +92,7 @@ module Nexmo
92
92
  # @param [String] conversation_id
93
93
  # @param [String] member_id
94
94
  #
95
- # @return [Entity]
95
+ # @return [Response]
96
96
  #
97
97
  # @see https://developer.nexmo.com/api/conversation#deleteMember
98
98
  #
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nexmo
4
- class ConversationUsers < Namespace
4
+ class Conversations::Users < Namespace
5
5
  self.authentication = BearerToken
6
6
 
7
7
  self.request_body = JSON
@@ -20,7 +20,7 @@ module Nexmo
20
20
  #
21
21
  # @param [Hash] params
22
22
  #
23
- # @return [Entity]
23
+ # @return [Response]
24
24
  #
25
25
  # @see https://developer.nexmo.com/api/conversation#createUser
26
26
  #
@@ -30,7 +30,7 @@ module Nexmo
30
30
 
31
31
  # List users.
32
32
  #
33
- # @return [Entity]
33
+ # @return [Response]
34
34
  #
35
35
  # @see https://developer.nexmo.com/api/conversation#getUsers
36
36
  #
@@ -42,7 +42,7 @@ module Nexmo
42
42
  #
43
43
  # @param [String] id
44
44
  #
45
- # @return [Entity]
45
+ # @return [Response]
46
46
  #
47
47
  # @see https://developer.nexmo.com/api/conversation#getUser
48
48
  #
@@ -69,7 +69,7 @@ module Nexmo
69
69
  # @param [String] id
70
70
  # @param [Hash] params
71
71
  #
72
- # @return [Entity]
72
+ # @return [Response]
73
73
  #
74
74
  # @see https://developer.nexmo.com/api/conversation#updateUser
75
75
  #
@@ -81,7 +81,7 @@ module Nexmo
81
81
  #
82
82
  # @param [String] id
83
83
  #
84
- # @return [Entity]
84
+ # @return [Response]
85
85
  #
86
86
  # @see https://developer.nexmo.com/api/conversation#deleteUser
87
87
  #
@@ -6,6 +6,10 @@ module Nexmo
6
6
  @attributes = kwargs
7
7
  end
8
8
 
9
+ def [](key)
10
+ @attributes[attribute_key(key)]
11
+ end
12
+
9
13
  def []=(key, value)
10
14
  @attributes[attribute_key(key)] = value
11
15
  end
@@ -31,5 +35,15 @@ module Nexmo
31
35
  attr_reader :attributes
32
36
 
33
37
  protected :attributes
38
+
39
+ def each_pair(&block)
40
+ return to_enum(:each_pair) unless block
41
+
42
+ @attributes.each_pair(&block)
43
+ end
44
+
45
+ alias_method :each, :each_pair
46
+
47
+ include Enumerable
34
48
  end
35
49
  end
File without changes
@@ -5,8 +5,7 @@ module Nexmo
5
5
  self.authentication = BearerToken
6
6
 
7
7
  def get(id)
8
- response = request('/v1/files/' + id.split('/').last)
9
- response.body
8
+ request('/v1/files/' + id.split('/').last)
10
9
  end
11
10
 
12
11
  def save(id, filename)
@@ -0,0 +1,13 @@
1
+ module Nexmo
2
+ module GSM7
3
+ CHARACTERS = "\n\f\r !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~ ¡£¤¥§¿ÄÅÆÉÑÖØÜßàäåæçèéìñòöøùüΓΔΘΛΞΠΣΦΨΩ€"
4
+
5
+ REGEXP = /\A[#{Regexp.escape(CHARACTERS)}]*\z/
6
+
7
+ def self.encoded?(string)
8
+ REGEXP =~ string
9
+ end
10
+ end
11
+
12
+ private_constant :GSM7
13
+ end
@@ -3,8 +3,8 @@ module Nexmo
3
3
  def update(object)
4
4
  return unless object.is_a?(Hash)
5
5
 
6
- object[:api_key] = @client.api_key
7
- object[:api_secret] = @client.api_secret
6
+ object[:api_key] = @config.api_key
7
+ object[:api_secret] = @config.api_secret
8
8
  end
9
9
  end
10
10
 
@@ -10,8 +10,8 @@ module Nexmo
10
10
 
11
11
  def params
12
12
  {
13
- api_key: @client.api_key,
14
- api_secret: @client.api_secret
13
+ api_key: @config.api_key,
14
+ api_secret: @config.api_secret
15
15
  }
16
16
  end
17
17
  end
@@ -2,30 +2,12 @@
2
2
 
3
3
  module Nexmo
4
4
  module Keys
5
- if {}.respond_to?(:transform_keys)
6
- def hyphenate(hash)
7
- hash.transform_keys { |k| hyphenate_key(k) }
8
- end
9
-
10
- def camelcase(hash)
11
- hash.transform_keys { |k| camelcase_key(k) }
12
- end
13
- else
14
- def hyphenate(hash)
15
- hash.each_with_object({}) { |(k, v), h| h[hyphenate_key(k)] = v }
16
- end
17
-
18
- def camelcase(hash)
19
- hash.each_with_object({}) { |(k, v), h| h[camelcase_key(k)] = v }
20
- end
5
+ def hyphenate(hash)
6
+ hash.transform_keys { |k| k.to_s.tr('_', '-') }
21
7
  end
22
8
 
23
- def hyphenate_key(k)
24
- k.to_s.tr('_', '-')
25
- end
26
-
27
- def camelcase_key(k)
28
- k.to_s.gsub(/_(\w)/) { $1.upcase }
9
+ def camelcase(hash)
10
+ hash.transform_keys { |k| k.to_s.gsub(/_(\w)/) { $1.upcase } }
29
11
  end
30
12
 
31
13
  ATTRIBUTE_KEYS = Hash.new { |h, k| h[k] = k.split(PATTERN).join('_').downcase.to_sym }
@@ -4,17 +4,17 @@ require 'json'
4
4
 
5
5
  module Nexmo
6
6
  class Namespace
7
- def initialize(client)
8
- @client = client
7
+ def initialize(config)
8
+ @config = config
9
9
 
10
- @logger = client.logger
10
+ @logger = config.logger
11
11
 
12
12
  @host = self.class.host
13
13
 
14
14
  @http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
15
15
  @http.use_ssl = true
16
16
 
17
- @client.http_options.set(@http)
17
+ @config.http.set(@http) unless @config.http.nil?
18
18
  end
19
19
 
20
20
  def self.host
@@ -45,6 +45,14 @@ module Nexmo
45
45
  @request_headers ||= {}
46
46
  end
47
47
 
48
+ def self.response_class
49
+ @response_class ||= Response
50
+ end
51
+
52
+ def self.response_class=(response_class)
53
+ @response_class = response_class
54
+ end
55
+
48
56
  private
49
57
 
50
58
  Get = Net::HTTP::Get
@@ -52,12 +60,12 @@ module Nexmo
52
60
  Post = Net::HTTP::Post
53
61
  Delete = Net::HTTP::Delete
54
62
 
55
- def request(path, params: nil, type: Get, &block)
63
+ def request(path, params: nil, type: Get, response_class: nil, &block)
56
64
  uri = URI('https://' + @host + path)
57
65
 
58
66
  params ||= {}
59
67
 
60
- authentication = self.class.authentication.new(@client)
68
+ authentication = self.class.authentication.new(@config)
61
69
  authentication.update(params)
62
70
 
63
71
  unless type::REQUEST_HAS_BODY || params.empty?
@@ -68,7 +76,7 @@ module Nexmo
68
76
 
69
77
  message = type.new(uri)
70
78
 
71
- message['User-Agent'] = @client.user_agent
79
+ message['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
72
80
 
73
81
  self.class.request_headers.each do |key, value|
74
82
  message[key] = value
@@ -88,18 +96,20 @@ module Nexmo
88
96
 
89
97
  @logger.debug(response.body) if response.body
90
98
 
91
- parse(response)
99
+ parse(response, response_class || self.class.response_class)
92
100
  end
93
101
 
94
- def parse(response)
102
+ def parse(response, response_class)
95
103
  case response
96
104
  when Net::HTTPNoContent
97
- :no_content
105
+ response_class.new(nil, response)
98
106
  when Net::HTTPSuccess
99
107
  if response['Content-Type'].split(';').first == 'application/json'
100
- ::JSON.parse(response.body, object_class: Nexmo::Entity)
108
+ entity = ::JSON.parse(response.body, object_class: Nexmo::Entity)
109
+
110
+ response_class.new(entity, response)
101
111
  else
102
- response
112
+ response_class.new(nil, response)
103
113
  end
104
114
  else
105
115
  raise Errors.parse(response)