Class: Plivo::Resources::IdentityInterface

Inherits:
Base::ResourceInterface show all
Defined in:
lib/plivo/resources/identities.rb

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Method Summary collapse

Methods included from Utils

expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?

Constructor Details

#initialize(client, resource_list_json = nil) ⇒ IdentityInterface

Returns a new instance of IdentityInterface.



109
110
111
112
113
114
# File 'lib/plivo/resources/identities.rb', line 109

def initialize(client, resource_list_json = nil)
  @_name = 'Verification/Identity'
  @_resource_type = Identity
  @_identifier_string = 'id'
  super
end

Instance Method Details

#create(country_iso, salutation, first_name, last_name, birth_place, birth_date, nationality, id_nationality, id_issue_date, id_type, id_number, address_line1, address_line2, city, region, postal_code, file_to_upload = nil, options = nil) ⇒ Identity

Create a new identity

Parameters:

  • country_iso (String)
  • salutation (String)
  • first_name (String)
  • last_name (String)
  • birth_place (String)
  • birth_date (String)
  • nationality (String)
  • id_nationality (String)
  • id_issue_date (String)
  • id_type (String)
  • id_number (String)
  • address_line1 (String)
  • address_line2 (String)
  • city (String)
  • region (String)
  • postal_code (String)
  • file_to_upload (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :alias (String)
    • Alias name of the identity

  • :business_name (String)
    • Business name of the user for whom the identity is created.

  • :auto_correct_address (String)
    • 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.

  • :fiscal_identification_code (String)
    • The code is valid for businesses alone

  • :street_code (String)
    • Street code of the address

  • :municipal_code (String)
    • Municipal code of the address

  • :callback_url (String)
    • The callback URL that gets the result of identity creation POSTed to.

  • :subaccount (String)
    • The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.

Returns:



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/plivo/resources/identities.rb', line 203

def create(country_iso, salutation, first_name, last_name, birth_place, birth_date, nationality,
           id_nationality, id_issue_date, id_type, id_number, address_line1, address_line2,
           city, region, postal_code, file_to_upload=nil, options=nil)
  valid_param?(:country_iso, country_iso, [String, Symbol], true)
  valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr])
  valid_param?(:first_name, first_name, [String, Symbol], true)
  valid_param?(:last_name, last_name, [String, Symbol], true)
  valid_param?(:birth_place, birth_place, [String, Symbol], true)
  valid_param?(:birth_date, birth_date, [String, Symbol], true)
  valid_param?(:nationality, nationality, [String, Symbol], true)
  valid_param?(:id_nationality, id_nationality, [String, Symbol], true)
  valid_param?(:id_issue_date, id_issue_date, [String, Symbol], true)
  valid_param?(:id_type, id_type, [String, Symbol], true)
  valid_param?(:id_number, id_number, [String, Symbol], true)
  valid_param?(:address_line1, address_line1, [String, Symbol], true)
  valid_param?(:address_line2, address_line2, [String, Symbol], true)
  valid_param?(:city, city, [String, Symbol], true)
  valid_param?(:region, region, [String, Symbol], true)
  valid_param?(:postal_code, postal_code, [String, Symbol], true)

  params = {
      country_iso: country_iso,
      salutation: salutation,
      first_name: first_name,
      last_name: last_name,
      birth_place: birth_place,
      birth_date: birth_date,
      nationality: nationality,
      id_nationality: id_nationality,
      id_issue_date: id_issue_date,
      id_type: id_type,
      id_number: id_number,
      address_line1: address_line1,
      address_line2: address_line2,
      city: city,
      region: region,
      postal_code: postal_code
  }

  unless file_to_upload.nil?
    file_extension = file_to_upload.split('.')[-1]

    content_type = case file_extension
                     when 'jpeg' then 'image/jpeg'
                     when 'jpg' then 'image/jpeg'
                     when 'png' then 'image/png'
                     when 'pdf' then 'application/pdf'
                     else raise_invalid_request("#{file_extension} is not yet supported for upload")
                   end

    params[:file] = Faraday::UploadIO.new(file_to_upload, content_type)
  end

  %i[alias business_name fiscal_identification_code street_code municipal_code callback_url subaccount]
      .each do |param|
    if options.key?(param) &&
        valid_param?(param, options[param], [String, Symbol], true)
      params[param] = options[param]
    end
  end

  %i[auto_correct_address]
      .each do |param|
    if options.key?(param) &&
        valid_param?(param, options[param], nil, true, [true, false])
      params[param] = options[param]
    end
  end

  perform_create(params, true)
end

#delete(identity_id) ⇒ Object

Delete an identity

Parameters:

  • identity_id (String)


312
313
314
315
316
# File 'lib/plivo/resources/identities.rb', line 312

def delete(identity_id)
  valid_param?(:identity_id, identity_id, [String, Symbol], true)
  Identity.new(@_client,
              resource_id: identity_id).delete
end

#get(identity_id) ⇒ Identity

Get an identity

Parameters:

  • identity_id (String)

Returns:



120
121
122
123
# File 'lib/plivo/resources/identities.rb', line 120

def get(identity_id)
  valid_param?(:identity_id, identity_id, [String, Symbol], true)
  perform_get(identity_id)
end

#list(options = nil) ⇒ Hash

List all identities

Parameters:

  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :country_iso (String)
    • Country ISO 2 code

  • :customer_name (String)
    • Name of the customer or business that is mentioned in the identity

  • :alias (String)
    • Friendly name of the id proof

  • :verification_status (String)
    • The status of the identity: pending. accepted, rejected, null

  • :offset (Int)
  • :limit (Int)

Returns:

  • (Hash)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/plivo/resources/identities.rb', line 135

def list(options=nil)
  return perform_list if options.nil?

  params = {}

  %i[country_iso customer_name alias].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [String, Symbol], true)
      params[param] = options[param]
    end
  end

  %i[verification_status].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [String, Symbol], true, ['pending', 'accepted', 'rejected',
                                                                    :pending, :accepted, :rejected])
      params[param] = options[param]
    end
  end

  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer], true)
      params[param] = options[param]
    end
  end

  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end

  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end

  perform_list(params)
end

#update(identity_id, file_to_upload = nil, options = nil) ⇒ Identity

Update an identity

Parameters:

  • identity_id (String)
  • file_to_upload (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :salutation (String)
    • One of Mr or Ms

  • :first_name (String)
    • First name of the user for whom the identity is created

  • :last_name (String)
    • Last name of the user for whom the identity is created

  • :country_iso (String)
    • Country ISO 2 code

  • :birth_place (String)
    • Birthplace of the user for whom the identity is created

  • :birth_date (String)
    • Birth date in yyyy-mm-dd format of the user for whom the identity is created

  • :nationality (String)
    • Nationality of the user for whom the identity is created

  • :id_nationality (String)
    • Nationality mentioned in the identity proof

  • :id_issue_date (String)
    • Issue date in yyyy-mm-dd mentioned in the identity proof

  • :id_type (String)

    -

  • :id_number (String)
    • The unique number on the identifier

  • :address_line1 (String)
    • Building name/number

  • :address_line2 (String)
    • The street name/number of the address

  • :city (String)
    • The city of the address for which the address proof is created

  • :region (String)
    • The region of the address for which the address proof is created

  • :postal_code (String)
    • The postal code of the address that is being created

  • :alias (String)
    • Alias name of the identity

  • :business_name (String)
    • Business name of the user for whom the identity is created.

  • :auto_correct_address (String)
    • 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.

  • :fiscal_identification_code (String)
    • The code is valid for businesses alone

  • :street_code (String)
    • Street code of the address

  • :municipal_code (String)
    • Municipal code of the address

  • :callback_url (String)
    • The callback URL that gets the result of identity creation POSTed to.

  • :subaccount (String)
    • The link to the subaccount resource associated with the application. If the application belongs to the main account, this field will be null.

Returns:



304
305
306
307
# File 'lib/plivo/resources/identities.rb', line 304

def update(identity_id, file_to_upload=nil, options=nil)
  Identity.new(@_client,
              resource_id: identity_id).update(file_to_upload, options)
end