Class: AlfaBank::DataBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/alfa_bank/data_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_type, opts) ⇒ DataBuilder

Returns a new instance of DataBuilder.



9
10
11
12
# File 'lib/alfa_bank/data_builder.rb', line 9

def initialize(request_type, opts)
  @request_type = request_type
  @opts = opts.symbolize_keys!
end

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



7
8
9
# File 'lib/alfa_bank/data_builder.rb', line 7

def opts
  @opts
end

#request_typeObject

Returns the value of attribute request_type.



7
8
9
# File 'lib/alfa_bank/data_builder.rb', line 7

def request_type
  @request_type
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
# File 'lib/alfa_bank/data_builder.rb', line 14

def call
  unless valid?
    raise_custom_error
  end
  opts.merge!(user_name: user_name, password: password)
  data_builder.build_params(request_type, opts)
end

#data_builderObject

TODO: add depandency from config (soap|rest)



42
43
44
# File 'lib/alfa_bank/data_builder.rb', line 42

def data_builder
  AlfaBank::RestDataBuilder
end


29
30
31
# File 'lib/alfa_bank/data_builder.rb', line 29

def link
  "#{AlfaBank.configuration.base_link}/#{Constants::ALFA_LINKS[request_type]}"
end

#passwordObject



37
38
39
# File 'lib/alfa_bank/data_builder.rb', line 37

def password
  AlfaBank.configuration.password
end

#user_nameObject



33
34
35
# File 'lib/alfa_bank/data_builder.rb', line 33

def user_name
  AlfaBank.configuration.user_name
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/alfa_bank/data_builder.rb', line 22

def valid?
  fields = Constants::REQUIRED_FIELDS[request_type]
  opts.values_at(*fields).compact.size == fields.size
rescue
  raise_custom_error
end