class BankValInternational::GetIBAN

BankValInternational::GetIban

Class to control calls to IBANValidate

Synopsis

requires 'BankValInternational'

@obj1 = BankValInternational::GetIBAN.new
@ans = obj1.bankval_int_ibanval('json','AN_IBAN_NUMBER','userID','PINNo')

Public Instance Methods

bankval_int_ibanval(*args) click to toggle source

Method to control calls to IBANValidate

Parameters

1.Return Format

must be either ‘json’, ‘xml’ or ‘csv’

2.Iban Number

the number for validation

3.UserId

can obtained from www.unifiedsoftware.co.uk/freetrial/free-trial-home.html

4.PIN

can obtained from www.unifiedsoftware.co.uk/freetrial/free-trial-home.html

The parameters must be passed in the order shown above

Returns

The response from the webservice is returned as a string in either: *XML format *json format *csv format depending on the Return Format Parameter passed in

# File lib/BankValInternational.rb, line 53
def bankval_int_ibanval(*args)
  @format = args[0].downcase
  @iban = args[1]
  @userid = args[2]
  @pin = args[3]
  if args.size !=4
    return "ERROR - not enough parameters supplied"
  end
  format_validation
  if @error_string != nil
    format_error_string
    return @error_string
  end
  build_req_url
  return "#{BankValInternational::GoValidate.new.validate(@service_url)}"
end

Private Instance Methods

build_req_url() click to toggle source

method to build the base request url for the REST call

# File lib/BankValInternational.rb, line 73
def build_req_url()
  @service_url = "bankvalint/ibanvalidator/userid/#{@userid}/pin/#{@pin}/iban/#{@iban}/#{@format}/"
end
format_error_string() click to toggle source
# File lib/BankValInternational.rb, line 89
def format_error_string()
  if @format == 'xml'
    @error_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><iban><result>" + @error_string + "</result></iban>"
  elsif @format == 'json'
    @error_string = "{\"result\":\"" + @error_string + "\"}"
  end
end
format_validation() click to toggle source
# File lib/BankValInternational.rb, line 76
def format_validation
  @error_string = nil
  if @format !~  /^json$|^xml$|^csv$/
    @error_string = "INVALID - Result Format"
  elsif @iban !~ /^[A-Z,0-9]{1,34}$/
    @error_string = "INVALID - FORMAT"
  elsif @pin !~ /^[0-9]{5}$/
    @error_string = "ERROR - Invalid User ID/PIN"
  elsif @userid !~ /^[a-zA-Z\-_][a-zA-Z][a-zA-Z]*\D\d\d\d$/
    @error_string = "ERROR - Invalid User ID/PIN"
  end
end