diff --git a/lib/plivo/resources/addresses.rb b/lib/plivo/resources/addresses.rb index 43c35997..d6b5ba04 100644 --- a/lib/plivo/resources/addresses.rb +++ b/lib/plivo/resources/addresses.rb @@ -29,12 +29,23 @@ def delete # @option options [String] :alias - Alias name of the address # @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. # @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to. + # @option options [String] :phone_number_country + # @option options [String] :number_type + # @option options [String] :fiscal_identification_code + # @option options [String] :street_code + # @option options [String] :municipal_code + # @option options [String] :file + # @option options [String] :proof_type + # @option options [String] :id_number + # @return [Address] Address - def update(file_to_upload = nil, options = nil) + def update(options = nil) params = {} unless options.nil? - %i[salutation first_name last_name country_iso address_line1 address_line2 city region postal_code alias callback_url] + valid_param?(:options, options, Hash, true) + + %i[first_name last_name country_iso address_line1 address_line2 city region postal_code alias callback_url phone_number_country fiscal_identification_code street_code municipal_code file id_number] .each do |param| if options.key?(param) && valid_param?(param, options[param], [String, Symbol], true) @@ -49,22 +60,48 @@ def update(file_to_upload = nil, options = nil) params[param] = options[param] end end - end - unless file_to_upload.nil? - file_extension = file_to_upload.split('.')[-1] + if options[:salutation] + valid_param?(:salutation, options[:salutation], [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr]) + params[:salutation] = options[:salutation] + end - 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 + if options[:number_type] + valid_param?(:number_type, options[:number_type], [String, Symbol], true, ['local', 'national', 'mobile', 'tollfree']) + params[:number_type] = options[:number_type] + end - params[:file] = Faraday::UploadIO.new(file_to_upload, content_type) - end + if options[:proof_type] + if options[:country_iso] + if options[:country_iso] == 'ES' + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NIF', 'NIE', 'DNI']) + else + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NATIONAL_ID_CARD', 'PASSPORT', 'BUSINESS_REGISTRATION', 'any']) + end + else + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NIF', 'NIE', 'DNI', 'NATIONAL_ID_CARD', 'PASSPORT', 'BUSINESS_REGISTRATION', 'any']) + end + params[:proof_type] = options[:proof_type] + end + unless options[:file].nil? + valid_param?(:file, options[:file], [String, Symbol], true) + file_extension = options[:file].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 + file_size = File.size("#{options[:file]}") + if file_size > 5000000 + raise_invalid_request("Maximum file size can be 5 MB") + end + params[:file] = Faraday::UploadIO.new(options[:file], content_type) + end + end return perform_update(params, true) end @@ -124,6 +161,7 @@ def list(options=nil) return perform_list if options.nil? params = {} + valid_param?(:options, options, Hash, true) %i[country_iso customer_name alias].each do |param| if options.key?(param) && valid_param?(param, options[param], @@ -161,6 +199,8 @@ def list(options=nil) ## # Create a new address + # @param [String] phone_number_country + # @param [String] number_type # @param [String] country_iso # @param [String] salutation # @param [String] first_name @@ -170,8 +210,6 @@ def list(options=nil) # @param [String] city # @param [String] region # @param [String] postal_code - # @param [String] address_proof_type - # @param [String] file_to_upload # @param [Hash] options # @option options [String] :alias - Alias name of the address # @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. @@ -179,11 +217,16 @@ def list(options=nil) # @option options [String] :street_code - Street code of the address # @option options [String] :municipal_code - Municipal code of the address # @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to. + # @option options :file - A File to upload, which needs to be considered the proof of address. Max. file Size = 5 MB. File should be in jpg, pdf, or png format. + # @option options [String] :proof_type - The type of document that is provided as address proof + # @option options [String] :id_number - Unique Identifier for the address proof you have submitted + # @return [Address] Address - def create(country_iso, salutation, first_name, last_name, address_line1, address_line2, city, region, - postal_code, address_proof_type, 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]) + def create(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, city, region, + postal_code, country_iso, options=nil) + valid_param?(:phone_number_country, phone_number_country, [String, Symbol], true) + valid_param?(:number_type, number_type, [String, Symbol], true, ['local', 'national', 'mobile', 'tollfree']) + valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms']) valid_param?(:first_name, first_name, [String, Symbol], true) valid_param?(:last_name, last_name, [String, Symbol], true) valid_param?(:address_line1, address_line1, [String, Symbol], true) @@ -191,14 +234,12 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres valid_param?(:city, city, [String, Symbol], true) valid_param?(:region, region, [String, Symbol], true) valid_param?(:postal_code, postal_code, [String, Symbol], true) - valid_param?(:address_proof_type, - address_proof_type, - [String, Symbol], true, - ['national_id', 'passport', 'business_id', 'NIF', 'NIE', 'DNI', 'others', - :national_id, :passport, :business_id, :NIF, :NIE, :DNI, :others]) + valid_param?(:country_iso, country_iso, [String, Symbol], true) + params = { - country_iso: country_iso, + phone_number_country: phone_number_country, + number_type: number_type, salutation: salutation, first_name: first_name, last_name: last_name, @@ -207,8 +248,11 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres city: city, region: region, postal_code: postal_code, - address_proof_type: address_proof_type + country_iso: country_iso, } + return perform_create(params, true) if options.nil? + + valid_param?(:options, options, Hash, true) if country_iso == 'ES' valid_param?(:fiscal_identification_code, options[:fiscal_identification_code], [String, Symbol], true) @@ -223,8 +267,19 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres params[:municipal_code] = options[:municipal_code] end - unless file_to_upload.nil? - file_extension = file_to_upload.split('.')[-1] + if options[:proof_type] + if country_iso == 'ES' + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NIF', 'NIE', 'DNI']) + else + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NATIONAL_ID_CARD', 'PASSPORT', 'BUSINESS_REGISTRATION', 'any']) + end + params[:proof_type] = options[:proof_type] + end + + + unless options[:file].nil? + valid_param?(:file, options[:file], [String, Symbol], true) + file_extension = options[:file].split('.')[-1].downcase content_type = case file_extension when 'jpeg' then 'image/jpeg' @@ -233,11 +288,15 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres 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) + # add a check on file size + file_size = File.size("#{options[:file]}") + if file_size > 5000000 + raise_invalid_request("Maximum file size can be 5 MB") + end + params[:file] = Faraday::UploadIO.new(options[:file], content_type) end - %i[alias fiscal_identification_code street_code municipal_code callback_url] + %i[alias fiscal_identification_code street_code municipal_code callback_url id_number] .each do |param| if options.key?(param) && valid_param?(param, options[param], [String, Symbol], true) @@ -252,7 +311,6 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres params[param] = options[param] end end - perform_create(params, true) end @@ -274,9 +332,9 @@ def create(country_iso, salutation, first_name, last_name, address_line1, addres # @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. # @option options [String] :callback_url - The callback URL that gets the result of address creation POSTed to. # @return [Address] Address - def update(address_id, file_to_upload=nil, options=nil) - Address.new(@_client, - resource_id: address_id).update(file_to_upload, options) + def update(address_id, options=nil) + valid_param?(:address_id, address_id, [String, Symbol], true) + Address.new(@_client,resource_id: address_id).update(options) end ## @@ -299,4 +357,4 @@ def each end end end -end \ No newline at end of file +end diff --git a/lib/plivo/resources/identities.rb b/lib/plivo/resources/identities.rb index e4cf5c3d..df56d8b2 100644 --- a/lib/plivo/resources/identities.rb +++ b/lib/plivo/resources/identities.rb @@ -15,41 +15,42 @@ def delete # Update an identity # @param [String] identity_id - # @param [String] file_to_upload # @param [Hash] options + # @option options [String] :phone_number_country - Country ISO 2 code for which you are submitted + # @option options [String] :number_type - This can only take values “local”, “national”, “mobile”, “tollfree” # @option options [String] :salutation - One of Mr or Ms # @option options [String] :first_name - First name of the user for whom the identity is created # @option options [String] :last_name - Last name of the user for whom the identity is created - # @option options [String] :country_iso - Country ISO 2 code - # @option options [String] :birth_place - Birthplace of the user for whom the identity is created - # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created - # @option options [String] :nationality - Nationality of the user for whom the identity is created - # @option options [String] :id_nationality - Nationality mentioned in the identity proof - # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof - # @option options [String] :id_type - - # @option options [String] :id_number - The unique number on the identifier # @option options [String] :address_line1 - Building name/number # @option options [String] :address_line2 - The street name/number of the address # @option options [String] :city - The city of the address for which the address proof is created # @option options [String] :region - The region of the address for which the address proof is created # @option options [String] :postal_code - The postal code of the address that is being created + # @option options [String] :country_iso - Country ISO 2 code + # @option options [String] :proof_type - The type of document that is provided as address proof + # @option options [String] :id_number - The unique number on the identifier + # @option options [String] :nationality - Nationality of the user for whom the identity is created + # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. # @option options [String] :alias - Alias name of the identity + # @option options :file - A File to upload, which needs to be considered the proof of address. Max. file Size = 5 MB. File should be in jpg, pdf, or png format. + # @option options [String] :id_nationality - Nationality mentioned in the identity proof + # @option options [String] :birth_place - Birthplace of the user for whom the identity is created + # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created + # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof # @option options [String] :business_name - Business name of the user for whom the identity is created. - # @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. # @option options [String] :fiscal_identification_code - The code is valid for businesses alone # @option options [String] :street_code - Street code of the address # @option options [String] :municipal_code - Municipal code of the address - # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. - # @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. # @return [Identity] Identity - def update(file_to_upload = nil, options = nil) + + def update(options = nil) params = {} unless options.nil? - %i[salutation first_name last_name country_iso birth_place birth_date nationality id_nationality id_issue_date - id_type id_number address_line1 address_line2 city region postal_code alias business_name - fiscal_identification_code street_code municipal_code callback_url subaccount - ] + valid_param?(:options, options, Hash, true) + + %i[phone_number_country first_name last_name address_line1 address_line2 city region postal_code country_iso + id_number nationality callback_url alias id_nationality birth_place birth_date id_issue_date business_name fiscal_identification_code street_code municipal_code] .each do |param| if options.key?(param) && valid_param?(param, options[param], [String, Symbol], true) @@ -57,45 +58,64 @@ def update(file_to_upload = nil, options = nil) 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 + if options[:salutation] + valid_param?(:salutation, options[:salutation], [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr]) + params[:salutation] = options[:salutation] end - end - - 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 + if options[:number_type] + valid_param?(:number_type, options[:number_type], [String, Symbol], true, ['local', 'national', 'mobile', 'tollfree']) + params[:number_type] = options[:number_type] + end - params[:file] = Faraday::UploadIO.new(file_to_upload, content_type) + if options[:proof_type] + if options[:country_iso] + if options[:country_iso] == 'ES' + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NIF', 'NIE', 'DNI']) + else + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NATIONAL_ID_CARD', 'PASSPORT', 'BUSINESS_REGISTRATION', 'any']) + end + else + valid_param?(:proof_type, options[:proof_type], [String, Symbol], false, ['NIF', 'NIE', 'DNI', 'national_id', 'passport', 'business_id']) + end + params[:proof_type] = options[:proof_type] + end + unless options[:file].nil? + valid_param?(:file, options[:file], [String, Symbol], true) + file_extension = options[:file].split('.')[-1].downcase + # add check on file size + 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 + file_size = File.size("#{options[:file]}") + if file_size > 5000000 + raise_invalid_request("Maximum file size can be 5 MB") + end + params[:file] = Faraday::UploadIO.new(options[:file], content_type) + end end - return perform_update(params, true) end def to_s { account: @account, + address_line1: @address_line1, + address_line2: @address_line2, alias: @alias, api_id: @api_id, + city: @city, country_iso: @country_iso, document_details: @document_details, first_name: @first_name, id: @id, - id_number: @id_number, - id_type: @id_type, last_name: @last_name, - nationality: @nationality, + postal_code: @postal_code, + region: @region, salutation: @salutation, subaccount: @subaccount, url: @url, @@ -135,6 +155,7 @@ def get(identity_id) def list(options=nil) return perform_list if options.nil? + valid_param?(:options, options, Hash, true) params = {} %i[country_iso customer_name alias].each do |param| @@ -173,74 +194,71 @@ def list(options=nil) ## # Create a new identity - # @param [String] country_iso + # @param [String] phone_number_country + # @param [String] number_type # @param [String] salutation # @param [String] first_name # @param [String] last_name - # @param [String] birth_place - # @param [String] birth_date - # @param [String] nationality - # @param [String] id_nationality - # @param [String] id_issue_date - # @param [String] id_type - # @param [String] id_number # @param [String] address_line1 # @param [String] address_line2 # @param [String] city # @param [String] region # @param [String] postal_code - # @param [String] file_to_upload + # @param [String] country_iso + # @param [String] proof_type + # @param [String] id_number + # @param [String] nationality # @param [Hash] options + # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. # @option options [String] :alias - Alias name of the identity + # @option options :file - A File to upload, which needs to be considered the proof of address. Max. file Size = 5 MB. File should be in jpg, pdf, or png format. + # @option options [String] :id_nationality - Nationality of the user mentioned in the document + # @option options [String] :birth_place - Birth Place of the user mentioned in the document + # @option options [String] :birth_date - Birth Date of the user mentioned in the document + # @option options [String] :id_issue_date - Issued date of the proof being uploaded # @option options [String] :business_name - Business name of the user for whom the identity is created. - # @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. # @option options [String] :fiscal_identification_code - The code is valid for businesses alone # @option options [String] :street_code - Street code of the address # @option options [String] :municipal_code - Municipal code of the address - # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. - # @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. # @return [Identity] Identity - 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) + + def create(phone_number_country, number_type, salutation, first_name, last_name, address_line1, address_line2, + city, region, postal_code, country_iso, proof_type, id_number, nationality, options=nil) + valid_param?(:phone_number_country, phone_number_country, [String, Symbol], true) + valid_param?(:number_type, number_type, [String, Symbol], true, ['local', 'national', 'mobile', 'tollfree']) 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) + valid_param?(:country_iso, country_iso, [String, Symbol], true) + valid_param?(:id_number, id_number, [String, Symbol], true) + valid_param?(:nationality, nationality, [String, Symbol], true) params = { - country_iso: country_iso, + phone_number_country: phone_number_country, + number_type: number_type, 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 + postal_code: postal_code, + country_iso: country_iso, + id_number: id_number, + nationality: nationality } - unless file_to_upload.nil? - file_extension = file_to_upload.split('.')[-1] + return perform_create(params, true) if options.nil? + valid_param?(:options, options, Hash, true) + unless options[:file].nil? + valid_param?(:file, options[:file], [String, Symbol], true) + file_extension = options[:file].split('.')[-1].downcase content_type = case file_extension when 'jpeg' then 'image/jpeg' @@ -249,61 +267,71 @@ def create(country_iso, salutation, first_name, last_name, birth_place, birth_da 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) + file_size = File.size("#{options[:file]}") + if file_size > 5000000 + raise_invalid_request("Maximum file size can be 5 MB") + end + params[:file] = Faraday::UploadIO.new(options[:file], 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 + if country_iso == 'ES' + valid_param?(:fiscal_identification_code, options[:fiscal_identification_code], [String, Symbol], true) + valid_param?(:proof_type, proof_type, [String, Symbol], true, ['NIF', 'NIE', 'DNI']) + params[:proof_type] = proof_type + params[:fiscal_identification_code] = options[:fiscal_identification_code] + elsif country_iso == 'DK' + valid_param?(:street_code, options[:street_code], [String, Symbol], true) + valid_param?(:municipal_code, options[:municipal_code], [String, Symbol], true) + params[:street_code] = options[:street_code] + params[:municipal_code] = options[:municipal_code] + else + valid_param?(:proof_type, proof_type, [String, Symbol], true, ['NATIONAL_ID_CARD', 'PASSPORT', 'BUSINESS_REGISTRATION', 'any']) + params[:proof_type] = proof_type end - %i[auto_correct_address] + %i[callback_url alias id_nationality birth_place birth_date id_issue_date business_name fiscal_identification_code street_code municipal_code] .each do |param| if options.key?(param) && - valid_param?(param, options[param], nil, true, [true, false]) + valid_param?(param, options[param], [String, Symbol], true) params[param] = options[param] end end - perform_create(params, true) end # Update an identity # @param [String] identity_id - # @param [String] file_to_upload # @param [Hash] options + # @option options [String] :phone_number_country - Country ISO 2 code for which you are submitted + # @option options [String] :number_type - This can only take values “local”, “national”, “mobile”, “tollfree” # @option options [String] :salutation - One of Mr or Ms # @option options [String] :first_name - First name of the user for whom the identity is created # @option options [String] :last_name - Last name of the user for whom the identity is created - # @option options [String] :country_iso - Country ISO 2 code - # @option options [String] :birth_place - Birthplace of the user for whom the identity is created - # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created - # @option options [String] :nationality - Nationality of the user for whom the identity is created - # @option options [String] :id_nationality - Nationality mentioned in the identity proof - # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof - # @option options [String] :id_type - - # @option options [String] :id_number - The unique number on the identifier # @option options [String] :address_line1 - Building name/number # @option options [String] :address_line2 - The street name/number of the address # @option options [String] :city - The city of the address for which the address proof is created # @option options [String] :region - The region of the address for which the address proof is created # @option options [String] :postal_code - The postal code of the address that is being created + # @option options [String] :country_iso - Country ISO 2 code + # @option options [String] :proof_type - The type of document that is provided as address proof + # @option options [String] :id_number - The unique number on the identifier + # @option options [String] :nationality - Nationality of the user for whom the identity is created + # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. # @option options [String] :alias - Alias name of the identity + # @option options :file - A File to upload, which needs to be considered the proof of address. Max. file Size = 5 MB. File should be in jpg, pdf, or png format. + # @option options [String] :id_nationality - Nationality mentioned in the identity proof + # @option options [String] :birth_place - Birthplace of the user for whom the identity is created + # @option options [String] :birth_date - Birth date in yyyy-mm-dd format of the user for whom the identity is created + # @option options [String] :id_issue_date - Issue date in yyyy-mm-dd mentioned in the identity proof # @option options [String] :business_name - Business name of the user for whom the identity is created. - # @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. # @option options [String] :fiscal_identification_code - The code is valid for businesses alone # @option options [String] :street_code - Street code of the address # @option options [String] :municipal_code - Municipal code of the address - # @option options [String] :callback_url - The callback URL that gets the result of identity creation POSTed to. - # @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. # @return [Identity] Identity - def update(identity_id, file_to_upload=nil, options=nil) + def update(identity_id, options=nil) + valid_param?(:identity_id, identity_id, [String, Symbol], true) Identity.new(@_client, - resource_id: identity_id).update(file_to_upload, options) + resource_id: identity_id).update(options) end ## @@ -316,4 +344,4 @@ def delete(identity_id) end end end -end \ No newline at end of file +end diff --git a/spec/mocks/addressCreateErrorResponse.json b/spec/mocks/addressCreateErrorResponse.json new file mode 100644 index 00000000..d020d313 --- /dev/null +++ b/spec/mocks/addressCreateErrorResponse.json @@ -0,0 +1,8 @@ +{ + "api_id": "396f3832-0a89-11e9-b0b4-066a42519598", + "error": { + "error": "user already exists", + "message": "Could not complete address verification.", + "status": "error" + } +} diff --git a/spec/mocks/addressCreateResponse.json b/spec/mocks/addressCreateSuccessResponse.json similarity index 100% rename from spec/mocks/addressCreateResponse.json rename to spec/mocks/addressCreateSuccessResponse.json diff --git a/spec/mocks/identityCreateErrorResponse.json b/spec/mocks/identityCreateErrorResponse.json new file mode 100644 index 00000000..a4f39225 --- /dev/null +++ b/spec/mocks/identityCreateErrorResponse.json @@ -0,0 +1,8 @@ +{ + "api_id": "396f3832-0a89-11e9-b0b4-066a42519598", + "error": { + "error": "user already exists", + "message": "Could not complete idenity verification.", + "status": "error" + } +} diff --git a/spec/mocks/identityCreateResponse.json b/spec/mocks/identityCreateSuccessResponse.json similarity index 100% rename from spec/mocks/identityCreateResponse.json rename to spec/mocks/identityCreateSuccessResponse.json diff --git a/spec/resource_addresses_spec.rb b/spec/resource_addresses_spec.rb index 275b4482..3a15ca06 100644 --- a/spec/resource_addresses_spec.rb +++ b/spec/resource_addresses_spec.rb @@ -51,33 +51,91 @@ def to_json_list(list_object) }.to_json end - it 'creates an address' do - contents = File.read(Dir.pwd + '/spec/mocks/addressCreateResponse.json') +describe "create an address" do + it "creates an address sucessfully" do + contents = File.read(Dir.pwd + '/spec/mocks/addressCreateSuccessResponse.json') mock(200, JSON.parse(contents)) expect(JSON.parse(to_json_create(@api.addresses - .create( - 'US', - 'Mr', - 'Bruce', - 'Wayne', - '1234', - 'Wayne Towers', - 'New York', - 'NY', - '12345', - 'others', - nil, - { - callback_url: 'https://callback.url', - auto_correct_address: true - } + .create('US', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'US', + { + callback_url: 'https://callback.url', + proof_type: 'PASSPORT' + } )))) .to eql(JSON.parse(contents).reject { |_, v| v.nil? }) compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Verification/Address/', method: 'POST', data: { + phone_number_country: 'US', + number_type: 'local', + salutation: 'Mr', + first_name: 'Bruce', + last_name: 'Wayne', + address_line1: '1234', + address_line2: 'Wayne Towers', + city: 'New York', + region: 'NY', + postal_code: '12345', country_iso: 'US', + callback_url: 'https://callback.url', + proof_type: 'PASSPORT' + }) + end + + it "raises exception: in case of mandatory param - fiscal_identification_code is mandatory when country_iso is Spain" do + expect{@api.addresses.create('ES', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'ES', + { + callback_url: 'https://callback.url', + proof_type: 'PASSPORT' + } + )}.to raise_error(Plivo::Exceptions::InvalidRequestError) + end + + it "returns error: in case of invalid value for param" do + contents = File.read(Dir.pwd + '/spec/mocks/addressCreateErrorResponse.json') + mock(405, JSON.parse(contents)) + expect{@api.addresses.create('US', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'US', + { + callback_url: 'https://callback.url', + proof_type: 'PASSPORT' + } + )}.to raise_error(Plivo::Exceptions::InvalidRequestError) + compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Verification/Address/', + method: 'POST', + data: { + phone_number_country: 'US', + number_type: 'local', salutation: 'Mr', first_name: 'Bruce', last_name: 'Wayne', @@ -86,11 +144,13 @@ def to_json_list(list_object) city: 'New York', region: 'NY', postal_code: '12345', - address_proof_type: 'others', + country_iso: 'US', callback_url: 'https://callback.url', - auto_correct_address: true + proof_type: 'PASSPORT' }) end +end + it 'fetches details of an address' do contents = File.read(Dir.pwd + '/spec/mocks/addressGetResponse.json') @@ -127,7 +187,7 @@ def to_json_list(list_object) contents = File.read(Dir.pwd + '/spec/mocks/addressUpdateResponse.json') mock(200, JSON.parse(contents)) expect(JSON.parse(to_json_update(@api.addresses - .update(id, nil, { + .update(id, { salutation: 'Mr', first_name: 'Bruce' })))) diff --git a/spec/resource_identities_spec.rb b/spec/resource_identities_spec.rb index 2834ef21..8f2dc641 100644 --- a/spec/resource_identities_spec.rb +++ b/spec/resource_identities_spec.rb @@ -49,55 +49,126 @@ def to_json_list(list_object) }.to_json end - it 'creates an identity' do - contents = File.read(Dir.pwd + '/spec/mocks/identityCreateResponse.json') - mock(200, JSON.parse(contents)) + describe 'create an identity' do + it 'creates an idenity sucessfully' do + contents = File.read(Dir.pwd + '/spec/mocks/identityCreateSuccessResponse.json') + mock(200, JSON.parse(contents)) - expect(JSON.parse(to_json_create(@api.identities - .create( - 'US', - 'Mr', - 'Bruce', - 'Wayne', - 'Gotham City', - '1900-01-01', - 'US', - 'American', - '1900-01-01', - 'others', - 'BATMANRETURNS', - '1234', - 'Wayne Towers', - 'New York', - 'NY', - '12345', - nil, - { - callback_url: 'https://callback.url', - } - )))) - .to eql(JSON.parse(contents).reject { |_, v| v.nil? }) - compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Verification/Identity/', - method: 'POST', - data: { - country_iso: 'US', - salutation: 'Mr', - first_name: 'Bruce', - last_name: 'Wayne', - birth_place: 'Gotham City', - birth_date: '1900-01-01', - nationality: 'US', - id_nationality: 'American', - id_issue_date: '1900-01-01', - id_type: 'others', - id_number: 'BATMANRETURNS', - address_line1: '1234', - address_line2: 'Wayne Towers', - city: 'New York', - region: 'NY', - postal_code: '12345', - callback_url: 'https://callback.url' - }) + expect(JSON.parse(to_json_create(@api.identities + .create( + 'US', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'US', + 'PASSPORT', + '123456', + 'US', + { + callback_url: 'https://callback.url', + birth_date: '1900-01-01', + birth_place: 'Gotham City' + } + )))) + .to eql(JSON.parse(contents).reject { |_, v| v.nil? }) + compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Verification/Identity/', + method: 'POST', + data: { + phone_number_country: 'US', + number_type: 'local', + salutation: 'Mr', + first_name: 'Bruce', + last_name: 'Wayne', + address_line1: '1234', + address_line2: 'Wayne Towers', + city: 'New York', + region: 'NY', + postal_code: '12345', + country_iso: 'US', + proof_type: 'PASSPORT', + id_number: '123456', + nationality: 'US', + callback_url: 'https://callback.url', + birth_date: '1900-01-01', + birth_place: 'Gotham City' + }) + end + + it "raises exception: in case of mandatory param - fiscal_identification_code is mandatory when country_iso is Spain" do + expect{@api.identities.create('ES', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'ES', + 'PASSPORT', + '123456', + 'ES', + { + callback_url: 'https://callback.url', + birth_date: '1900-01-01', + birth_place: 'Gotham City' + } + )}.to raise_error(Plivo::Exceptions::InvalidRequestError) + end + + it "returns error: in case of invalid value for param" do + contents = File.read(Dir.pwd + '/spec/mocks/identityCreateErrorResponse.json') + mock(405, JSON.parse(contents)) + expect{@api.identities.create('US', + 'local', + 'Mr', + 'Bruce', + 'Wayne', + '1234', + 'Wayne Towers', + 'New York', + 'NY', + '12345', + 'US', + 'PASSPORT', + '123456', + 'US', + { + callback_url: 'https://callback.url', + birth_date: '1900-01-01', + birth_place: 'Gotham City' + } + )}.to raise_error(Plivo::Exceptions::InvalidRequestError) + compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/Verification/Identity/', + method: 'POST', + data: { + phone_number_country: 'US', + number_type: 'local', + salutation: 'Mr', + first_name: 'Bruce', + last_name: 'Wayne', + address_line1: '1234', + address_line2: 'Wayne Towers', + city: 'New York', + region: 'NY', + postal_code: '12345', + country_iso: 'US', + proof_type: 'PASSPORT', + id_number: '123456', + nationality: 'US', + callback_url: 'https://callback.url', + birth_date: '1900-01-01', + birth_place: 'Gotham City' + }) + + end end it 'fetches details of an identity' do @@ -135,7 +206,7 @@ def to_json_list(list_object) contents = File.read(Dir.pwd + '/spec/mocks/identityUpdateResponse.json') mock(200, JSON.parse(contents)) expect(JSON.parse(to_json_update(@api.identities - .update(id, nil, + .update(id, { salutation: 'Mr', first_name: 'Bruce'