class IbanClient::Iban
Constants
- BANK_DATA_GETTER
- SEPA_DATA_GETTER
- VALIDATION_MESSAGES
Attributes
iban[R]
Public Class Methods
new(iban)
click to toggle source
# File lib/iban_client/iban.rb, line 15 def initialize(iban) @iban = iban end
Public Instance Methods
attributes()
click to toggle source
# File lib/iban_client/iban.rb, line 31 def attributes handle_result { (result['bank_data'] || {}).merge('iban' => iban) } end
errors()
click to toggle source
# File lib/iban_client/iban.rb, line 39 def errors handle_result do (result['validations'] || []).map { |validation| VALIDATION_MESSAGES[validation['code']] } .reject(&:nil?) end end
valid?()
click to toggle source
# File lib/iban_client/iban.rb, line 35 def valid? errors.empty? end
Private Instance Methods
api_errors()
click to toggle source
# File lib/iban_client/iban.rb, line 70 def api_errors result['errors'] end
handle_result() { || ... }
click to toggle source
# File lib/iban_client/iban.rb, line 74 def handle_result(&block) raise IbanClient::AccountError.new(iban: iban, errors: api_errors) if api_errors.count > 0 yield rescue JSON::ParserError => err raise IbanClient::RequestError.new(iban: iban, response: request) end
params()
click to toggle source
# File lib/iban_client/iban.rb, line 58 def params URI.encode_www_form( format: :json, api_key: IbanClient.api_key, iban: iban ) end
request()
click to toggle source
# File lib/iban_client/iban.rb, line 48 def request RestClient::Request.execute( method: :get, url: "#{IbanClient.api_base}?#{params}", timeout: IbanClient.timeout ) rescue RestClient::ExceptionWithResponse => err raise IbanClient::RequestError.new(iban: iban, response: err.response) end
result()
click to toggle source
# File lib/iban_client/iban.rb, line 66 def result @result ||= JSON.parse(request) end