The ktoblzcheck package can be downloaded from
http://ktoblzcheck.sourceforge.net/ as source distribution tar-ball or RPM.
Debian
has a package named 'libktoblzcheck1-dev',
simply apt-get install it.
Download from Rbktoblzcheck Current version: 0.1
After uncompressing the archive cd to the newly created directory and execute the following commands:
$ ruby extconf.rb $ make Optional: $ ruby test-ktoblzcheck.rb $ ruby test-ktoblzcheck-all.rb Become root # make install Type `make --help` for available build options, see documentation for Ruby's mkmf dir_config for options to configure installation location for the extension library.
Example:
-----------------------------------------------------------------------
require 'ktoblzcheck'
$bc="20030700"
$an="0"
puts "Testing Bank Code: #{$bc} / Account No. #{$an}"
KtoBlzCheck.new do |kbc|
name,location=kbc.find($bc)
if name
puts "Bank found! #{name} located in #{location}"
else
puts "Bank not found!"
end
case kbc.check($bc,$an)
when KtoBlzCheck::ERROR
puts "Failed, bank code and account number don't match"
when KtoBlzCheck::OK
puts "Success, valid combination of bank code and account number"
when KtoBlzCheck::UNKNOWN
puts "Unknown."
when KtoBlzCheck::BANK_NOT_KNOWN
puts "Unknown bank code"
else
puts "Never reached :)"
end
end
-----------------------------------------------------------------------
Rails:
class AccountData
attr_accessor :bank_code, :account_no, :name_of_bank
def initialize(data = {})
@bank_code = data["bank_code"].to_s
@account_no = data["account_no"].to_s
@name_of_bank = data["name_of_bank"].to_s
end
end
Controller:
def index
@accountdata = AccountData.new
end
def check
@accountdata = AccountData.new(@params["checkdata"])
msg = nil
KtoBlzCheck.new do |kbc|
case kbc.check(@accountdata.bank_code, @accountdata.account_no)
when KtoBlzCheck::ERROR
msg = "Failed, bank code and account number dont match"
when KtoBlzCheck::OK
msg = "Success, valid combination of bank code and account number"
res = kbc.find(@accountdata.bank_code)
@accountdata.name_of_bank = res[0].to_s
when KtoBlzCheck::UNKNOWN
msg = "Unknown."
when KtoBlzCheck::BANK_NOT_KNOWN
msg = "Unknown bank code"
else
msg = "Never reached :)"
end
end
flash["notice"] = msg
render_action "index"
end
View:
<% if @flash['notice'] -%>
<%= @flash["notice"] -%>
<% end -%>
Create a form
<%= text_field "checkdata", "bank_code", "size" => 20, "maxlength" => 20 %>
...
...
Result:
<%= @accountdata.name_of_bank %>
For more code examples refer to the rbkbc program and the test-*.rb files
provided with this distribution.
-----------------------------------------------------------------------
© 2004-2008 ruby and rails
zopy community
zopy blog