Class: RusBank

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

Instance Method Summary collapse

Constructor Details

#initializeRusBank

Returns a new instance of RusBank.



5
6
7
# File 'lib/rus_bank.rb', line 5

def initialize
  @client = Savon.client(wsdl: "http://www.cbr.ru/CreditInfoWebServ/CreditOrgInfo.asmx?WSDL")
end

Instance Method Details

#BicToIntCode(bic) ⇒ Object

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



19
20
21
22
# File 'lib/rus_bank.rb', line 19

def BicToIntCode(bic)
  params = { "BicCode" => bic }
  call(:bic_to_int_code, params)
end

#BicToRegNumber(bic) ⇒ Object

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



27
28
29
30
# File 'lib/rus_bank.rb', line 27

def BicToRegNumber(bic)
  params = { "BicCode" => bic }
  call(:bic_to_reg_number, params)
end

#call(method, params = nil) ⇒ Object

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



116
117
118
119
120
121
122
123
# 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

#CreditInfoByIntCode(internal_code) ⇒ Object

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



103
104
105
106
107
108
109
110
111
# 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

#EnumBicObject

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



87
88
89
90
# File 'lib/rus_bank.rb', line 87

def EnumBic
  response = call(:enum_bic_xml)
  get_array(response, :enum_bic, :bic)
end

#GetOffices(int_code) ⇒ Object

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



69
70
71
72
73
# 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) ⇒ Object

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



78
79
80
81
82
# 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) ⇒ Object

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



43
44
45
46
# File 'lib/rus_bank.rb', line 43

def IntCodeToRegNum(int_code)
  params = { "IntNumber" => int_code }
  call(:int_code_to_reg_num, params)
end

#operationsObject

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



12
13
14
# File 'lib/rus_bank.rb', line 12

def operations
  @client.operations
end

#RegionsEnumObject

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



95
96
97
98
# File 'lib/rus_bank.rb', line 95

def RegionsEnum
  response = call(:regions_enum_xml)
  get_array(response, :regions_enum, :rgid)
end

#RegNumToIntCode(reg_num) ⇒ Object

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



35
36
37
38
# File 'lib/rus_bank.rb', line 35

def RegNumToIntCode(reg_num)
  params = { "RegNumber" => reg_num }
  call(:reg_num_to_int_code, params)
end

#SearchByName(bank_name) ⇒ Object

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



60
61
62
63
64
# 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) ⇒ Object

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



51
52
53
54
55
# 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