nexmo 5.8.0 → 5.9.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 +1 -1
- data/lib/nexmo.rb +1 -1
- data/lib/nexmo/account.rb +36 -1
- data/lib/nexmo/alerts.rb +46 -0
- data/lib/nexmo/applications.rb +118 -0
- data/lib/nexmo/applications_v2.rb +71 -0
- data/lib/nexmo/authentication/abstract.rb +3 -1
- data/lib/nexmo/authentication/basic.rb +3 -1
- data/lib/nexmo/authentication/bearer_token.rb +3 -1
- data/lib/nexmo/authentication/key_secret_params.rb +3 -1
- data/lib/nexmo/authentication/key_secret_query.rb +3 -1
- data/lib/nexmo/call_dtmf.rb +12 -0
- data/lib/nexmo/call_stream.rb +26 -0
- data/lib/nexmo/call_talk.rb +30 -0
- data/lib/nexmo/calls.rb +188 -0
- data/lib/nexmo/client.rb +77 -1
- data/lib/nexmo/conversation_events.rb +47 -0
- data/lib/nexmo/conversation_legs.rb +14 -0
- data/lib/nexmo/conversation_members.rb +74 -0
- data/lib/nexmo/conversation_users.rb +63 -0
- data/lib/nexmo/conversations.rb +110 -0
- data/lib/nexmo/errors.rb +41 -0
- data/lib/nexmo/errors/error.rb +0 -27
- data/lib/nexmo/form_data.rb +3 -1
- data/lib/nexmo/http.rb +3 -1
- data/lib/nexmo/json.rb +3 -1
- data/lib/nexmo/jwt.rb +25 -0
- data/lib/nexmo/keys.rb +3 -1
- data/lib/nexmo/logger.rb +3 -1
- data/lib/nexmo/namespace.rb +4 -2
- data/lib/nexmo/number_insight.rb +102 -0
- data/lib/nexmo/numbers.rb +155 -0
- data/lib/nexmo/params.rb +3 -1
- data/lib/nexmo/redact.rb +20 -0
- data/lib/nexmo/secrets.rb +53 -0
- data/lib/nexmo/signature.rb +24 -13
- data/lib/nexmo/sms.rb +88 -0
- data/lib/nexmo/user_agent.rb +3 -1
- data/lib/nexmo/verify.rb +144 -0
- data/lib/nexmo/version.rb +1 -1
- data/nexmo.gemspec +2 -0
- metadata +31 -3
- data/lib/nexmo/problem.rb +0 -20
data/lib/nexmo/errors/error.rb
CHANGED
@@ -1,31 +1,4 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module Nexmo
|
5
2
|
class Error < StandardError
|
6
|
-
def self.parse(response) # :nodoc:
|
7
|
-
exception_class = case response
|
8
|
-
when Net::HTTPUnauthorized
|
9
|
-
AuthenticationError
|
10
|
-
when Net::HTTPClientError
|
11
|
-
ClientError
|
12
|
-
when Net::HTTPServerError
|
13
|
-
ServerError
|
14
|
-
else
|
15
|
-
Error
|
16
|
-
end
|
17
|
-
|
18
|
-
message = if content_type = response['Content-Type']
|
19
|
-
case content_type.split(';').first
|
20
|
-
when 'application/problem+json'
|
21
|
-
Problem.parse(response.body)
|
22
|
-
when 'application/json'
|
23
|
-
hash = ::JSON.parse(response.body)
|
24
|
-
hash['error_title']
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
exception_class.new(message)
|
29
|
-
end
|
30
3
|
end
|
31
4
|
end
|
data/lib/nexmo/form_data.rb
CHANGED
data/lib/nexmo/http.rb
CHANGED
data/lib/nexmo/json.rb
CHANGED
@@ -2,10 +2,12 @@
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module Nexmo
|
5
|
-
module JSON
|
5
|
+
module JSON
|
6
6
|
def self.update(http_request, params)
|
7
7
|
http_request['Content-Type'] = 'application/json'
|
8
8
|
http_request.body = ::JSON.generate(params)
|
9
9
|
end
|
10
10
|
end
|
11
|
+
|
12
|
+
private_constant :JSON
|
11
13
|
end
|
data/lib/nexmo/jwt.rb
CHANGED
@@ -5,6 +5,31 @@ require 'jwt'
|
|
5
5
|
|
6
6
|
module Nexmo
|
7
7
|
module JWT
|
8
|
+
# Generate an encoded JSON Web Token.
|
9
|
+
#
|
10
|
+
# By default the Nexmo Ruby SDK generates a short lived JWT per request.
|
11
|
+
#
|
12
|
+
# To generate a long lived JWT for multiple requests or to specify JWT claims
|
13
|
+
# directly call {Nexmo::JWT.generate} to generate a token, and set the token
|
14
|
+
# attribute on the client object.
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# claims = {
|
18
|
+
# application_id: application_id,
|
19
|
+
# nbf: 1483315200,
|
20
|
+
# exp: 1514764800,
|
21
|
+
# iat: 1483228800
|
22
|
+
# }
|
23
|
+
#
|
24
|
+
# private_key = File.read('path/to/private.key')
|
25
|
+
#
|
26
|
+
# client.token = Nexmo::JWT.generate(claims, private_key)
|
27
|
+
#
|
28
|
+
# @param [Hash] payload
|
29
|
+
# @param [String, OpenSSL::PKey::RSA] private_key
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
#
|
8
33
|
def self.generate(payload, private_key)
|
9
34
|
payload[:iat] = iat = Time.now.to_i unless payload.key?(:iat) || payload.key?('iat')
|
10
35
|
payload[:exp] = iat + 60 unless payload.key?(:exp) || payload.key?('exp')
|
data/lib/nexmo/keys.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Nexmo
|
4
|
-
module Keys
|
4
|
+
module Keys
|
5
5
|
if {}.respond_to?(:transform_keys)
|
6
6
|
def hyphenate(hash)
|
7
7
|
hash.transform_keys { |k| hyphenate_key(k) }
|
@@ -42,4 +42,6 @@ module Nexmo
|
|
42
42
|
ATTRIBUTE_KEYS[k]
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
private_constant :Keys
|
45
47
|
end
|
data/lib/nexmo/logger.rb
CHANGED
@@ -3,7 +3,7 @@ require 'logger'
|
|
3
3
|
require 'forwardable'
|
4
4
|
|
5
5
|
module Nexmo
|
6
|
-
class Logger
|
6
|
+
class Logger
|
7
7
|
def initialize(logger)
|
8
8
|
@logger = logger || ::Logger.new(nil)
|
9
9
|
end
|
@@ -45,4 +45,6 @@ module Nexmo
|
|
45
45
|
fields.join(' ')
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
private_constant :Logger
|
48
50
|
end
|
data/lib/nexmo/namespace.rb
CHANGED
@@ -3,7 +3,7 @@ require 'net/http'
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
module Nexmo
|
6
|
-
class Namespace
|
6
|
+
class Namespace
|
7
7
|
def initialize(client)
|
8
8
|
@client = client
|
9
9
|
|
@@ -102,8 +102,10 @@ module Nexmo
|
|
102
102
|
response
|
103
103
|
end
|
104
104
|
else
|
105
|
-
raise
|
105
|
+
raise Errors.parse(response)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
private_constant :Namespace
|
109
111
|
end
|
data/lib/nexmo/number_insight.rb
CHANGED
@@ -2,18 +2,120 @@
|
|
2
2
|
|
3
3
|
module Nexmo
|
4
4
|
class NumberInsight < Namespace
|
5
|
+
# Provides basic number insight information about a number.
|
6
|
+
#
|
7
|
+
# @example
|
8
|
+
# response = client.number_insight.basic(number: '447700900000')
|
9
|
+
#
|
10
|
+
# @option params [required, String] :number
|
11
|
+
# A single phone number that you need insight about in national or international format.
|
12
|
+
#
|
13
|
+
# @option params [String] :country
|
14
|
+
# If a number does not have a country code or is uncertain, set the two-character country code.
|
15
|
+
# This code must be in ISO 3166-1 alpha-2 format and in upper case. For example, GB or US.
|
16
|
+
# If you set country and number is already in E.164 format, country must match the country code in number.
|
17
|
+
#
|
18
|
+
# @param [Hash] params
|
19
|
+
#
|
20
|
+
# @return [Entity]
|
21
|
+
#
|
22
|
+
# @see https://developer.nexmo.com/api/number-insight#getNumberInsightBasic
|
23
|
+
#
|
5
24
|
def basic(params)
|
6
25
|
request('/ni/basic/json', params: params)
|
7
26
|
end
|
8
27
|
|
28
|
+
# Provides standard number insight information about a number.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# response = client.number_insight.standard(number: '447700900000')
|
32
|
+
#
|
33
|
+
# @option params [required, String] :number
|
34
|
+
# A single phone number that you need insight about in national or international format.
|
35
|
+
#
|
36
|
+
# @option params [String] :country
|
37
|
+
# If a number does not have a country code or is uncertain, set the two-character country code.
|
38
|
+
# This code must be in ISO 3166-1 alpha-2 format and in upper case. For example, GB or US.
|
39
|
+
# If you set country and number is already in E.164 format, country must match the country code in number.
|
40
|
+
#
|
41
|
+
# @option params [Boolean] :cnam
|
42
|
+
# Indicates if the name of the person who owns the phone number should be looked up and returned in the response.
|
43
|
+
# Set to true to receive phone number owner name in the response.
|
44
|
+
# This features is available for US numbers only and incurs an additional charge.
|
45
|
+
#
|
46
|
+
# @param [Hash] params
|
47
|
+
#
|
48
|
+
# @return [Entity]
|
49
|
+
#
|
50
|
+
# @see https://developer.nexmo.com/api/number-insight#getNumberInsightStandard
|
51
|
+
#
|
9
52
|
def standard(params)
|
10
53
|
request('/ni/standard/json', params: params)
|
11
54
|
end
|
12
55
|
|
56
|
+
# Provides advanced number insight information about a number synchronously.
|
57
|
+
#
|
58
|
+
# @example
|
59
|
+
# response = client.number_insight.advanced(number: '447700900000')
|
60
|
+
#
|
61
|
+
# @option params [required, String] :number
|
62
|
+
# A single phone number that you need insight about in national or international format.
|
63
|
+
#
|
64
|
+
# @option params [String] :country
|
65
|
+
# If a number does not have a country code or is uncertain, set the two-character country code.
|
66
|
+
# This code must be in ISO 3166-1 alpha-2 format and in upper case. For example, GB or US.
|
67
|
+
# If you set country and number is already in E.164 format, country must match the country code in number.
|
68
|
+
#
|
69
|
+
# @option params [Boolean] :cnam
|
70
|
+
# Indicates if the name of the person who owns the phone number should be looked up and returned in the response.
|
71
|
+
# Set to true to receive phone number owner name in the response.
|
72
|
+
# This features is available for US numbers only and incurs an additional charge.
|
73
|
+
#
|
74
|
+
# @option params [String] :ip
|
75
|
+
# The IP address of the user.
|
76
|
+
# If supplied, we will compare this to the country the user's phone is located in and return an error if it does not match.
|
77
|
+
#
|
78
|
+
# @param [Hash] params
|
79
|
+
#
|
80
|
+
# @return [Entity]
|
81
|
+
#
|
82
|
+
# @see https://developer.nexmo.com/api/number-insight#getNumberInsightAdvanced
|
83
|
+
#
|
13
84
|
def advanced(params)
|
14
85
|
request('/ni/advanced/json', params: params)
|
15
86
|
end
|
16
87
|
|
88
|
+
# Provides advanced number insight number information *asynchronously* using the URL specified in the callback parameter.
|
89
|
+
#
|
90
|
+
# @example
|
91
|
+
# response = client.number_insight.advanced_async(number: '447700900000', callback: webhook_url)
|
92
|
+
#
|
93
|
+
# @option params [required, String] :callback
|
94
|
+
# The callback URL.
|
95
|
+
#
|
96
|
+
# @option params [required, String] :number
|
97
|
+
# A single phone number that you need insight about in national or international format.
|
98
|
+
#
|
99
|
+
# @option params [String] :country
|
100
|
+
# If a number does not have a country code or is uncertain, set the two-character country code.
|
101
|
+
# This code must be in ISO 3166-1 alpha-2 format and in upper case. For example, GB or US.
|
102
|
+
# If you set country and number is already in E.164 format, country must match the country code in number.
|
103
|
+
#
|
104
|
+
# @option params [Boolean] :cnam
|
105
|
+
# Indicates if the name of the person who owns the phone number should be looked up and returned in the response.
|
106
|
+
# Set to true to receive phone number owner name in the response.
|
107
|
+
# This features is available for US numbers only and incurs an additional charge.
|
108
|
+
#
|
109
|
+
# @option params [String] :ip
|
110
|
+
# The IP address of the user.
|
111
|
+
# If supplied, we will compare this to the country the user's phone is located in and return an error if it does not match.
|
112
|
+
#
|
113
|
+
# @param [Hash] params
|
114
|
+
#
|
115
|
+
# @return [Entity]
|
116
|
+
#
|
117
|
+
# @see https://developer.nexmo.com/api/number-insight#getNumberInsightAsync
|
118
|
+
#
|
17
119
|
def advanced_async(params)
|
18
120
|
request('/ni/advanced/async/json', params: params)
|
19
121
|
end
|
data/lib/nexmo/numbers.rb
CHANGED
@@ -6,22 +6,177 @@ module Nexmo
|
|
6
6
|
|
7
7
|
self.host = 'rest.nexmo.com'
|
8
8
|
|
9
|
+
# Retrieve all the inbound numbers associated with your Nexmo account.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# response = client.numbers.list
|
13
|
+
# response.numbers.each do |item|
|
14
|
+
# puts "#{item.msisdn} #{item.country} #{item.type}"
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# @option params [Integer] :index
|
18
|
+
# Page index.
|
19
|
+
#
|
20
|
+
# @option params [Integer] :size
|
21
|
+
# Page size.
|
22
|
+
#
|
23
|
+
# @option params [String] :pattern
|
24
|
+
# The number pattern you want to search for. Use in conjunction with **:search_pattern**.
|
25
|
+
#
|
26
|
+
# @option params [Integer] :search_pattern
|
27
|
+
# The strategy you want to use for matching:
|
28
|
+
# - `0` - Search for numbers that start with **:pattern**
|
29
|
+
# - `1` - Search for numbers that contain **:pattern**
|
30
|
+
# - `2` - Search for numbers that end with **:pattern**
|
31
|
+
#
|
32
|
+
# @param [Hash] params
|
33
|
+
#
|
34
|
+
# @return [Entity]
|
35
|
+
#
|
36
|
+
# @see https://developer.nexmo.com/api/developer/numbers#getOwnedNumbers
|
37
|
+
#
|
9
38
|
def list(params = nil)
|
10
39
|
request('/account/numbers', params: params)
|
11
40
|
end
|
12
41
|
|
42
|
+
# Retrieve inbound numbers that are available for the specified country.
|
43
|
+
#
|
44
|
+
# @example
|
45
|
+
# response = client.numbers.search(country: 'GB')
|
46
|
+
# response.numbers.each do |item|
|
47
|
+
# puts "#{item.msisdn} #{item.type} #{item.cost}"
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# @option params [required, String] :country
|
51
|
+
# The two character country code in ISO 3166-1 alpha-2 format.
|
52
|
+
#
|
53
|
+
# @option params [String] :type
|
54
|
+
# Set this parameter to filter the type of number, such as mobile or landline.
|
55
|
+
#
|
56
|
+
# @option params [String] :pattern
|
57
|
+
# The number pattern you want to search for.
|
58
|
+
# Use in conjunction with **:search_pattern**.
|
59
|
+
#
|
60
|
+
# @option params [Integer] :search_pattern
|
61
|
+
# The strategy you want to use for matching:
|
62
|
+
# - `0` - Search for numbers that start with **:pattern**
|
63
|
+
# - `1` - Search for numbers that contain **:pattern**
|
64
|
+
# - `2` - Search for numbers that end with **:pattern**
|
65
|
+
#
|
66
|
+
# @option params [String] :features
|
67
|
+
# Available features are `SMS` and `VOICE`.
|
68
|
+
# To look for numbers that support both, use a comma-separated value: `SMS,VOICE`.
|
69
|
+
#
|
70
|
+
# @option params [Integer] :size
|
71
|
+
# Page size.
|
72
|
+
#
|
73
|
+
# @option params [Integer] :index
|
74
|
+
# Page index.
|
75
|
+
#
|
76
|
+
# @param [Hash] params
|
77
|
+
#
|
78
|
+
# @return [Entity]
|
79
|
+
#
|
80
|
+
# @see https://developer.nexmo.com/api/developer/numbers#getAvailableNumbers
|
81
|
+
#
|
13
82
|
def search(params)
|
14
83
|
request('/number/search', params: params)
|
15
84
|
end
|
16
85
|
|
86
|
+
# Request to purchase a specific inbound number.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# response = client.numbers.buy(country: 'GB', msisdn: '447700900000')
|
90
|
+
#
|
91
|
+
# @option params [required, String] :country
|
92
|
+
# The two character country code in ISO 3166-1 alpha-2 format.
|
93
|
+
#
|
94
|
+
# @option params [required, String] :msisdn
|
95
|
+
# An available inbound virtual number.
|
96
|
+
#
|
97
|
+
# @param [Hash] params
|
98
|
+
#
|
99
|
+
# @return [Entity]
|
100
|
+
#
|
101
|
+
# @see https://developer.nexmo.com/api/developer/numbers#buyANumber
|
102
|
+
#
|
17
103
|
def buy(params)
|
18
104
|
request('/number/buy', params: params, type: Post)
|
19
105
|
end
|
20
106
|
|
107
|
+
# Cancel your subscription for a specific inbound number.
|
108
|
+
#
|
109
|
+
# @example
|
110
|
+
# response = client.numbers.cancel(country: 'GB', msisdn: '447700900000')
|
111
|
+
#
|
112
|
+
# @option params [required, String] :country
|
113
|
+
# The two character country code in ISO 3166-1 alpha-2 format.
|
114
|
+
#
|
115
|
+
# @option params [required, String] :msisdn
|
116
|
+
# An available inbound virtual number.
|
117
|
+
#
|
118
|
+
# @param [Hash] params
|
119
|
+
#
|
120
|
+
# @return [Entity]
|
121
|
+
#
|
122
|
+
# @see https://developer.nexmo.com/api/developer/numbers#cancelANumber
|
123
|
+
#
|
21
124
|
def cancel(params)
|
22
125
|
request('/number/cancel', params: params, type: Post)
|
23
126
|
end
|
24
127
|
|
128
|
+
# Change the behaviour of a number that you own.
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# params = {
|
132
|
+
# country: 'GB',
|
133
|
+
# msisdn: '447700900000',
|
134
|
+
# voice_callback_type: 'app',
|
135
|
+
# voice_callback_value: application_id
|
136
|
+
# }
|
137
|
+
#
|
138
|
+
# response = client.numbers.update(params)
|
139
|
+
#
|
140
|
+
# @option params [required, String] :country
|
141
|
+
# The two character country code in ISO 3166-1 alpha-2 format.
|
142
|
+
#
|
143
|
+
# @option params [required, String] :msisdn
|
144
|
+
# An available inbound virtual number.
|
145
|
+
#
|
146
|
+
# @option params [String] :mo_http_url
|
147
|
+
# An URL-encoded URI to the webhook endpoint that handles inbound messages.
|
148
|
+
# Your webhook endpoint must be active before you make this request.
|
149
|
+
# Nexmo makes a `GET` request to the endpoint and checks that it returns a `200 OK` response.
|
150
|
+
# Set this parameter's value to an empty string to remove the webhook.
|
151
|
+
#
|
152
|
+
# @option params [String] :mo_smpp_sys_type
|
153
|
+
# The associated system type for your SMPP client.
|
154
|
+
#
|
155
|
+
# @option params [String] :messages_callback_type
|
156
|
+
# The SMS webhook type (always `app`).
|
157
|
+
# Must be used with the **:messages_callback_value** option.
|
158
|
+
#
|
159
|
+
# @option params [String] :messages_callback_value
|
160
|
+
# A Nexmo Application ID.
|
161
|
+
# Must be used with the **:messages_callback_type** option.
|
162
|
+
#
|
163
|
+
# @option params [String] :voice_callback_type
|
164
|
+
# The voice webhook type.
|
165
|
+
# Must be used with the **:voice_callback_value** option.
|
166
|
+
#
|
167
|
+
# @option params [String] :voice_callback_value
|
168
|
+
# A SIP URI, telephone number or Application ID.
|
169
|
+
# Must be used with the **:voice_callback_type** option.
|
170
|
+
#
|
171
|
+
# @option params [String] :voice_status_callback
|
172
|
+
# A webhook URI for Nexmo to send a request to when a call ends.
|
173
|
+
#
|
174
|
+
# @param [Hash] params
|
175
|
+
#
|
176
|
+
# @return [Entity]
|
177
|
+
#
|
178
|
+
# @see https://developer.nexmo.com/api/developer/numbers#updateANumber
|
179
|
+
#
|
25
180
|
def update(params)
|
26
181
|
request('/number/update', params: camelcase(params), type: Post)
|
27
182
|
end
|