esortcode 0.9.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.
- data.tar.gz.sig +0 -0
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +33 -0
- data/README.txt +3 -0
- data/Rakefile +138 -0
- data/lib/e_sort_code.rb +3 -0
- data/lib/esortcode.rb +5 -0
- data/lib/esortcode/client.rb +142 -0
- data/lib/esortcode/exception.rb +9 -0
- data/lib/esortcode/industry_sort_code_directory.rb +19 -0
- data/lib/esortcode/response.rb +5 -0
- data/lib/esortcode/response/base.rb +41 -0
- data/lib/esortcode/response/branch_details.rb +10 -0
- data/lib/esortcode/response/standardise_account.rb +23 -0
- data/lib/esortcode/response/validate_account.rb +5 -0
- data/lib/esortcode/response/validate_credit_card.rb +14 -0
- data/lib/esortcode/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/spec/client_spec.rb +13 -0
- data/spec/esortcode_spec.rb +9 -0
- data/spec/response/branch_details_spec.rb +324 -0
- data/spec/response/common_spec.rb +57 -0
- data/spec/response/standardise_account_spec.rb +96 -0
- data/spec/response/validate_account_spec.rb +72 -0
- data/spec/response/validate_credit_card_spec.rb +81 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +4 -0
- data/website/index.html +11 -0
- data/website/index.txt +38 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +106 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Geoff Garside
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
lib/e_sort_code.rb
|
7
|
+
lib/esortcode.rb
|
8
|
+
lib/esortcode/client.rb
|
9
|
+
lib/esortcode/exception.rb
|
10
|
+
lib/esortcode/industry_sort_code_directory.rb
|
11
|
+
lib/esortcode/response.rb
|
12
|
+
lib/esortcode/response/base.rb
|
13
|
+
lib/esortcode/response/branch_details.rb
|
14
|
+
lib/esortcode/response/standardise_account.rb
|
15
|
+
lib/esortcode/response/validate_account.rb
|
16
|
+
lib/esortcode/response/validate_credit_card.rb
|
17
|
+
lib/esortcode/version.rb
|
18
|
+
scripts/txt2html
|
19
|
+
setup.rb
|
20
|
+
spec/client_spec.rb
|
21
|
+
spec/esortcode_spec.rb
|
22
|
+
spec/response/branch_details_spec.rb
|
23
|
+
spec/response/common_spec.rb
|
24
|
+
spec/response/standardise_account_spec.rb
|
25
|
+
spec/response/validate_account_spec.rb
|
26
|
+
spec/response/validate_credit_card_spec.rb
|
27
|
+
spec/spec.opts
|
28
|
+
spec/spec_helper.rb
|
29
|
+
website/index.html
|
30
|
+
website/index.txt
|
31
|
+
website/javascripts/rounded_corners_lite.inc.js
|
32
|
+
website/stylesheets/screen.css
|
33
|
+
website/template.rhtml
|
data/README.txt
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rake/packagetask'
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
require 'rake/rdoctask'
|
8
|
+
require 'rake/contrib/rubyforgepublisher'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'hoe'
|
11
|
+
begin
|
12
|
+
require 'spec/rake/spectask'
|
13
|
+
rescue LoadError
|
14
|
+
puts 'To use rspec for testing you must install rspec gem:'
|
15
|
+
puts '$ sudo gem install rspec'
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
include FileUtils
|
20
|
+
require File.join(File.dirname(__FILE__), 'lib', 'esortcode', 'version')
|
21
|
+
|
22
|
+
AUTHOR = 'Geoff Garside' # can also be an array of Authors
|
23
|
+
EMAIL = "geoff.garside@openhosting.co.uk"
|
24
|
+
DESCRIPTION = "Ruby interface to eSortCode UK Account and Bank Branch validator"
|
25
|
+
GEM_NAME = 'esortcode' # what ppl will type to install your gem
|
26
|
+
|
27
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
28
|
+
@config = nil
|
29
|
+
def rubyforge_username
|
30
|
+
unless @config
|
31
|
+
begin
|
32
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
33
|
+
rescue
|
34
|
+
puts <<-EOS
|
35
|
+
ERROR: No rubyforge config file found: #{@config_file}"
|
36
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
37
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
38
|
+
EOS
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@rubyforge_username ||= @config["username"]
|
43
|
+
end
|
44
|
+
|
45
|
+
RUBYFORGE_PROJECT = 'esortcode' # The unix name for your project
|
46
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
47
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
48
|
+
|
49
|
+
NAME = "esortcode"
|
50
|
+
REV = nil
|
51
|
+
# UNCOMMENT IF REQUIRED:
|
52
|
+
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
53
|
+
VERS = ESortCode::VERSION::STRING + (REV ? ".#{REV}" : "")
|
54
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
|
55
|
+
RDOC_OPTS = ['--quiet', '--title', 'eSortCode documentation',
|
56
|
+
"--opname", "index.html",
|
57
|
+
"--line-numbers",
|
58
|
+
"--main", "README",
|
59
|
+
"--inline-source"]
|
60
|
+
|
61
|
+
class Hoe
|
62
|
+
def extra_deps
|
63
|
+
@extra_deps.reject { |x| Array(x).first == 'hoe' }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Generate all the Rake tasks
|
68
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
69
|
+
hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
70
|
+
p.author = AUTHOR
|
71
|
+
p.description = DESCRIPTION
|
72
|
+
p.email = EMAIL
|
73
|
+
p.summary = DESCRIPTION
|
74
|
+
p.url = HOMEPATH
|
75
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
76
|
+
p.test_globs = ["test/**/test_*.rb"]
|
77
|
+
p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
|
78
|
+
|
79
|
+
# == Optional
|
80
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
81
|
+
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
82
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
83
|
+
end
|
84
|
+
|
85
|
+
CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
|
86
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
87
|
+
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
88
|
+
|
89
|
+
desc 'Generate website files'
|
90
|
+
task :website_generate do
|
91
|
+
Dir['website/**/*.txt'].each do |txt|
|
92
|
+
sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
desc 'Upload website files to rubyforge'
|
97
|
+
task :website_upload do
|
98
|
+
host = "#{rubyforge_username}@rubyforge.org"
|
99
|
+
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
100
|
+
local_dir = 'website'
|
101
|
+
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'Generate and upload website files'
|
105
|
+
task :website => [:website_generate, :website_upload, :publish_docs]
|
106
|
+
|
107
|
+
desc 'Release the website and new gem version'
|
108
|
+
task :deploy => [:check_version, :website, :release] do
|
109
|
+
puts "Remember to create SVN tag:"
|
110
|
+
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
111
|
+
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
112
|
+
puts "Suggested comment:"
|
113
|
+
puts "Tagging release #{CHANGES}"
|
114
|
+
end
|
115
|
+
|
116
|
+
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
117
|
+
task :local_deploy => [:website_generate, :install_gem]
|
118
|
+
|
119
|
+
task :check_version do
|
120
|
+
unless ENV['VERSION']
|
121
|
+
puts 'Must pass a VERSION=x.y.z release version'
|
122
|
+
exit
|
123
|
+
end
|
124
|
+
unless ENV['VERSION'] == VERS
|
125
|
+
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
126
|
+
exit
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
desc "Run the specs under spec/models"
|
131
|
+
Spec::Rake::SpecTask.new do |t|
|
132
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
133
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
134
|
+
end
|
135
|
+
|
136
|
+
desc "Default task is to run specs"
|
137
|
+
task :default => :spec
|
138
|
+
|
data/lib/e_sort_code.rb
ADDED
data/lib/esortcode.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
|
4
|
+
module ESortCode
|
5
|
+
class Client
|
6
|
+
BASE_URL = 'https://ws.esortcode.com/bankdetails.asmx'
|
7
|
+
USER_AGENT = "Ruby eSortCode Client v#{ESortCode::VERSION::STRING}"
|
8
|
+
|
9
|
+
def initialize(login = nil, guid = nil)
|
10
|
+
@account = login ? login : @@account
|
11
|
+
@guid = guid ? guid : @@guid
|
12
|
+
@uri = URI.parse(BASE_URL)
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def account_name=(val)
|
17
|
+
@@account = val
|
18
|
+
end
|
19
|
+
def account_name
|
20
|
+
@@account
|
21
|
+
end
|
22
|
+
|
23
|
+
def guid=(val)
|
24
|
+
@@guid = val
|
25
|
+
end
|
26
|
+
def guid
|
27
|
+
@@guid
|
28
|
+
end
|
29
|
+
|
30
|
+
alias :license_id= :guid=
|
31
|
+
alias :license_id :guid
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_account(sort_code, account_number)
|
35
|
+
unless sort_code.match(/^[0-9]{6}$/)
|
36
|
+
raise Exception::InvalidSortcode,
|
37
|
+
"#{sort_code} is not valid"
|
38
|
+
end
|
39
|
+
|
40
|
+
unless account_number.match(/^[0-9]{8}$/)
|
41
|
+
raise Exception::InvalidAccountNumber,
|
42
|
+
"#{account_number} is not valid"
|
43
|
+
end
|
44
|
+
|
45
|
+
Response::ValidateAccount.new(
|
46
|
+
request('ValidateAccount', :sSortcode => sort_code,
|
47
|
+
:sAccountNumber => account_number))
|
48
|
+
end
|
49
|
+
|
50
|
+
def branch_details(sort_code)
|
51
|
+
unless sort_code.match(/^[0-9]{6}$/)
|
52
|
+
raise Exception::InvalidSortcode,
|
53
|
+
"#{sort_code} is not valid"
|
54
|
+
end
|
55
|
+
|
56
|
+
Response::BranchDetails.new(
|
57
|
+
request('BranchDetails', :sSortcode => sort_code))
|
58
|
+
end
|
59
|
+
|
60
|
+
def standardise_account(sort_code, account_number)
|
61
|
+
unless sort_code.match(/^[0-9]{6}$/)
|
62
|
+
raise Exception::InvalidSortcode,
|
63
|
+
"#{sort_code} is not valid"
|
64
|
+
end
|
65
|
+
|
66
|
+
unless account_number.match(/^[0-9]{8}$/)
|
67
|
+
raise Exception::InvalidAccountNumber,
|
68
|
+
"#{account_number} is not valid"
|
69
|
+
end
|
70
|
+
|
71
|
+
Response::StandardiseAccount.new(
|
72
|
+
request('StandardiseAccount', :sSortcode => sort_code,
|
73
|
+
:sAccountNumber => account_number))
|
74
|
+
end
|
75
|
+
|
76
|
+
def validate_account_get_branch_details(sort_code, account_number)
|
77
|
+
unless sort_code.match(/^[0-9]{6}$/)
|
78
|
+
raise Exception::InvalidSortcode,
|
79
|
+
"#{sort_code} is not valid"
|
80
|
+
end
|
81
|
+
|
82
|
+
unless account_number.match(/^[0-9]{6,10}$/)
|
83
|
+
raise Exception::InvalidAccountNumber,
|
84
|
+
"#{account_number} is not valid"
|
85
|
+
end
|
86
|
+
|
87
|
+
Response::BranchDetails.new(
|
88
|
+
request('ValidateAccountGetBranchDetails',
|
89
|
+
:sSortcode => sort_code,
|
90
|
+
:sAccountNumber => account_number))
|
91
|
+
end
|
92
|
+
|
93
|
+
def validate_credit_card(credit_card_number)
|
94
|
+
unless credit_card_number.match(/[0-9]+/)
|
95
|
+
raise Exception::InvalidCreditCardNumber,
|
96
|
+
"#{credit_card_number} is not valid"
|
97
|
+
end
|
98
|
+
|
99
|
+
Response::ValidateCreditCard.new(
|
100
|
+
request('ValidateCreditCard',
|
101
|
+
:sCreditCardNumber => credit_card_number))
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
def request(action, args = {}, attempts = 3)
|
106
|
+
begin
|
107
|
+
s_client = Net::HTTP.new(@uri.host, @uri.port)
|
108
|
+
s_client.use_ssl = true
|
109
|
+
|
110
|
+
@resp = s_client.start do |https|
|
111
|
+
@request = Net::HTTP::Post.new([@uri.path, action].join('/'))
|
112
|
+
@request.add_field('User-Agent', USER_AGENT)
|
113
|
+
@request.set_form_data(post_data.merge(args))
|
114
|
+
|
115
|
+
https.request(@request)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Handle the response
|
119
|
+
case @resp
|
120
|
+
when Net::HTTPSuccess
|
121
|
+
@resp.body
|
122
|
+
else
|
123
|
+
@resp.error!
|
124
|
+
end
|
125
|
+
rescue Timeout::Error => e
|
126
|
+
if attempts == 1
|
127
|
+
raise e
|
128
|
+
else
|
129
|
+
request(action, args, attempts - 1)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def post_data
|
135
|
+
{
|
136
|
+
:sUserName => @account,
|
137
|
+
:sGUID => @guid,
|
138
|
+
:sIPAddress => ''
|
139
|
+
}
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ESortCode
|
2
|
+
module Exception
|
3
|
+
class GeneralError < ::Exception; end
|
4
|
+
class ValidationError < ::Exception; end
|
5
|
+
class InvalidSortcode < ::Exception; end
|
6
|
+
class InvalidAccountNumber < ::Exception; end
|
7
|
+
class InvalidCreditCardNumber < ::Exception; end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ESortCode
|
2
|
+
class IndustrySortCodeDirectory
|
3
|
+
def initialize(xml_doc)
|
4
|
+
@xml = xml_doc
|
5
|
+
@fields = Hash.new
|
6
|
+
end
|
7
|
+
|
8
|
+
# We cache the requested entries in a hash for
|
9
|
+
# quicker repeated access to
|
10
|
+
def [](v)
|
11
|
+
unless @fields.has_key?(v)
|
12
|
+
t = @xml.get_text("*/#{v}")
|
13
|
+
@fields[v] = t && t.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
@fields[v]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
|
3
|
+
module ESortCode
|
4
|
+
module Response
|
5
|
+
class Base
|
6
|
+
def initialize(xml_data)
|
7
|
+
@xml = REXML::Document.new(xml_data)
|
8
|
+
end
|
9
|
+
|
10
|
+
def valid?
|
11
|
+
@valid ||= (@xml.get_text('*/ValidationMessage') == 'VALID')
|
12
|
+
end
|
13
|
+
|
14
|
+
def invalid_message
|
15
|
+
unless valid?
|
16
|
+
@invalid_message ||= (message_from(@xml.get_text('*/ValidationMessage')))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_error?
|
21
|
+
@has_error ||= (@xml.get_text('*/IsError') == 'true')
|
22
|
+
end
|
23
|
+
|
24
|
+
def error
|
25
|
+
if has_error?
|
26
|
+
@error ||= (message_from(@xml.get_text('*/ErrorMessage')))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def error!
|
31
|
+
raise ESortCode::Exception::GeneralError, error if has_error?
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def message_from(str)
|
36
|
+
return nil if str.nil?
|
37
|
+
str.to_s.split(':',2)[1].strip.gsub('"', '')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|