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



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

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

#BicToRegNumber(bic) ⇒ Object



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

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

#call(method, params = nil) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/rus_bank.rb', line 85

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

#CreditInfoByIntCodeXML(internal_code) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/rus_bank.rb', line 75

def CreditInfoByIntCodeXML(internal_code)
  params = { "InternalCode" => internal_code }
  response = call(:credit_info_by_int_code_xml, params)
  if response.nil?
    nil
  else
    response[:credit_org_info][:co]
  end
end

#EnumBicXMLObject



57
58
59
60
61
62
63
64
# File 'lib/rus_bank.rb', line 57

def EnumBicXML
  response = call(:enum_bic_xml)
  if response.nil?
    nil
  else
    response[:enum_bic][:bic]
  end
end

#IntCodeToRegNum(int_code) ⇒ Object



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

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

#operationsObject



9
10
11
# File 'lib/rus_bank.rb', line 9

def operations
  @client.operations
end

#RegionsEnumXMLObject



66
67
68
69
70
71
72
73
# File 'lib/rus_bank.rb', line 66

def RegionsEnumXML
  response = call(:regions_enum_xml)
  if response.nil?
    nil
  else
    response[:regions_enum][:rgid]
  end
end

#RegNumToIntCode(reg_num) ⇒ Object



23
24
25
26
# File 'lib/rus_bank.rb', line 23

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

#SearchByNameXML(bank_name) ⇒ Object

Метод возвращает nil, либо массив хэшей



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rus_bank.rb', line 43

def SearchByNameXML(bank_name)    # Метод возвращает nil, либо массив хэшей
  params = { "NamePart" => bank_name }
  response = call(:search_by_name_xml, params)
  if response[:credit_org][:enum_credits].nil?
    nil
  else
    if not response[:credit_org][:enum_credits].instance_of?(Array)      # Если найдена одна запись, возвращается единичный хэш,
      [response[:credit_org][:enum_credits]]                             # если более одной, то массив хешей,
    else                                                                 # поэтому одну запись преобразуем к массиву из одного хэша.
      response[:credit_org][:enum_credits]
    end
  end
end

#SearchByRegionCodeXML(region_code) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/rus_bank.rb', line 33

def SearchByRegionCodeXML(region_code)
  params = { "RegCode" => region_code }
  response = call(:search_by_region_code_xml, params)
  if response.nil?
    nil
  else
    response[:credit_org][:enum_credits]
  end
end