postcodeanywhere_banking 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.md +33 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/httparty_icebox.rb +263 -0
- data/lib/postcodeanywhere_banking.rb +69 -0
- data/spec/postcodeanywhere_banking_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +185 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "httparty"
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "yard", "~> 0.6.0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
crack (0.1.8)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
httparty (0.7.3)
|
8
|
+
crack (= 0.1.8)
|
9
|
+
jeweler (1.5.2)
|
10
|
+
bundler (~> 1.0.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rake (0.8.7)
|
14
|
+
rcov (0.9.9)
|
15
|
+
rspec (2.3.0)
|
16
|
+
rspec-core (~> 2.3.0)
|
17
|
+
rspec-expectations (~> 2.3.0)
|
18
|
+
rspec-mocks (~> 2.3.0)
|
19
|
+
rspec-core (2.3.1)
|
20
|
+
rspec-expectations (2.3.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.3.0)
|
23
|
+
yard (0.6.4)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
httparty
|
31
|
+
jeweler (~> 1.5.2)
|
32
|
+
rcov
|
33
|
+
rspec (~> 2.3.0)
|
34
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Aaron Russell
|
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/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# PostCodeAnywhere BankAccountValidation
|
2
|
+
|
3
|
+
A very simple wrapper for the PostCodeAnywhere [Bank Account Validation API](http://www.postcodeanywhere.co.uk/support/webservices/BankAccountValidation/Interactive/Validate/v2/default.aspx).
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
include PostcodeAnywhere::BankAccountValidation
|
8
|
+
authenticate "AA11-AA11-AA11-AA11"
|
9
|
+
result = validate :account_number => "12345678", :sort_code => "11-22-33"
|
10
|
+
|
11
|
+
if result.error
|
12
|
+
result.error_message => "AccountNumber Required: The AccountNumber parameter was not supplied. Please ensure that you supply the AccountNumber parameter and try again."
|
13
|
+
else
|
14
|
+
result.is_correct => true
|
15
|
+
result.is_direct_debit_capable => true
|
16
|
+
result.status_information => "OK"
|
17
|
+
end
|
18
|
+
|
19
|
+
## Contributing to postcodeanywhere_banking
|
20
|
+
|
21
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
22
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
23
|
+
* Fork the project
|
24
|
+
* Start a feature/bugfix branch
|
25
|
+
* Commit and push until you are happy with your contribution
|
26
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
27
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
28
|
+
|
29
|
+
## Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2011 Aaron Russell. See LICENSE.txt for
|
32
|
+
further details.
|
33
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "postcodeanywhere_banking"
|
16
|
+
gem.homepage = "http://github.com/aaronrussell/postcodeanywhere_banking"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = "A very simple wrapper for the PostCodeAnywhere Bank Account Validation API."
|
19
|
+
gem.description = "A very simple wrapper for the PostCodeAnywhere Bank Account Validation API."
|
20
|
+
gem.email = "aaron@gc4.co.uk"
|
21
|
+
gem.authors = ["Aaron Russell"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
gem.add_runtime_dependency 'httparty'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'yard'
|
43
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,263 @@
|
|
1
|
+
# = Icebox : Caching for HTTParty
|
2
|
+
#
|
3
|
+
# Cache responses in HTTParty models [http://github.com/jnunemaker/httparty]
|
4
|
+
#
|
5
|
+
# === Usage
|
6
|
+
#
|
7
|
+
# class Foo
|
8
|
+
# include HTTParty
|
9
|
+
# include HTTParty::Icebox
|
10
|
+
# cache :store => 'file', :timeout => 600, :location => MY_APP_ROOT.join('tmp', 'cache')
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# Modeled after Martyn Loughran's APICache [http://github.com/newbamboo/api_cache]
|
14
|
+
# and Ruby On Rails's caching [http://api.rubyonrails.org/classes/ActiveSupport/Cache.html]
|
15
|
+
#
|
16
|
+
# Author: Karel Minarik [www.karmi.cz]
|
17
|
+
#
|
18
|
+
# === Notes
|
19
|
+
#
|
20
|
+
# Thanks to Amit Chakradeo for pointing out response objects have to be stored marhalled on FS
|
21
|
+
# Thanks to Marlin Forbes for pointing out the query parameters have to be included in the cache key
|
22
|
+
#
|
23
|
+
#
|
24
|
+
|
25
|
+
require 'logger'
|
26
|
+
require 'ftools'
|
27
|
+
require 'tmpdir'
|
28
|
+
require 'pathname'
|
29
|
+
require 'digest/md5'
|
30
|
+
|
31
|
+
module HTTParty #:nodoc:
|
32
|
+
# == Caching for HTTParty
|
33
|
+
# See documentation in HTTParty::Icebox::ClassMethods.cache
|
34
|
+
#
|
35
|
+
module Icebox
|
36
|
+
|
37
|
+
module ClassMethods
|
38
|
+
|
39
|
+
# Enable caching and set cache options
|
40
|
+
# Returns memoized cache object
|
41
|
+
#
|
42
|
+
# Following options are available, default values are in []:
|
43
|
+
#
|
44
|
+
# +store+:: Storage mechanism for cached data (memory, filesystem, your own) [memory]
|
45
|
+
# +timeout+:: Cache expiration in seconds [60]
|
46
|
+
# +logger+:: Path to logfile or logger instance [nil, silent]
|
47
|
+
#
|
48
|
+
# Any additional options are passed to the Cache constructor
|
49
|
+
#
|
50
|
+
# Usage:
|
51
|
+
#
|
52
|
+
# # Enable caching in HTTParty, in memory, for 1 minute
|
53
|
+
# cache # Use default values
|
54
|
+
#
|
55
|
+
# # Enable caching in HTTParty, on filesystem (/tmp), for 10 minutes
|
56
|
+
# cache :store => 'file', :timeout => 600, :location => '/tmp/'
|
57
|
+
#
|
58
|
+
# # Use your own cache store (see +AbstractStore+ class below)
|
59
|
+
# cache :store => 'memcached', :timeout => 600, :server => '192.168.1.1:1001'
|
60
|
+
#
|
61
|
+
def cache(options={})
|
62
|
+
options[:store] ||= 'memory'
|
63
|
+
options[:timeout] ||= 60
|
64
|
+
logger = options[:logger]
|
65
|
+
@cache ||= Cache.new( options.delete(:store), options )
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# When included, extend class with +cache+ method
|
71
|
+
# and redefine +get+ method to use cache
|
72
|
+
#
|
73
|
+
def self.included(receiver) #:nodoc:
|
74
|
+
receiver.extend ClassMethods
|
75
|
+
receiver.class_eval do
|
76
|
+
|
77
|
+
# Get reponse from network
|
78
|
+
#
|
79
|
+
# TODO: Why alias :new :old is not working here? Returns NoMethodError
|
80
|
+
#
|
81
|
+
def self.get_without_caching(path, options={})
|
82
|
+
perform_request Net::HTTP::Get, path, options
|
83
|
+
end
|
84
|
+
|
85
|
+
# Get response from cache, if available
|
86
|
+
#
|
87
|
+
def self.get_with_caching(path, options={})
|
88
|
+
key = path.downcase # this makes a copy of path
|
89
|
+
key << options[:query].to_s if defined? options[:query]
|
90
|
+
if cache.exists?(key) and not cache.stale?(key)
|
91
|
+
Cache.logger.debug "CACHE -- GET #{path}#{options[:query]}"
|
92
|
+
return cache.get(key)
|
93
|
+
else
|
94
|
+
Cache.logger.debug "/!\\ NETWORK -- GET #{path}#{options[:query]}"
|
95
|
+
response = get_without_caching(path, options)
|
96
|
+
cache.set(key, response) if response.code.to_s == "200" # this works for string and integer response codes
|
97
|
+
return response
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Redefine original HTTParty +get+ method to use cache
|
102
|
+
#
|
103
|
+
def self.get(path, options={})
|
104
|
+
self.get_with_caching(path, options)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# === Cache container
|
111
|
+
#
|
112
|
+
# Pass a store name ('memory', etc) to new
|
113
|
+
#
|
114
|
+
class Cache
|
115
|
+
attr_accessor :store
|
116
|
+
|
117
|
+
def initialize(store, options={})
|
118
|
+
self.class.logger = options[:logger]
|
119
|
+
@store = self.class.lookup_store(store).new(options)
|
120
|
+
end
|
121
|
+
|
122
|
+
def get(key); @store.get encode(key) unless stale?(key); end
|
123
|
+
def set(key, value);puts "Cache.set, key: #{key}, value: #{value}"; @store.set encode(key), value; end
|
124
|
+
def exists?(key); @store.exists? encode(key); end
|
125
|
+
def stale?(key); @store.stale? encode(key); end
|
126
|
+
|
127
|
+
def self.logger; @logger || default_logger; end
|
128
|
+
def self.default_logger; logger = ::Logger.new(STDERR); end
|
129
|
+
|
130
|
+
# Pass a filename (String), IO object, Logger instance or +nil+ to silence the logger
|
131
|
+
def self.logger=(device); @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device); end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
# Return store class based on passed name
|
136
|
+
def self.lookup_store(name)
|
137
|
+
store_name = "#{name.capitalize}Store"
|
138
|
+
return Store::const_get(store_name)
|
139
|
+
rescue NameError => e
|
140
|
+
raise Store::StoreNotFound, "The cache store '#{store_name}' was not found. Did you load any such class?"
|
141
|
+
end
|
142
|
+
|
143
|
+
def encode(key); Digest::MD5.hexdigest(key); end
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# === Cache stores
|
148
|
+
#
|
149
|
+
module Store
|
150
|
+
|
151
|
+
class StoreNotFound < StandardError; end #:nodoc:
|
152
|
+
|
153
|
+
# ==== Abstract Store
|
154
|
+
# Inherit your store from this class
|
155
|
+
# *IMPORTANT*: Do not forget to call +super+ in your +initialize+ method!
|
156
|
+
#
|
157
|
+
class AbstractStore
|
158
|
+
def initialize(options={})
|
159
|
+
raise ArgumentError, "You need to set the :timeout parameter" unless options[:timeout]
|
160
|
+
@timeout = options[:timeout]
|
161
|
+
message = "Cache: Using #{self.class.to_s.split('::').last}"
|
162
|
+
message << " in location: #{options[:location]}" if options[:location]
|
163
|
+
message << " with timeout #{options[:timeout]} sec"
|
164
|
+
Cache.logger.info message unless options[:logger].nil?
|
165
|
+
return self
|
166
|
+
end
|
167
|
+
%w{set get exists? stale?}.each do |method_name|
|
168
|
+
define_method(method_name) { raise NoMethodError, "Please implement method #{method_name} in your store class" }
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# ==== Store objects in memory
|
173
|
+
# See HTTParty::Icebox::ClassMethods.cache
|
174
|
+
#
|
175
|
+
class MemoryStore < AbstractStore
|
176
|
+
def initialize(options={})
|
177
|
+
super; @store = {}; self
|
178
|
+
end
|
179
|
+
def set(key, value)
|
180
|
+
Cache.logger.info("Cache: set (#{key})")
|
181
|
+
@store[key] = [Time.now, value]; true
|
182
|
+
end
|
183
|
+
def get(key)
|
184
|
+
data = @store[key][1]
|
185
|
+
Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
|
186
|
+
data
|
187
|
+
end
|
188
|
+
def exists?(key)
|
189
|
+
!@store[key].nil?
|
190
|
+
end
|
191
|
+
def stale?(key)
|
192
|
+
return true unless exists?(key)
|
193
|
+
Time.now - created(key) > @timeout
|
194
|
+
end
|
195
|
+
private
|
196
|
+
def created(key)
|
197
|
+
@store[key][0]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# ==== Store objects on the filesystem
|
202
|
+
# See HTTParty::Icebox::ClassMethods.cache
|
203
|
+
#
|
204
|
+
class FileStore < AbstractStore
|
205
|
+
def initialize(options={})
|
206
|
+
super
|
207
|
+
options[:location] ||= Dir::tmpdir
|
208
|
+
@path = Pathname.new( options[:location] )
|
209
|
+
FileUtils.mkdir_p( @path )
|
210
|
+
self
|
211
|
+
end
|
212
|
+
def set(key, value)
|
213
|
+
Cache.logger.info("Cache: set (#{key})")
|
214
|
+
File.open( @path.join(key), 'w' ) { |file| file << Marshal.dump(value) }
|
215
|
+
true
|
216
|
+
end
|
217
|
+
def get(key)
|
218
|
+
data = Marshal.load(File.read( @path.join(key)))
|
219
|
+
Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
|
220
|
+
data
|
221
|
+
end
|
222
|
+
def exists?(key)
|
223
|
+
File.exists?( @path.join(key) )
|
224
|
+
end
|
225
|
+
def stale?(key)
|
226
|
+
return true unless exists?(key)
|
227
|
+
Time.now - created(key) > @timeout
|
228
|
+
end
|
229
|
+
private
|
230
|
+
def created(key)
|
231
|
+
File.mtime( @path.join(key) )
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
# Major parts of this code are based on architecture of ApiCache.
|
241
|
+
# Copyright (c) 2008 Martyn Loughran
|
242
|
+
#
|
243
|
+
# Other parts are inspired by the ActiveSupport::Cache in Ruby On Rails.
|
244
|
+
# Copyright (c) 2005-2009 David Heinemeier Hansson
|
245
|
+
#
|
246
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
247
|
+
# a copy of this software and associated documentation files (the
|
248
|
+
# "Software"), to deal in the Software without restriction, including
|
249
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
250
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
251
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
252
|
+
# the following conditions:
|
253
|
+
#
|
254
|
+
# The above copyright notice and this permission notice shall be
|
255
|
+
# included in all copies or substantial portions of the Software.
|
256
|
+
#
|
257
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
258
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
259
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
260
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
261
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
262
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
263
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require File.join(File.dirname(__FILE__), "httparty_icebox")
|
3
|
+
|
4
|
+
module PostcodeAnywhere
|
5
|
+
|
6
|
+
class BankAccountValidation
|
7
|
+
|
8
|
+
HEADERS = {
|
9
|
+
"User-Agent" => "Ruby.PostcodeAnywhere.BankAccountValidation",
|
10
|
+
"Accept" => "application/json",
|
11
|
+
"Content-Type" => "application/json"
|
12
|
+
}
|
13
|
+
|
14
|
+
include HTTParty
|
15
|
+
include HTTParty::Icebox
|
16
|
+
|
17
|
+
base_uri "https://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive/Validate/v2.00/"
|
18
|
+
headers HEADERS
|
19
|
+
format :json
|
20
|
+
cache :timeout => 43200
|
21
|
+
|
22
|
+
def self.authenticate(api_key)
|
23
|
+
default_params "Key" => api_key
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.validate(opts)
|
27
|
+
res = get "/json.ws", :query => {"AccountNumber" => opts[:account_number], "SortCode" => opts[:sort_code]}
|
28
|
+
res.code == 200 ? BankAccountValidationResponse.new(res.parsed_response[0]) : res
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class BankAccountValidationResponse
|
34
|
+
|
35
|
+
attr_reader :is_correct, :is_direct_debit_capable, :status_nformation, :corrected_sort_code, :corrected_account_number,
|
36
|
+
:iban, :bank, :bank_bic, :branch, :branch_bic, :faster_payments_supported, :chaps_supported,
|
37
|
+
:contact_address_line1, :contact_address_line2, :contact_post_town, :contact_postcode, :contact_phone, :contact_fax
|
38
|
+
attr_reader :error, :error_code, :error_message, :description, :cause, :resolution
|
39
|
+
|
40
|
+
def initialize(res = {})
|
41
|
+
res.keys.each do |att|
|
42
|
+
instance_variable_set "@#{underscore(att)}".to_sym, res[att]
|
43
|
+
end
|
44
|
+
@error = res["Error"] ? true : false
|
45
|
+
if @error
|
46
|
+
@error_code = res["Error"]
|
47
|
+
@error_message = "#{@description}: #{@cause} #{@resolution}"
|
48
|
+
else
|
49
|
+
["@is_correct", "@is_direct_debit_capable", "@faster_payments_supported", "@chaps_supported"].each do |att|
|
50
|
+
instance_variable_set att.to_sym, (instance_variable_get(att) == "True" ? true : false)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def underscore(camel_cased_word)
|
58
|
+
word = camel_cased_word.to_s.dup
|
59
|
+
word.gsub!(/::/, '/')
|
60
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
61
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
62
|
+
word.tr!("-", "_")
|
63
|
+
word.downcase!
|
64
|
+
word
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'postcodeanywhere-banking'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: postcodeanywhere_banking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Aaron Russell
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-28 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
name: httparty
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 3
|
45
|
+
- 0
|
46
|
+
version: 2.3.0
|
47
|
+
type: :development
|
48
|
+
name: rspec
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 7
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 6
|
61
|
+
- 0
|
62
|
+
version: 0.6.0
|
63
|
+
type: :development
|
64
|
+
name: yard
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 23
|
74
|
+
segments:
|
75
|
+
- 1
|
76
|
+
- 0
|
77
|
+
- 0
|
78
|
+
version: 1.0.0
|
79
|
+
type: :development
|
80
|
+
name: bundler
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 7
|
90
|
+
segments:
|
91
|
+
- 1
|
92
|
+
- 5
|
93
|
+
- 2
|
94
|
+
version: 1.5.2
|
95
|
+
type: :development
|
96
|
+
name: jeweler
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
type: :development
|
110
|
+
name: rcov
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *id006
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
type: :runtime
|
124
|
+
name: httparty
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: *id007
|
127
|
+
description: A very simple wrapper for the PostCodeAnywhere Bank Account Validation API.
|
128
|
+
email: aaron@gc4.co.uk
|
129
|
+
executables: []
|
130
|
+
|
131
|
+
extensions: []
|
132
|
+
|
133
|
+
extra_rdoc_files:
|
134
|
+
- LICENSE.txt
|
135
|
+
- README.md
|
136
|
+
files:
|
137
|
+
- .document
|
138
|
+
- .rspec
|
139
|
+
- Gemfile
|
140
|
+
- Gemfile.lock
|
141
|
+
- LICENSE.txt
|
142
|
+
- README.md
|
143
|
+
- Rakefile
|
144
|
+
- VERSION
|
145
|
+
- lib/httparty_icebox.rb
|
146
|
+
- lib/postcodeanywhere_banking.rb
|
147
|
+
- spec/postcodeanywhere_banking_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
has_rdoc: true
|
150
|
+
homepage: http://github.com/aaronrussell/postcodeanywhere_banking
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
|
156
|
+
require_paths:
|
157
|
+
- lib
|
158
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
|
+
none: false
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
hash: 3
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
version: "0"
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 3
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
requirements: []
|
177
|
+
|
178
|
+
rubyforge_project:
|
179
|
+
rubygems_version: 1.3.7
|
180
|
+
signing_key:
|
181
|
+
specification_version: 3
|
182
|
+
summary: A very simple wrapper for the PostCodeAnywhere Bank Account Validation API.
|
183
|
+
test_files:
|
184
|
+
- spec/postcodeanywhere_banking_spec.rb
|
185
|
+
- spec/spec_helper.rb
|