plivo 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/plivo/base/resource.rb +2 -2
- data/lib/plivo/base/resource_interface.rb +2 -2
- data/lib/plivo/resources.rb +2 -0
- data/lib/plivo/resources/addresses.rb +302 -0
- data/lib/plivo/resources/calls.rb +1 -0
- data/lib/plivo/resources/identities.rb +319 -0
- data/lib/plivo/resources/numbers.rb +19 -3
- data/lib/plivo/rest_client.rb +36 -7
- data/lib/plivo/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f175349919f9673146aa1ff209cb04f858fb7b3d
|
4
|
+
data.tar.gz: 70f9007164e621fbd5a907a65fe9c9473982a8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e62b19ef47a2a306e05a75a4acf531dacf7259dd1a92bebc2e4e97322fcf6892891490e860898a06e5163e8ee1748dd9fc9f575ba7fb5cb271867d5599ae66b
|
7
|
+
data.tar.gz: f56366f71dea549499326685b43aabeff5730db7a157b862b52c7cfa78ebc7d64c89422685e3541f57f66c971cb5524378981d6bc5d832b4c9d80c871b8f5cd8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [4.1.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.1.0) (2018-02-26)
|
4
|
+
- Add Address and Identity resources
|
5
|
+
- Change a few functions in number-related methods to support the verification flows
|
6
|
+
|
3
7
|
## [4.0.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.0.0) (2018-01-18)
|
4
8
|
- Now supports timeout & proxy (in a non-deprecated way) settings
|
5
9
|
- A bug fixed (#55)
|
data/README.md
CHANGED
data/lib/plivo/base/resource.rb
CHANGED
@@ -50,13 +50,13 @@ module Plivo
|
|
50
50
|
@id = resource_json[@_identifier_string]
|
51
51
|
end
|
52
52
|
|
53
|
-
def perform_update(params)
|
53
|
+
def perform_update(params, use_multipart_conn = false)
|
54
54
|
unless @id
|
55
55
|
raise_invalid_request("Cannot update a #{@_name} resource "\
|
56
56
|
'without an identifier')
|
57
57
|
end
|
58
58
|
|
59
|
-
response_json = @_client.send_request(@_resource_uri, 'POST', params)
|
59
|
+
response_json = @_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn)
|
60
60
|
|
61
61
|
parse_and_set(params)
|
62
62
|
parse_and_set(response_json)
|
@@ -51,9 +51,9 @@ module Plivo
|
|
51
51
|
@_resource_type.new(@_client, resource_json: response_json)
|
52
52
|
end
|
53
53
|
|
54
|
-
def perform_create(params)
|
54
|
+
def perform_create(params, use_multipart_conn=false)
|
55
55
|
Response.new(
|
56
|
-
@_client.send_request(@_resource_uri, 'POST', params),
|
56
|
+
@_client.send_request(@_resource_uri, 'POST', params, nil, use_multipart_conn),
|
57
57
|
@_identifier_string
|
58
58
|
)
|
59
59
|
end
|
data/lib/plivo/resources.rb
CHANGED
@@ -7,6 +7,8 @@ require_relative 'resources/numbers'
|
|
7
7
|
require_relative 'resources/conferences'
|
8
8
|
require_relative 'resources/calls'
|
9
9
|
require_relative 'resources/endpoints'
|
10
|
+
require_relative 'resources/addresses'
|
11
|
+
require_relative 'resources/identities'
|
10
12
|
|
11
13
|
module Plivo
|
12
14
|
module Resources
|
@@ -0,0 +1,302 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
class Address < Base::Resource
|
5
|
+
|
6
|
+
def initialize(client, options = nil)
|
7
|
+
@_name = 'Verification/Address'
|
8
|
+
@_identifier_string = 'id'
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete
|
13
|
+
perform_delete
|
14
|
+
end
|
15
|
+
|
16
|
+
##
|
17
|
+
# Update an address
|
18
|
+
# @param [String] file_to_upload
|
19
|
+
# @param [Hash] options
|
20
|
+
# @option options [String] :salutation - One of Mr or Ms
|
21
|
+
# @option options [String] :first_name - First name of the user for whom the address is created
|
22
|
+
# @option options [String] :last_name - Last name of the user for whom the address is created
|
23
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
24
|
+
# @option options [String] :address_line1 - Building name/number
|
25
|
+
# @option options [String] :address_line2 - The street name/number of the address
|
26
|
+
# @option options [String] :city - The city of the address for which the address proof is created
|
27
|
+
# @option options [String] :region - The region of the address for which the address proof is created
|
28
|
+
# @option options [String] :postal_code - The postal code of the address that is being created
|
29
|
+
# @option options [String] :alias - Alias name of the address
|
30
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
31
|
+
# @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to.
|
32
|
+
# @return [Address] Address
|
33
|
+
def update(file_to_upload = nil, options = nil)
|
34
|
+
params = {}
|
35
|
+
|
36
|
+
unless options.nil?
|
37
|
+
%i[salutation first_name last_name country_iso address_line1 address_line2 city region postal_code alias callback_url]
|
38
|
+
.each do |param|
|
39
|
+
if options.key?(param) &&
|
40
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
41
|
+
params[param] = options[param]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
%i[auto_correct_address]
|
46
|
+
.each do |param|
|
47
|
+
if options.key?(param) &&
|
48
|
+
valid_param?(param, options[param], nil, true, [true, false])
|
49
|
+
params[param] = options[param]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
unless file_to_upload.nil?
|
55
|
+
file_extension = file_to_upload.split('.')[-1]
|
56
|
+
|
57
|
+
content_type = case file_extension
|
58
|
+
when 'jpeg' then 'image/jpeg'
|
59
|
+
when 'jpg' then 'image/jpeg'
|
60
|
+
when 'png' then 'image/png'
|
61
|
+
when 'pdf' then 'application/pdf'
|
62
|
+
else raise_invalid_request("#{file_extension} is not yet supported for upload")
|
63
|
+
end
|
64
|
+
|
65
|
+
params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
|
66
|
+
end
|
67
|
+
|
68
|
+
return perform_update(params, true)
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_s
|
72
|
+
{
|
73
|
+
account: @account,
|
74
|
+
address_line1: @address_line1,
|
75
|
+
address_line2: @address_line2,
|
76
|
+
alias: @alias,
|
77
|
+
api_id: @api_id,
|
78
|
+
city: @city,
|
79
|
+
country_iso: @country_iso,
|
80
|
+
document_details: @document_details,
|
81
|
+
first_name: @first_name,
|
82
|
+
id: @id,
|
83
|
+
last_name: @last_name,
|
84
|
+
postal_code: @postal_code,
|
85
|
+
region: @region,
|
86
|
+
salutation: @salutation,
|
87
|
+
subaccount: @subaccount,
|
88
|
+
url: @url,
|
89
|
+
validation_status: @validation_status,
|
90
|
+
verification_status: @verification_status
|
91
|
+
}.to_s
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class AddressInterface < Base::ResourceInterface
|
96
|
+
def initialize(client, resource_list_json = nil)
|
97
|
+
@_name = 'Verification/Address'
|
98
|
+
@_resource_type = Address
|
99
|
+
@_identifier_string = 'id'
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Get an address
|
105
|
+
# @param [String] address_id
|
106
|
+
# @return [Address] Address
|
107
|
+
def get(address_id)
|
108
|
+
valid_param?(:address_id, address_id, [String, Symbol], true)
|
109
|
+
perform_get(address_id)
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# List all addresses
|
114
|
+
# @param [Hash] options
|
115
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
116
|
+
# @option options [String] :customer_name - Name of the customer or business that is mentioned in the address
|
117
|
+
# @option options [String] :alias - Friendly name of the id proof
|
118
|
+
# @option options [String] :verification_status - The status of the address: pending. accepted, rejected, null
|
119
|
+
# @option options [String] :validation_status - The status of the address: pending. accepted, rejected, null
|
120
|
+
# @option options [Int] :offset
|
121
|
+
# @option options [Int] :limit
|
122
|
+
# @return [Hash]
|
123
|
+
def list(options=nil)
|
124
|
+
return perform_list if options.nil?
|
125
|
+
|
126
|
+
params = {}
|
127
|
+
|
128
|
+
%i[country_iso customer_name alias].each do |param|
|
129
|
+
if options.key?(param) && valid_param?(param, options[param],
|
130
|
+
[String, Symbol], true)
|
131
|
+
params[param] = options[param]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
%i[verification_status validation_status].each do |param|
|
136
|
+
if options.key?(param) && valid_param?(param, options[param],
|
137
|
+
[String, Symbol], true, ['pending', 'accepted', 'rejected',
|
138
|
+
:pending, :accepted, :rejected])
|
139
|
+
params[param] = options[param]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
%i[offset limit].each do |param|
|
144
|
+
if options.key?(param) && valid_param?(param, options[param],
|
145
|
+
[Integer], true)
|
146
|
+
params[param] = options[param]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
151
|
+
raise_invalid_request('The maximum number of results that can be '\
|
152
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
153
|
+
end
|
154
|
+
|
155
|
+
if options.key?(:offset) && options[:offset] < 0
|
156
|
+
raise_invalid_request("Offset can't be negative")
|
157
|
+
end
|
158
|
+
|
159
|
+
perform_list(params)
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Create a new address
|
164
|
+
# @param [String] country_iso
|
165
|
+
# @param [String] salutation
|
166
|
+
# @param [String] first_name
|
167
|
+
# @param [String] last_name
|
168
|
+
# @param [String] address_line1
|
169
|
+
# @param [String] address_line2
|
170
|
+
# @param [String] city
|
171
|
+
# @param [String] region
|
172
|
+
# @param [String] postal_code
|
173
|
+
# @param [String] address_proof_type
|
174
|
+
# @param [String] file_to_upload
|
175
|
+
# @param [Hash] options
|
176
|
+
# @option options [String] :alias - Alias name of the address
|
177
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
178
|
+
# @option options [String] :fiscal_identification_code - The code is valid for businesses alone
|
179
|
+
# @option options [String] :street_code - Street code of the address
|
180
|
+
# @option options [String] :municipal_code - Municipal code of the address
|
181
|
+
# @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to.
|
182
|
+
# @return [Address] Address
|
183
|
+
def create(country_iso, salutation, first_name, last_name, address_line1, address_line2, city, region,
|
184
|
+
postal_code, address_proof_type, file_to_upload=nil, options=nil)
|
185
|
+
valid_param?(:country_iso, country_iso, [String, Symbol], true)
|
186
|
+
valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr])
|
187
|
+
valid_param?(:first_name, first_name, [String, Symbol], true)
|
188
|
+
valid_param?(:last_name, last_name, [String, Symbol], true)
|
189
|
+
valid_param?(:address_line1, address_line1, [String, Symbol], true)
|
190
|
+
valid_param?(:address_line2, address_line2, [String, Symbol], true)
|
191
|
+
valid_param?(:city, city, [String, Symbol], true)
|
192
|
+
valid_param?(:region, region, [String, Symbol], true)
|
193
|
+
valid_param?(:postal_code, postal_code, [String, Symbol], true)
|
194
|
+
valid_param?(:address_proof_type,
|
195
|
+
address_proof_type,
|
196
|
+
[String, Symbol], true,
|
197
|
+
['national_id', 'passport', 'business_id', 'NIF', 'NIE', 'DNI', 'others',
|
198
|
+
:national_id, :passport, :business_id, :NIF, :NIE, :DNI, :others])
|
199
|
+
|
200
|
+
params = {
|
201
|
+
country_iso: country_iso,
|
202
|
+
salutation: salutation,
|
203
|
+
first_name: first_name,
|
204
|
+
last_name: last_name,
|
205
|
+
address_line1: address_line1,
|
206
|
+
address_line2: address_line2,
|
207
|
+
city: city,
|
208
|
+
region: region,
|
209
|
+
postal_code: postal_code,
|
210
|
+
address_proof_type: address_proof_type
|
211
|
+
}
|
212
|
+
|
213
|
+
if country_iso == 'ES'
|
214
|
+
valid_param?(:fiscal_identification_code, options[:fiscal_identification_code], [String, Symbol], true)
|
215
|
+
params[:fiscal_identification_code] = options[:fiscal_identification_code]
|
216
|
+
end
|
217
|
+
|
218
|
+
if country_iso == 'DK'
|
219
|
+
valid_param?(:street_code, options[:street_code], [String, Symbol], true)
|
220
|
+
valid_param?(:municipal_code, options[:municipal_code], [String, Symbol], true)
|
221
|
+
|
222
|
+
params[:street_code] = options[:street_code]
|
223
|
+
params[:municipal_code] = options[:municipal_code]
|
224
|
+
end
|
225
|
+
|
226
|
+
unless file_to_upload.nil?
|
227
|
+
file_extension = file_to_upload.split('.')[-1]
|
228
|
+
|
229
|
+
content_type = case file_extension
|
230
|
+
when 'jpeg' then 'image/jpeg'
|
231
|
+
when 'jpg' then 'image/jpeg'
|
232
|
+
when 'png' then 'image/png'
|
233
|
+
when 'pdf' then 'application/pdf'
|
234
|
+
else raise_invalid_request("#{file_extension} is not yet supported for upload")
|
235
|
+
end
|
236
|
+
|
237
|
+
params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
|
238
|
+
end
|
239
|
+
|
240
|
+
%i[alias fiscal_identification_code street_code municipal_code callback_url]
|
241
|
+
.each do |param|
|
242
|
+
if options.key?(param) &&
|
243
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
244
|
+
params[param] = options[param]
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
%i[auto_correct_address]
|
249
|
+
.each do |param|
|
250
|
+
if options.key?(param) &&
|
251
|
+
valid_param?(param, options[param], nil, true, [true, false])
|
252
|
+
params[param] = options[param]
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
perform_create(params, true)
|
257
|
+
end
|
258
|
+
|
259
|
+
##
|
260
|
+
# Update an address
|
261
|
+
# @param [String] address_id
|
262
|
+
# @param [String] file_to_upload
|
263
|
+
# @param [Hash] options
|
264
|
+
# @option options [String] :salutation - One of Mr or Ms
|
265
|
+
# @option options [String] :first_name - First name of the user for whom the address is created
|
266
|
+
# @option options [String] :last_name - Last name of the user for whom the address is created
|
267
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
268
|
+
# @option options [String] :address_line1 - Building name/number
|
269
|
+
# @option options [String] :address_line2 - The street name/number of the address
|
270
|
+
# @option options [String] :city - The city of the address for which the address proof is created
|
271
|
+
# @option options [String] :region - The region of the address for which the address proof is created
|
272
|
+
# @option options [String] :postal_code - The postal code of the address that is being created
|
273
|
+
# @option options [String] :alias - Alias name of the address
|
274
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
275
|
+
# @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to.
|
276
|
+
# @return [Address] Address
|
277
|
+
def update(address_id, file_to_upload=nil, options=nil)
|
278
|
+
Address.new(@_client,
|
279
|
+
resource_id: address_id).update(file_to_upload, options)
|
280
|
+
end
|
281
|
+
|
282
|
+
##
|
283
|
+
# Delete an address
|
284
|
+
# @param [String] address_id
|
285
|
+
def delete(address_id)
|
286
|
+
valid_param?(:address_id, address_id, [String, Symbol], true)
|
287
|
+
Address.new(@_client,
|
288
|
+
resource_id: address_id).delete
|
289
|
+
end
|
290
|
+
|
291
|
+
def each
|
292
|
+
offset = 0
|
293
|
+
loop do
|
294
|
+
address_list = list(offset: offset)
|
295
|
+
address_list[:objects].each { |address| yield address }
|
296
|
+
offset += 20
|
297
|
+
return unless address_list.length == 20
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
@@ -0,0 +1,319 @@
|
|
1
|
+
module Plivo
|
2
|
+
module Resources
|
3
|
+
include Plivo::Utils
|
4
|
+
class Identity < Base::Resource
|
5
|
+
|
6
|
+
def initialize(client, options = nil)
|
7
|
+
@_name = 'Verification/Identity'
|
8
|
+
@_identifier_string = 'id'
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete
|
13
|
+
perform_delete
|
14
|
+
end
|
15
|
+
|
16
|
+
# Update an identity
|
17
|
+
# @param [String] identity_id
|
18
|
+
# @param [String] file_to_upload
|
19
|
+
# @param [Hash] options
|
20
|
+
# @option options [String] :salutation - One of Mr or Ms
|
21
|
+
# @option options [String] :first_name - First name of the user for whom the identity is created
|
22
|
+
# @option options [String] :last_name - Last name of the user for whom the identity is created
|
23
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
24
|
+
# @option options [String] :birth_place - Birthplace of the user for whom the identity is created
|
25
|
+
# @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created
|
26
|
+
# @option options [String] :nationality - Nationality of the user for whom the identity is created
|
27
|
+
# @option options [String] :id_nationality - Nationality mentioned in the identity proof
|
28
|
+
# @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof
|
29
|
+
# @option options [String] :id_type -
|
30
|
+
# @option options [String] :id_number - The unique number on the identifier
|
31
|
+
# @option options [String] :address_line1 - Building name/number
|
32
|
+
# @option options [String] :address_line2 - The street name/number of the address
|
33
|
+
# @option options [String] :city - The city of the address for which the address proof is created
|
34
|
+
# @option options [String] :region - The region of the address for which the address proof is created
|
35
|
+
# @option options [String] :postal_code - The postal code of the address that is being created
|
36
|
+
# @option options [String] :alias - Alias name of the identity
|
37
|
+
# @option options [String] :business_name - Business name of the user for whom the identity is created.
|
38
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
39
|
+
# @option options [String] :fiscal_identification_code - The code is valid for businesses alone
|
40
|
+
# @option options [String] :street_code - Street code of the address
|
41
|
+
# @option options [String] :municipal_code - Municipal code of the address
|
42
|
+
# @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
|
43
|
+
# @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
|
44
|
+
# @return [Identity] Identity
|
45
|
+
def update(file_to_upload = nil, options = nil)
|
46
|
+
params = {}
|
47
|
+
|
48
|
+
unless options.nil?
|
49
|
+
%i[salutation first_name last_name country_iso birth_place birth_date nationality id_nationality id_issue_date
|
50
|
+
id_type id_number address_line1 address_line2 city region postal_code alias business_name
|
51
|
+
fiscal_identification_code street_code municipal_code callback_url subaccount
|
52
|
+
]
|
53
|
+
.each do |param|
|
54
|
+
if options.key?(param) &&
|
55
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
56
|
+
params[param] = options[param]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
%i[auto_correct_address]
|
61
|
+
.each do |param|
|
62
|
+
if options.key?(param) &&
|
63
|
+
valid_param?(param, options[param], nil, true, [true, false])
|
64
|
+
params[param] = options[param]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
unless file_to_upload.nil?
|
70
|
+
file_extension = file_to_upload.split('.')[-1]
|
71
|
+
|
72
|
+
content_type = case file_extension
|
73
|
+
when 'jpeg' then 'image/jpeg'
|
74
|
+
when 'jpg' then 'image/jpeg'
|
75
|
+
when 'png' then 'image/png'
|
76
|
+
when 'pdf' then 'application/pdf'
|
77
|
+
else raise_invalid_request("#{file_extension} is not yet supported for upload")
|
78
|
+
end
|
79
|
+
|
80
|
+
params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
|
81
|
+
end
|
82
|
+
|
83
|
+
return perform_update(params, true)
|
84
|
+
end
|
85
|
+
|
86
|
+
def to_s
|
87
|
+
{
|
88
|
+
account: @account,
|
89
|
+
alias: @alias,
|
90
|
+
api_id: @api_id,
|
91
|
+
country_iso: @country_iso,
|
92
|
+
document_details: @document_details,
|
93
|
+
first_name: @first_name,
|
94
|
+
id: @id,
|
95
|
+
id_number: @id_number,
|
96
|
+
id_type: @id_type,
|
97
|
+
last_name: @last_name,
|
98
|
+
nationality: @nationality,
|
99
|
+
salutation: @salutation,
|
100
|
+
subaccount: @subaccount,
|
101
|
+
url: @url,
|
102
|
+
validation_status: @validation_status,
|
103
|
+
verification_status: @verification_status
|
104
|
+
}.to_s
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
class IdentityInterface < Base::ResourceInterface
|
109
|
+
def initialize(client, resource_list_json = nil)
|
110
|
+
@_name = 'Verification/Identity'
|
111
|
+
@_resource_type = Identity
|
112
|
+
@_identifier_string = 'id'
|
113
|
+
super
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Get an identity
|
118
|
+
# @param [String] identity_id
|
119
|
+
# @return [Identity] Identity
|
120
|
+
def get(identity_id)
|
121
|
+
valid_param?(:identity_id, identity_id, [String, Symbol], true)
|
122
|
+
perform_get(identity_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# List all identities
|
127
|
+
# @param [Hash] options
|
128
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
129
|
+
# @option options [String] :customer_name - Name of the customer or business that is mentioned in the identity
|
130
|
+
# @option options [String] :alias - Friendly name of the id proof
|
131
|
+
# @option options [String] :verification_status - The status of the identity: pending. accepted, rejected, null
|
132
|
+
# @option options [Int] :offset
|
133
|
+
# @option options [Int] :limit
|
134
|
+
# @return [Hash]
|
135
|
+
def list(options=nil)
|
136
|
+
return perform_list if options.nil?
|
137
|
+
|
138
|
+
params = {}
|
139
|
+
|
140
|
+
%i[country_iso customer_name alias].each do |param|
|
141
|
+
if options.key?(param) && valid_param?(param, options[param],
|
142
|
+
[String, Symbol], true)
|
143
|
+
params[param] = options[param]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
%i[verification_status].each do |param|
|
148
|
+
if options.key?(param) && valid_param?(param, options[param],
|
149
|
+
[String, Symbol], true, ['pending', 'accepted', 'rejected',
|
150
|
+
:pending, :accepted, :rejected])
|
151
|
+
params[param] = options[param]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
%i[offset limit].each do |param|
|
156
|
+
if options.key?(param) && valid_param?(param, options[param],
|
157
|
+
[Integer], true)
|
158
|
+
params[param] = options[param]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
163
|
+
raise_invalid_request('The maximum number of results that can be '\
|
164
|
+
"fetched is 20. limit can't be more than 20 or less than 1")
|
165
|
+
end
|
166
|
+
|
167
|
+
if options.key?(:offset) && options[:offset] < 0
|
168
|
+
raise_invalid_request("Offset can't be negative")
|
169
|
+
end
|
170
|
+
|
171
|
+
perform_list(params)
|
172
|
+
end
|
173
|
+
|
174
|
+
##
|
175
|
+
# Create a new identity
|
176
|
+
# @param [String] country_iso
|
177
|
+
# @param [String] salutation
|
178
|
+
# @param [String] first_name
|
179
|
+
# @param [String] last_name
|
180
|
+
# @param [String] birth_place
|
181
|
+
# @param [String] birth_date
|
182
|
+
# @param [String] nationality
|
183
|
+
# @param [String] id_nationality
|
184
|
+
# @param [String] id_issue_date
|
185
|
+
# @param [String] id_type
|
186
|
+
# @param [String] id_number
|
187
|
+
# @param [String] address_line1
|
188
|
+
# @param [String] address_line2
|
189
|
+
# @param [String] city
|
190
|
+
# @param [String] region
|
191
|
+
# @param [String] postal_code
|
192
|
+
# @param [String] file_to_upload
|
193
|
+
# @param [Hash] options
|
194
|
+
# @option options [String] :alias - Alias name of the identity
|
195
|
+
# @option options [String] :business_name - Business name of the user for whom the identity is created.
|
196
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
197
|
+
# @option options [String] :fiscal_identification_code - The code is valid for businesses alone
|
198
|
+
# @option options [String] :street_code - Street code of the address
|
199
|
+
# @option options [String] :municipal_code - Municipal code of the address
|
200
|
+
# @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
|
201
|
+
# @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
|
202
|
+
# @return [Identity] Identity
|
203
|
+
def create(country_iso, salutation, first_name, last_name, birth_place, birth_date, nationality,
|
204
|
+
id_nationality, id_issue_date, id_type, id_number, address_line1, address_line2,
|
205
|
+
city, region, postal_code, file_to_upload=nil, options=nil)
|
206
|
+
valid_param?(:country_iso, country_iso, [String, Symbol], true)
|
207
|
+
valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr])
|
208
|
+
valid_param?(:first_name, first_name, [String, Symbol], true)
|
209
|
+
valid_param?(:last_name, last_name, [String, Symbol], true)
|
210
|
+
valid_param?(:birth_place, birth_place, [String, Symbol], true)
|
211
|
+
valid_param?(:birth_date, birth_date, [String, Symbol], true)
|
212
|
+
valid_param?(:nationality, nationality, [String, Symbol], true)
|
213
|
+
valid_param?(:id_nationality, id_nationality, [String, Symbol], true)
|
214
|
+
valid_param?(:id_issue_date, id_issue_date, [String, Symbol], true)
|
215
|
+
valid_param?(:id_type, id_type, [String, Symbol], true)
|
216
|
+
valid_param?(:id_number, id_number, [String, Symbol], true)
|
217
|
+
valid_param?(:address_line1, address_line1, [String, Symbol], true)
|
218
|
+
valid_param?(:address_line2, address_line2, [String, Symbol], true)
|
219
|
+
valid_param?(:city, city, [String, Symbol], true)
|
220
|
+
valid_param?(:region, region, [String, Symbol], true)
|
221
|
+
valid_param?(:postal_code, postal_code, [String, Symbol], true)
|
222
|
+
|
223
|
+
params = {
|
224
|
+
country_iso: country_iso,
|
225
|
+
salutation: salutation,
|
226
|
+
first_name: first_name,
|
227
|
+
last_name: last_name,
|
228
|
+
birth_place: birth_place,
|
229
|
+
birth_date: birth_date,
|
230
|
+
nationality: nationality,
|
231
|
+
id_nationality: id_nationality,
|
232
|
+
id_issue_date: id_issue_date,
|
233
|
+
id_type: id_type,
|
234
|
+
id_number: id_number,
|
235
|
+
address_line1: address_line1,
|
236
|
+
address_line2: address_line2,
|
237
|
+
city: city,
|
238
|
+
region: region,
|
239
|
+
postal_code: postal_code
|
240
|
+
}
|
241
|
+
|
242
|
+
unless file_to_upload.nil?
|
243
|
+
file_extension = file_to_upload.split('.')[-1]
|
244
|
+
|
245
|
+
content_type = case file_extension
|
246
|
+
when 'jpeg' then 'image/jpeg'
|
247
|
+
when 'jpg' then 'image/jpeg'
|
248
|
+
when 'png' then 'image/png'
|
249
|
+
when 'pdf' then 'application/pdf'
|
250
|
+
else raise_invalid_request("#{file_extension} is not yet supported for upload")
|
251
|
+
end
|
252
|
+
|
253
|
+
params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
|
254
|
+
end
|
255
|
+
|
256
|
+
%i[alias business_name fiscal_identification_code street_code municipal_code callback_url subaccount]
|
257
|
+
.each do |param|
|
258
|
+
if options.key?(param) &&
|
259
|
+
valid_param?(param, options[param], [String, Symbol], true)
|
260
|
+
params[param] = options[param]
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
%i[auto_correct_address]
|
265
|
+
.each do |param|
|
266
|
+
if options.key?(param) &&
|
267
|
+
valid_param?(param, options[param], nil, true, [true, false])
|
268
|
+
params[param] = options[param]
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
perform_create(params, true)
|
273
|
+
end
|
274
|
+
|
275
|
+
# Update an identity
|
276
|
+
# @param [String] identity_id
|
277
|
+
# @param [String] file_to_upload
|
278
|
+
# @param [Hash] options
|
279
|
+
# @option options [String] :salutation - One of Mr or Ms
|
280
|
+
# @option options [String] :first_name - First name of the user for whom the identity is created
|
281
|
+
# @option options [String] :last_name - Last name of the user for whom the identity is created
|
282
|
+
# @option options [String] :country_iso - Country ISO 2 code
|
283
|
+
# @option options [String] :birth_place - Birthplace of the user for whom the identity is created
|
284
|
+
# @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created
|
285
|
+
# @option options [String] :nationality - Nationality of the user for whom the identity is created
|
286
|
+
# @option options [String] :id_nationality - Nationality mentioned in the identity proof
|
287
|
+
# @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof
|
288
|
+
# @option options [String] :id_type -
|
289
|
+
# @option options [String] :id_number - The unique number on the identifier
|
290
|
+
# @option options [String] :address_line1 - Building name/number
|
291
|
+
# @option options [String] :address_line2 - The street name/number of the address
|
292
|
+
# @option options [String] :city - The city of the address for which the address proof is created
|
293
|
+
# @option options [String] :region - The region of the address for which the address proof is created
|
294
|
+
# @option options [String] :postal_code - The postal code of the address that is being created
|
295
|
+
# @option options [String] :alias - Alias name of the identity
|
296
|
+
# @option options [String] :business_name - Business name of the user for whom the identity is created.
|
297
|
+
# @option options [String] :auto_correct_address - If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.
|
298
|
+
# @option options [String] :fiscal_identification_code - The code is valid for businesses alone
|
299
|
+
# @option options [String] :street_code - Street code of the address
|
300
|
+
# @option options [String] :municipal_code - Municipal code of the address
|
301
|
+
# @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to.
|
302
|
+
# @option options [String] :subaccount - The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.
|
303
|
+
# @return [Identity] Identity
|
304
|
+
def update(identity_id, file_to_upload=nil, options=nil)
|
305
|
+
Identity.new(@_client,
|
306
|
+
resource_id: identity_id).update(file_to_upload, options)
|
307
|
+
end
|
308
|
+
|
309
|
+
##
|
310
|
+
# Delete an identity
|
311
|
+
# @param [String] identity_id
|
312
|
+
def delete(identity_id)
|
313
|
+
valid_param?(:identity_id, identity_id, [String, Symbol], true)
|
314
|
+
Identity.new(@_client,
|
315
|
+
resource_id: identity_id).delete
|
316
|
+
end
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
@@ -9,9 +9,10 @@ module Plivo
|
|
9
9
|
super
|
10
10
|
end
|
11
11
|
|
12
|
-
def buy(app_id = nil)
|
12
|
+
def buy(app_id = nil, verification_info = nil)
|
13
13
|
params = {}
|
14
14
|
params[:app_id] = app_id unless app_id.nil?
|
15
|
+
params[:verification_info] = verification_info unless verification_info.nil?
|
15
16
|
perform_action(nil, 'POST', params, true)
|
16
17
|
end
|
17
18
|
|
@@ -58,6 +59,7 @@ module Plivo
|
|
58
59
|
# - By default, numbers that have either voice or sms or both enabled are returned.
|
59
60
|
# @option options [String] :lata Numbers can be searched using Local Access and Transport Area {http://en.wikipedia.org/wiki/Local_access_and_transport_area}. This filter is applicable only for country_iso US and CA.
|
60
61
|
# @option options [String] :rate_center Numbers can be searched using Rate Center {http://en.wikipedia.org/wiki/Telephone_exchange}. This filter is application only for country_iso US and CA.
|
62
|
+
# @option options [Boolean] :eligible If set to true, lists only those numbers that you are eligible to buy at the moment. To list all numbers, ignore this option.
|
61
63
|
# @option options [Int] :limit Used to display the number of results per page. The maximum number of results that can be fetched is 20.
|
62
64
|
# @option options [Int] :offset Denotes the number of value items by which the results should be offset. Eg:- If the result contains a 1000 values and limit is set to 10 and offset is set to 705, then values 706 through 715 are displayed in the results. This parameter is also used for pagination of the results.
|
63
65
|
def search(country_iso, options = nil)
|
@@ -83,6 +85,13 @@ module Plivo
|
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
88
|
+
%i[eligible].each do |param|
|
89
|
+
if options.key?(param) && valid_param?(param, options[param],
|
90
|
+
nil, true, [true, false])
|
91
|
+
params[param] = options[param]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
86
95
|
if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
|
87
96
|
raise_invalid_request('The maximum number of results that can be '\
|
88
97
|
"fetched is 20. limit can't be more than 20 or less than 1")
|
@@ -105,10 +114,10 @@ module Plivo
|
|
105
114
|
end
|
106
115
|
end
|
107
116
|
|
108
|
-
def buy(number, app_id = nil)
|
117
|
+
def buy(number, app_id = nil, verification_info = nil)
|
109
118
|
valid_param?(:number, number, [Integer, String, Symbol], true)
|
110
119
|
PhoneNumber.new(@_client,
|
111
|
-
resource_id: number).buy(app_id)
|
120
|
+
resource_id: number).buy(app_id, verification_info)
|
112
121
|
end
|
113
122
|
end
|
114
123
|
|
@@ -136,6 +145,13 @@ module Plivo
|
|
136
145
|
end
|
137
146
|
end
|
138
147
|
|
148
|
+
%i[verification_info].each do |param|
|
149
|
+
if options.key?(param) &&
|
150
|
+
valid_param?(param, options[param], Hash, true)
|
151
|
+
params[param] = options[param]
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
139
155
|
perform_update(params)
|
140
156
|
end
|
141
157
|
|
data/lib/plivo/rest_client.rb
CHANGED
@@ -18,6 +18,7 @@ module Plivo
|
|
18
18
|
attr_reader :messages, :account, :subaccounts, :recordings
|
19
19
|
attr_reader :pricings, :numbers, :calls, :conferences
|
20
20
|
attr_reader :phone_numbers, :applications, :endpoints
|
21
|
+
attr_reader :addresses, :identities
|
21
22
|
|
22
23
|
def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout=5)
|
23
24
|
configure_credentials(auth_id, auth_token)
|
@@ -46,12 +47,12 @@ module Plivo
|
|
46
47
|
response[:body]
|
47
48
|
end
|
48
49
|
|
49
|
-
def send_request(resource_path, method = 'GET', data = {}, timeout = nil)
|
50
|
+
def send_request(resource_path, method = 'GET', data = {}, timeout = nil, use_multipart_conn = false)
|
50
51
|
timeout ||= @timeout
|
51
52
|
|
52
53
|
response = case method
|
53
54
|
when 'GET' then send_get(resource_path, data, timeout)
|
54
|
-
when 'POST' then send_post(resource_path, data, timeout)
|
55
|
+
when 'POST' then send_post(resource_path, data, timeout, use_multipart_conn)
|
55
56
|
when 'DELETE' then send_delete(resource_path, timeout)
|
56
57
|
else raise_invalid_request("#{method} not supported by Plivo, yet")
|
57
58
|
end
|
@@ -121,6 +122,8 @@ module Plivo
|
|
121
122
|
@calls = Resources::CallInterface.new(self)
|
122
123
|
@endpoints = Resources::EndpointInterface.new(self)
|
123
124
|
@applications = Resources::ApplicationInterface.new(self)
|
125
|
+
@addresses = Resources::AddressInterface.new(self)
|
126
|
+
@identities = Resources::IdentityInterface.new(self)
|
124
127
|
end
|
125
128
|
|
126
129
|
def configure_connection
|
@@ -146,11 +149,37 @@ module Plivo
|
|
146
149
|
response
|
147
150
|
end
|
148
151
|
|
149
|
-
def send_post(resource_path, data, timeout)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
152
|
+
def send_post(resource_path, data, timeout, use_multipart_conn)
|
153
|
+
if use_multipart_conn
|
154
|
+
multipart_conn = Faraday.new(Base::PLIVO_API_URL) do |faraday|
|
155
|
+
faraday.headers = {
|
156
|
+
'User-Agent' => @headers['User-Agent'],
|
157
|
+
'Accept' => @headers['Accept']
|
158
|
+
}
|
159
|
+
|
160
|
+
# DANGER: Basic auth should always come after headers, else
|
161
|
+
# The headers will replace the basic_auth
|
162
|
+
|
163
|
+
faraday.request :multipart
|
164
|
+
faraday.request :url_encoded
|
165
|
+
faraday.basic_auth(auth_id, auth_token)
|
166
|
+
|
167
|
+
faraday.proxy=@proxy_hash if @proxy_hash
|
168
|
+
faraday.response :json, content_type: /\bjson$/
|
169
|
+
faraday.adapter Faraday.default_adapter
|
170
|
+
end
|
171
|
+
|
172
|
+
response = multipart_conn.post do |req|
|
173
|
+
req.url resource_path
|
174
|
+
req.options.timeout = timeout if timeout
|
175
|
+
req.body = data
|
176
|
+
end
|
177
|
+
else
|
178
|
+
response = @conn.post do |req|
|
179
|
+
req.url resource_path
|
180
|
+
req.options.timeout = timeout if timeout
|
181
|
+
req.body = JSON.generate(data) if data
|
182
|
+
end
|
154
183
|
end
|
155
184
|
response
|
156
185
|
end
|
data/lib/plivo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plivo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Plivo SDKs Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -149,10 +149,12 @@ files:
|
|
149
149
|
- lib/plivo/exceptions.rb
|
150
150
|
- lib/plivo/resources.rb
|
151
151
|
- lib/plivo/resources/accounts.rb
|
152
|
+
- lib/plivo/resources/addresses.rb
|
152
153
|
- lib/plivo/resources/applications.rb
|
153
154
|
- lib/plivo/resources/calls.rb
|
154
155
|
- lib/plivo/resources/conferences.rb
|
155
156
|
- lib/plivo/resources/endpoints.rb
|
157
|
+
- lib/plivo/resources/identities.rb
|
156
158
|
- lib/plivo/resources/messages.rb
|
157
159
|
- lib/plivo/resources/numbers.rb
|
158
160
|
- lib/plivo/resources/pricings.rb
|