rus_bank_rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/generators/rus_bank_rails_generator.rb +18 -0
- data/lib/generators/rus_bank_rails_generator/USAGE +9 -0
- data/lib/generators/rus_bank_rails_generator/templates/migration.rb +26 -0
- data/lib/generators/rus_bank_rails_generator/templates/model.rb +3 -0
- data/lib/rus_bank_rails.rb +4 -0
- data/lib/rus_bank_rails/acts_as_bank.rb +133 -0
- data/lib/rus_bank_rails/version.rb +3 -0
- data/lib/tasks/rus_bank_rails_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/bank.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140126153450_create_banks.rb +7 -0
- data/test/dummy/db/migrate/20140126171627_add_fields_to_banks.rb +23 -0
- data/test/dummy/db/schema.rb +40 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +1338 -0
- data/test/dummy/log/test.log +7294 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/fixtures/banks.yml +7 -0
- data/test/dummy/test/models/bank_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 671510be9988431965721054876afe03d7d49367
|
4
|
+
data.tar.gz: ce78ac2be25277e4f0bcf83c4fdc5b7440be2384
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 795fba742e4addff50e99eee350b19a9e2af15c4b708e0f8324041820681e5e0bad41883c62edd54a4b48ea2103f938ab3ae37ce9dd3cf9ace710121f83e60af
|
7
|
+
data.tar.gz: 105b35174624be0d57c83d6b8a760c7b490e4cfb5e020e1d6e8f4a507b80ca770787e989827c38b2ae11d55437c1cb359e12ac2f3691ce40306619541529a1c4
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Alexsandrov Denis
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RusBankRails'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class RusBankRailsGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../rus_bank_rails_generator', __FILE__)
|
3
|
+
|
4
|
+
def generate
|
5
|
+
migration_file_name = "db/migrate/#{Time.now.strftime("%Y%m%d%H%M%S")}_create_#{plural_name.parameterize.underscore}.rb"
|
6
|
+
model_file_name = "app/models/#{file_name.parameterize.underscore}.rb"
|
7
|
+
|
8
|
+
copy_file "templates/migration.rb", migration_file_name
|
9
|
+
copy_file "templates/model.rb", model_file_name
|
10
|
+
|
11
|
+
gsub_file migration_file_name, 'CreateMigration', "create_#{plural_name.parameterize.underscore}".camelize
|
12
|
+
gsub_file migration_file_name, 'table_name', ":#{plural_name.parameterize.underscore}"
|
13
|
+
|
14
|
+
gsub_file model_file_name, 'ModelName', "#{file_name.parameterize.underscore.camelize}"
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateMigration < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table table_name, force: true do |t|
|
4
|
+
t.integer "reg_number"
|
5
|
+
t.integer "internal_code"
|
6
|
+
t.string "bic"
|
7
|
+
t.string "org_name"
|
8
|
+
t.string "org_full_name"
|
9
|
+
t.string "phones"
|
10
|
+
t.date "date_kgr_registration"
|
11
|
+
t.string "main_reg_number"
|
12
|
+
t.date "main_date_reg"
|
13
|
+
t.string "ustav_adr"
|
14
|
+
t.string "fact_adr"
|
15
|
+
t.string "director"
|
16
|
+
t.integer "ust_money"
|
17
|
+
t.string "org_status"
|
18
|
+
t.integer "reg_code"
|
19
|
+
t.date "ssv_date"
|
20
|
+
t.integer "l_code"
|
21
|
+
t.string "lt"
|
22
|
+
t.date "l_date"
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module RusBankRails
|
2
|
+
module ActsAsBank
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def acts_as_bank
|
10
|
+
include RusBankRails::ActsAsBank::LocalInstanceMethods
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module LocalInstanceMethods
|
15
|
+
##
|
16
|
+
# Метод возвращает внутренний номер банка по БИК
|
17
|
+
|
18
|
+
def BicToIntCode(bic)
|
19
|
+
resp = check_and_update(bic)
|
20
|
+
resp ? resp.internal_code : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Метод возвращает регистрационный номер банка по БИК
|
25
|
+
|
26
|
+
def BicToRegNumber(bic)
|
27
|
+
resp = check_and_update(bic)
|
28
|
+
resp ? resp.reg_number : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Возвращает регистрационный номер банка по внутреннему номеру
|
33
|
+
|
34
|
+
def RegNumToIntCode(reg_number)
|
35
|
+
bank = self.class.find_by_reg_number(reg_number.to_i)
|
36
|
+
get_int_code_by_reg_number = lambda {
|
37
|
+
begin
|
38
|
+
cbr = RusBank.new
|
39
|
+
internal_code = cbr.RegNumToIntCode(reg_number)
|
40
|
+
bic = cbr.CreditInfoByIntCode(internal_code)[:co][:bic]
|
41
|
+
check_and_update(bic)
|
42
|
+
return internal_code.to_i
|
43
|
+
rescue SocketError, Savon::SOAPFault => e
|
44
|
+
handle_exception(e)
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
}
|
48
|
+
if bank.nil?
|
49
|
+
get_int_code_by_reg_number[]
|
50
|
+
else
|
51
|
+
resp = check_and_update(bank.bic)
|
52
|
+
if resp.reg_number == reg_number.to_i # на случай если после обновления записи в базе reg_number
|
53
|
+
resp.internal_code # поменялся и найденный банк из базы становится неактуальным
|
54
|
+
else
|
55
|
+
get_int_code_by_reg_number[]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
##
|
63
|
+
# Метод проверяет дату обновления записи в базе и пытается обновить в случае необходимости
|
64
|
+
|
65
|
+
def check_and_update(bic)
|
66
|
+
bank = self.class.find_by_bic(bic)
|
67
|
+
if bank.nil?
|
68
|
+
new_bank(bic)
|
69
|
+
else
|
70
|
+
if bank.updated_at < 1.minute.ago
|
71
|
+
update_bank(bank)
|
72
|
+
else
|
73
|
+
bank
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Метод создает новый банк в базе
|
80
|
+
|
81
|
+
def new_bank(bic)
|
82
|
+
if info = get_info(bic)
|
83
|
+
bank = self.class.new(info)
|
84
|
+
bank.save
|
85
|
+
bank
|
86
|
+
else
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
##
|
93
|
+
# Обновляет переданный экземпляр банка в базе
|
94
|
+
|
95
|
+
def update_bank(bank)
|
96
|
+
info = get_info(bank.bic)
|
97
|
+
bank.update(info.merge(updated_at: Time.now)) unless info.nil?
|
98
|
+
bank
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# Метод возвращает актуальную информацию по банку с сайта ЦБР
|
103
|
+
|
104
|
+
def get_info(bic)
|
105
|
+
begin
|
106
|
+
cbr = RusBank.new
|
107
|
+
internal_code = cbr.BicToIntCode(bic)
|
108
|
+
reg_number = cbr.BicToRegNumber(bic)
|
109
|
+
info = cbr.CreditInfoByIntCode(internal_code) if internal_code
|
110
|
+
rescue SocketError, Savon::SOAPFault => e
|
111
|
+
handle_exception(e)
|
112
|
+
return nil
|
113
|
+
end
|
114
|
+
|
115
|
+
if internal_code && reg_number && info
|
116
|
+
info[:co].merge(info[:lic]).merge(internal_code: internal_code, reg_number: reg_number)
|
117
|
+
else
|
118
|
+
nil
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def handle_exception(e)
|
123
|
+
puts "========== ========== =========="
|
124
|
+
puts e.inspect
|
125
|
+
puts "========== ========== =========="
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
ActiveRecord::Base.send :include, RusBankRails::ActsAsBank
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "rus_bank_rails"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|