Class: FidorApi::Model::Transfer::Generic
- Defined in:
- lib/fidor_api/model/transfer/generic.rb
Constant Summary collapse
- SUPPORTED_ROUTING_TYPES =
{ 'SEPA' => %w[remote_iban remote_bic instant], 'FOS_P2P_EMAIL' => %w[email], 'FOS_P2P_PHONE' => %w[mobile_phone_number], 'FOS_P2P_ACCOUNT_NUMBER' => %w[account_number], 'FOS_P2P_USERNAME' => %w[username], 'FPS' => %w[remote_account_number remote_sort_code instant] }.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
25 26 27 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 25 def self.resource_name 'Transfer' end |
Instance Method Details
#beneficiary=(value) ⇒ Object
29 30 31 32 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 29 def beneficiary=(value) write_attribute(:beneficiary, value) define_methods_for(beneficiary['routing_type']) end |
#define_methods_for(type) ⇒ Object
rubocop:disable Metrics/MethodLength
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 47 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
79 80 81 82 83 84 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 79 def parse_errors(body) body['errors'].each do |hash| hash['field'].sub!('beneficiary.routing_info.', '') end super(body) end |
#routing_type ⇒ Object
34 35 36 37 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 34 def routing_type @beneficiary ||= {} @beneficiary.dig('routing_type') end |
#routing_type=(type) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/fidor_api/model/transfer/generic.rb', line 39 def routing_type=(type) raise Errors::NotSupported unless SUPPORTED_ROUTING_TYPES.key?(type) @beneficiary ||= {} @beneficiary['routing_type'] = type define_methods_for(type) end |