Class: FidorApi::Model::Transfer::Generic
- Defined in:
- lib/fidor_api/model/transfer/generic.rb
Constant Summary collapse
- SUPPORTED_ROUTING_TYPES =
TODO: Not all params are part of routing_info :(
{ 'SEPA' => %w[contact_name remote_iban remote_bic bank_name], 'FOS_P2P_EMAIL' => %w[email], 'FOS_P2P_PHONE' => %w[mobile_phone_number], 'FOS_P2P_USERNAME' => %w[username], 'FPS' => %w[contact_name remote_account_number remote_sort_code] }.freeze
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #beneficiary=(value) ⇒ Object
-
#define_methods_for(type) ⇒ Object
rubocop:disable Metrics/MethodLength.
- #parse_errors(body) ⇒ Object
- #routing_type ⇒ Object
- #routing_type=(type) ⇒ Object
Methods inherited from Base
Class Method Details
.resource_name ⇒ Object
24 25 26 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 24 def self.resource_name 'Transfer' end |
Instance Method Details
#beneficiary=(value) ⇒ Object
28 29 30 31 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 28 def beneficiary=(value) write_attribute(:beneficiary, value) define_methods_for(beneficiary['routing_type']) end |
#define_methods_for(type) ⇒ Object
rubocop:disable Metrics/MethodLength
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 46 def define_methods_for(type) # rubocop:disable Metrics/MethodLength SUPPORTED_ROUTING_TYPES[type].each do |name| next if respond_to?(name) self.class.define_method name do @beneficiary ||= {} @beneficiary.dig('routing_info', name) end self.class.define_method "#{name}=" do |value| @beneficiary ||= {} @beneficiary['routing_info'] ||= {} @beneficiary['routing_info'][name] = value end end end |
#parse_errors(body) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 63 def parse_errors(body) body['errors'].each do |hash| hash['field'].sub!('beneficiary.routing_info.', '') end super(body) end |
#routing_type ⇒ Object
33 34 35 36 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 33 def routing_type @beneficiary ||= {} @beneficiary.dig('routing_type') end |
#routing_type=(type) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 38 def routing_type=(type) raise Errors::NotSupported unless SUPPORTED_ROUTING_TYPES.key?(type) @beneficiary ||= {} @beneficiary['routing_type'] = type define_methods_for(type) end |