class RusBank

Public Class Methods

new() click to toggle source
# File lib/rus_bank.rb, line 5
def initialize
  @client = Savon.client(wsdl: "http://www.cbr.ru/CreditInfoWebServ/CreditOrgInfo.asmx?WSDL")
end

Public Instance Methods

BicToIntCode(bic) click to toggle source

Возвращает внутренний код банка по БИК

# File lib/rus_bank.rb, line 19
def BicToIntCode(bic)
  params = { "BicCode" => bic }
  call(:bic_to_int_code, params)
end
BicToRegNumber(bic) click to toggle source

Возвращает регистрационный номер банка по БИК

# File lib/rus_bank.rb, line 27
def BicToRegNumber(bic)
  params = { "BicCode" => bic }
  call(:bic_to_reg_number, params)
end
CreditInfoByIntCode(internal_code) click to toggle source

Информация по кредитной организации по внутреннему номеру

# File lib/rus_bank.rb, line 103
def CreditInfoByIntCode(internal_code)
  params = { "InternalCode" => internal_code }
  response = call(:credit_info_by_int_code_xml, params)
  if response.nil?
    nil
  else
    response[:credit_org_info]
  end
end
EnumBic() click to toggle source

Данные по BIC кодам КО, без филиалов

# File lib/rus_bank.rb, line 87
def EnumBic
  response = call(:enum_bic_xml)
  get_array(response, :enum_bic, :bic)
end
GetOffices(int_code) click to toggle source

Информация по филиальной сети кредитной орг. по вн.коду

# File lib/rus_bank.rb, line 69
def GetOffices(int_code)
  params = { "IntCode" => int_code }
  response = call(:get_offices_xml, params)
  get_array(response, :co_offices, :offices)
end
GetOfficesByRegion(region_code) click to toggle source

Список филиалов в указанном регионе

# File lib/rus_bank.rb, line 78
def GetOfficesByRegion(region_code)
  params = { "RegCode" => region_code }
  response = call(:get_offices_by_region_xml, params)
  get_array(response, :co_offices, :offices)
end
IntCodeToRegNum(int_code) click to toggle source

Возвращает регистрационный номер по внутреннему номеру

# File lib/rus_bank.rb, line 43
def IntCodeToRegNum(int_code)
  params = { "IntNumber" => int_code }
  call(:int_code_to_reg_num, params)
end
RegNumToIntCode(reg_num) click to toggle source

Возвращает внутренний код банка по регистрационному номеру

# File lib/rus_bank.rb, line 35
def RegNumToIntCode(reg_num)
  params = { "RegNumber" => reg_num }
  call(:reg_num_to_int_code, params)
end
RegionsEnum() click to toggle source

Список регионов

# File lib/rus_bank.rb, line 95
def RegionsEnum
  response = call(:regions_enum_xml)
  get_array(response, :regions_enum, :rgid)
end
SearchByName(bank_name) click to toggle source

Поиск по названию банка

# File lib/rus_bank.rb, line 60
def SearchByName(bank_name)
  params = { "NamePart" => bank_name }
  response = call(:search_by_name_xml, params)
  get_array(response, :credit_org, :enum_credits)
end
SearchByRegionCode(region_code) click to toggle source

Список банков по коду региона

# File lib/rus_bank.rb, line 51
def SearchByRegionCode(region_code)
  params = { "RegCode" => region_code }
  response = call(:search_by_region_code_xml, params)
  get_array(response, :credit_org, :enum_credits)
end
call(method, params = nil) click to toggle source

Метод позволяет вручную вызывать нужные soap-сервисы.

# File lib/rus_bank.rb, line 116
def call(method, params = nil)
  response = @client.call(method, message: params).to_hash[(method.to_s + "_response").to_sym][(method.to_s + "_result").to_sym]
  if response == "-1" or response.to_s.include?("NotFound")           # Разные методы сервиса возвращают ответ в разном формате
    return nil
  else
    response
  end
end
operations() click to toggle source

Возвращает полный список доступных для метода call методов

# File lib/rus_bank.rb, line 12
def operations
  @client.operations
end

Private Instance Methods

get_array(response, *params) click to toggle source
# File lib/rus_bank.rb, line 127
def get_array(response, *params)
  node = params.inject(response){|inner_node, param| inner_node[param]}     # Вытягиваем вложенные ноды
  if node.nil?
    nil
  else
    if not node.instance_of?(Array)      # Если найдена одна запись, возвращается единичный хэш,
      [node]                             # если более одной, то массив хешей,
    else                                 # поэтому одну запись преобразуем к массиву из одного хэша.
      node
    end
  end
end