diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..1dec3c4
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,29 @@
+name: Ruby CI
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+jobs:
+ test:
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ ruby-version: ['3.1', '2.7', '2.5']
+
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up Ruby ${{ matrix.ruby-version }}
+ uses: ruby/setup-ruby@359bebbc29cbe6c87da6bc9ea3bc930432750108
+ with:
+ ruby-version: ${{ matrix.ruby-version }}
+ - name: Install dependencies
+ run: bundle install
+ - name: Run tests
+ run: bundle exec rake
+ - name: Run rubocop
+ run: bundle exec rubocop
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..2d61729
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,8 @@
+inherit_from: .rubocop_todo.yml
+
+AllCops:
+ DisplayCopNames: true
+ DisplayStyleGuide: true
+ ExtraDetails: true
+ UseCache: true
+ NewCops: enable
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
new file mode 100644
index 0000000..014768f
--- /dev/null
+++ b/.rubocop_todo.yml
@@ -0,0 +1,78 @@
+# This configuration was generated by
+# `rubocop --auto-gen-config --exclude-limit 99999999`
+# on 2023-04-19 12:16:33 UTC using RuboCop version 1.28.2.
+# The point is for the user to remove these configuration records
+# one by one as the offenses are removed from the code base.
+# Note that changes in the inspected code, or installation of new
+# versions of RuboCop, may require this file to be generated again.
+
+# Offense count: 1
+# Configuration parameters: Include.
+# Include: **/*.gemspec
+Gemspec/RequiredRubyVersion:
+ Exclude:
+ - 'ruby-postcodeanywhere.gemspec'
+
+# Offense count: 1
+# Configuration parameters: AllowComments, AllowEmptyLambdas.
+Lint/EmptyBlock:
+ Exclude:
+ - 'spec/spec_helper.rb'
+
+# Offense count: 1
+Lint/MissingSuper:
+ Exclude:
+ - 'lib/postcode_anywhere/bank_account_validation.rb'
+
+# Offense count: 2
+# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
+Metrics/AbcSize:
+ Max: 58
+
+# Offense count: 1
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
+# IgnoredMethods: refine
+Metrics/BlockLength:
+ Max: 82
+
+# Offense count: 2
+# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
+Metrics/MethodLength:
+ Max: 26
+
+# Offense count: 1
+# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
+# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
+# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
+Naming/FileName:
+ Exclude:
+ - 'lib/ruby-postcodeanywhere.rb'
+
+# Offense count: 5
+# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
+# SupportedStyles: snake_case, normalcase, non_integer
+# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
+Naming/VariableNumber:
+ Exclude:
+ - 'lib/ruby-postcodeanywhere.rb'
+
+# Offense count: 2
+Style/ClassVars:
+ Exclude:
+ - 'lib/ruby-postcodeanywhere.rb'
+
+# Offense count: 5
+# Configuration parameters: AllowedConstants.
+Style/Documentation:
+ Exclude:
+ - 'spec/**/*'
+ - 'test/**/*'
+ - 'lib/postcode_anywhere/bank_account_validation.rb'
+ - 'lib/ruby-postcodeanywhere.rb'
+
+# Offense count: 2
+# This cop supports safe auto-correction (--auto-correct).
+# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
+# URISchemes: http, https
+Layout/LineLength:
+ Max: 200
diff --git a/.ruby-version b/.ruby-version
new file mode 100644
index 0000000..30f69e8
--- /dev/null
+++ b/.ruby-version
@@ -0,0 +1 @@
+2.5.9
diff --git a/Gemfile b/Gemfile
index a64bcbb..7dd4445 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,14 +1,12 @@
-source "http://rubygems.org"
+# frozen_string_literal: true
-gem "httparty"
+source 'http://rubygems.org'
-gem "activesupport"
-gem "i18n"
+gemspec
-group :development do
- gem "rspec"
- gem "bundler"
- gem "jeweler", "~> 1.6.2"
- gem "rcov", ">= 0"
- gem "webmock", :require => false
+group :development, :test do
+ gem 'rake'
+ gem 'rspec'
+ gem 'rubocop'
+ gem 'webmock', require: false
end
diff --git a/Gemfile.lock b/Gemfile.lock
index f7ec29b..4046a02 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,43 +1,86 @@
+PATH
+ remote: .
+ specs:
+ ruby-postcodeanywhere (0.2.0)
+ activesupport
+ httparty
+
GEM
remote: http://rubygems.org/
specs:
- activesupport (3.1.1)
- multi_json (~> 1.0)
- addressable (2.2.7)
- crack (0.1.8)
- diff-lcs (1.1.3)
- git (1.2.5)
- httparty (0.7.8)
- crack (= 0.1.8)
- i18n (0.6.0)
- jeweler (1.6.2)
- bundler (~> 1.0)
- git (>= 1.2.5)
- rake
- multi_json (1.0.4)
- rake (0.9.2)
- rcov (0.9.9)
- rspec (2.8.0)
- rspec-core (~> 2.8.0)
- rspec-expectations (~> 2.8.0)
- rspec-mocks (~> 2.8.0)
- rspec-core (2.8.0)
- rspec-expectations (2.8.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.8.0)
- webmock (1.8.0)
- addressable (>= 2.2.7)
- crack (>= 0.1.7)
+ activesupport (6.1.7.3)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 1.6, < 2)
+ minitest (>= 5.1)
+ tzinfo (~> 2.0)
+ zeitwerk (~> 2.3)
+ addressable (2.8.4)
+ public_suffix (>= 2.0.2, < 6.0)
+ ast (2.4.2)
+ concurrent-ruby (1.2.2)
+ crack (0.4.5)
+ rexml
+ diff-lcs (1.5.0)
+ hashdiff (1.0.1)
+ httparty (0.21.0)
+ mini_mime (>= 1.0.0)
+ multi_xml (>= 0.5.2)
+ i18n (1.12.0)
+ concurrent-ruby (~> 1.0)
+ mini_mime (1.1.2)
+ minitest (5.15.0)
+ multi_xml (0.6.0)
+ parallel (1.23.0)
+ parser (3.2.2.0)
+ ast (~> 2.4.1)
+ public_suffix (4.0.7)
+ rainbow (3.1.1)
+ rake (13.0.6)
+ regexp_parser (2.8.0)
+ rexml (3.2.5)
+ rspec (3.12.0)
+ rspec-core (~> 3.12.0)
+ rspec-expectations (~> 3.12.0)
+ rspec-mocks (~> 3.12.0)
+ rspec-core (3.12.2)
+ rspec-support (~> 3.12.0)
+ rspec-expectations (3.12.3)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.12.0)
+ rspec-mocks (3.12.5)
+ diff-lcs (>= 1.2.0, < 2.0)
+ rspec-support (~> 3.12.0)
+ rspec-support (3.12.0)
+ rubocop (1.28.2)
+ parallel (~> 1.10)
+ parser (>= 3.1.0.0)
+ rainbow (>= 2.2.2, < 4.0)
+ regexp_parser (>= 1.8, < 3.0)
+ rexml
+ rubocop-ast (>= 1.17.0, < 2.0)
+ ruby-progressbar (~> 1.7)
+ unicode-display_width (>= 1.4.0, < 3.0)
+ rubocop-ast (1.17.0)
+ parser (>= 3.1.1.0)
+ ruby-progressbar (1.13.0)
+ tzinfo (2.0.6)
+ concurrent-ruby (~> 1.0)
+ unicode-display_width (2.4.2)
+ webmock (3.18.1)
+ addressable (>= 2.8.0)
+ crack (>= 0.3.2)
+ hashdiff (>= 0.4.0, < 2.0.0)
+ zeitwerk (2.6.7)
PLATFORMS
ruby
DEPENDENCIES
- activesupport
- bundler
- httparty
- i18n
- jeweler (~> 1.6.2)
- rcov
+ rake
rspec
+ rubocop
+ ruby-postcodeanywhere!
webmock
+
+BUNDLED WITH
+ 1.17.3
diff --git a/Postcode Anywhere.tmproj b/Postcode Anywhere.tmproj
deleted file mode 100644
index 4c289d3..0000000
--- a/Postcode Anywhere.tmproj
+++ /dev/null
@@ -1,184 +0,0 @@
-
-
-
-
- currentDocument
- lib/ruby-postcodeanywhere.rb
- documents
-
-
- expanded
-
- name
- ruby-postcodeanywhere
- regexFolderFilter
- !.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$
- sourceDirectory
-
-
-
- fileHierarchyDrawerWidth
- 200
- metaData
-
- Gemfile
-
- caret
-
- column
- 10
- line
- 12
-
- columnSelection
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
- selectFrom
-
- column
- 7
- line
- 12
-
- selectTo
-
- column
- 14
- line
- 12
-
-
- Gemfile.lock
-
- caret
-
- column
- 0
- line
- 0
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
- README.rdoc
-
- caret
-
- column
- 0
- line
- 0
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
- Rakefile
-
- caret
-
- column
- 27
- line
- 15
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
- VERSION
-
- caret
-
- column
- 0
- line
- 0
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
- lib/ruby-postcodeanywhere.rb
-
- caret
-
- column
- 26
- line
- 33
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 19
-
- ruby-postcodeanywhere.gemspec
-
- caret
-
- column
- 18
- line
- 23
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 5
-
- spec/ruby-postcodeanywhere_spec.rb
-
- caret
-
- column
- 0
- line
- 7
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
- spec/spec_helper.rb
-
- caret
-
- column
- 0
- line
- 0
-
- firstVisibleColumn
- 0
- firstVisibleLine
- 0
-
-
- openDocuments
-
- Gemfile
- Gemfile.lock
- VERSION
- ruby-postcodeanywhere.gemspec
- README.rdoc
- Rakefile
- spec/ruby-postcodeanywhere_spec.rb
- lib/ruby-postcodeanywhere.rb
- spec/spec_helper.rb
-
- showFileHierarchyDrawer
-
- windowFrame
- {{341, 61}, {987, 817}}
-
-
diff --git a/Rakefile b/Rakefile
index 950cc3f..df25d12 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,50 +1,20 @@
-# encoding: utf-8
+# frozen_string_literal: true
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
+ warn e.message
+ warn 'Run `bundle install` to install missing gems'
exit e.status_code
end
require 'rake'
-require 'jeweler'
-
-Jeweler::Tasks.new do |gem|
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
- gem.name = "ruby-postcodeanywhere"
- gem.homepage = "http://github.com/intothefire/ruby-postcodeanywhere"
- gem.license = "MIT"
- gem.summary = %Q{Gem to provide basic access to PostcodeAnywhere services}
- gem.description = %Q{Gem to provide basic access to PostcodeAnywhere services}
- gem.email = "chris@norman.me"
- gem.authors = ["Chris Norman"]
- # dependencies defined in Gemfile
-end
-Jeweler::RubygemsDotOrgTasks.new
-
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
-RSpec::Core::RakeTask.new(:rcov) do |spec|
- spec.pattern = 'spec/**/*_spec.rb'
- spec.rcov = true
-end
-
-task :default => :spec
-
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
-
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = "ruby-postcodeanywhere #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
+task default: :spec
diff --git a/VERSION b/VERSION
index 7693c96..0ea3a94 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.3
\ No newline at end of file
+0.2.0
diff --git a/lib/postcode_anywhere/bank_account_validation.rb b/lib/postcode_anywhere/bank_account_validation.rb
index 3650a69..783d02b 100644
--- a/lib/postcode_anywhere/bank_account_validation.rb
+++ b/lib/postcode_anywhere/bank_account_validation.rb
@@ -1,32 +1,35 @@
+# frozen_string_literal: true
+
require 'json'
-#require 'active_support/inflector/methods'
+# require 'active_support/inflector/methods'
require 'active_support/core_ext/string/inflections'
module PostcodeAnywhere
class BankAccountValidation
include HTTParty
- base_uri 'https://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive/Validate/v2.00/json3.ws'
+ base_uri 'https://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive'
format :html
def initialize(key)
- self.class.default_params :Key => key
+ self.class.default_params Key: key
end
+
def validate(sort_code, account_number)
- http_response = self.class.get('', :query => {:SortCode => sort_code, :AccountNumber => account_number})
+ http_response = self.class.get('/Validate/v2.00/json3.ws', query: { SortCode: sort_code, AccountNumber: account_number })
r = unwrap_response(http_response)
-
- if r["Error"]
- raise BankAccountException, r
- else
- BankAccountResult.new(r)
- end
+
+ raise BankAccountException, r if r['Error']
+
+ BankAccountResult.new(r)
end
-
+
protected
+
def unwrap_response(http_response)
r = JSON.parse(http_response)
raise unless r.length == 1
- r = r["Items"]
+
+ r = r['Items']
raise unless r.length == 1
r[0]
@@ -34,27 +37,27 @@ def unwrap_response(http_response)
end
class BankAccountResult
- ATTRIBUTES = [:is_correct,
- :is_direct_debit_capable,
- :status_information,
- :corrected_sort_code,
- :corrected_account_number,
- :iban,
- :bank,
- :bank_bic,
- :branch,
- :branch_bic,
- :contact_address_line1,
- :contact_address_line2,
- :contact_post_town,
- :contact_postcode,
- :contact_phone,
- :contact_fax,
- :faster_payments_supported,
- :chaps_supported]
- attr_accessor *ATTRIBUTES
-
- def initialize attributes
+ ATTRIBUTES = %i[is_correct
+ is_direct_debit_capable
+ status_information
+ corrected_sort_code
+ corrected_account_number
+ iban
+ bank
+ bank_bic
+ branch
+ branch_bic
+ contact_address_line1
+ contact_address_line2
+ contact_post_town
+ contact_postcode
+ contact_phone
+ contact_fax
+ faster_payments_supported
+ chaps_supported].freeze
+ attr_accessor(*ATTRIBUTES)
+
+ def initialize(attributes)
attributes.each do |k, v|
send "#{k.underscore}=", v
end
@@ -63,30 +66,32 @@ def initialize attributes
def correct?
is_correct
end
+
def direct_debit_capable?
is_direct_debit_capable
end
+
def faster_payments_supported?
faster_payments_supported
end
+
def chaps_supported?
chaps_supported
end
end
class BankAccountException < StandardError
- ATTRIBUTES = [:error,
- :description,
- :cause,
- :resolution]
- attr_accessor *ATTRIBUTES
+ ATTRIBUTES = %i[error
+ description
+ cause
+ resolution].freeze
+ attr_accessor(*ATTRIBUTES)
def initialize(attributes)
- self.error = attributes.delete("Error").to_i
- attributes.each do |k,v|
+ self.error = attributes.delete('Error').to_i
+ attributes.each do |k, v|
send "#{k.underscore}=", v
end
end
end
end
-
diff --git a/lib/ruby-postcodeanywhere.rb b/lib/ruby-postcodeanywhere.rb
index 7542918..7e35954 100644
--- a/lib/ruby-postcodeanywhere.rb
+++ b/lib/ruby-postcodeanywhere.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'httparty'
require 'active_support/core_ext/module/attribute_accessors'
@@ -6,137 +8,123 @@ module PostcodeAnywhere
# Account codes to access the PostcodeAnywhere Service
mattr_accessor :account_code
- @@account_code = "TEST"
+ @@account_code = 'TEST'
mattr_accessor :license_code
- @@license_code = "TEST"
+ @@license_code = 'TEST'
def self.setup
yield self
end
class PostcodeSearch
- include HTTParty
-
- base_uri 'https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive'
+ include HTTParty
- ADDRESS_LOOKUP = "/Find/v1.10/xmla.ws"
- ADDRESS_FETCH = "/RetrieveById/v1.20/xmla.ws"
- RETRIEVE_BY_PARTS_URL = "/RetrieveByParts/v1.00/xmla.ws"
+ base_uri 'https://services.postcodeanywhere.co.uk/PostcodeAnywhere/Interactive'
- def lookup(postcode)
+ ADDRESS_LOOKUP = '/Find/v1.10/xmla.ws'
+ ADDRESS_FETCH = '/RetrieveById/v1.20/xmla.ws'
+ RETRIEVE_BY_PARTS_URL = '/RetrieveByParts/v1.00/xmla.ws'
- raise "Postcode is Required" if postcode.blank? || postcode.nil?
+ def lookup(postcode)
+ raise 'Postcode is Required' if postcode.blank? || postcode.nil?
- options={ "SearchTerm" => postcode.gsub(/\s/, '') }
- options.merge!(self.license_information)
+ options = { 'SearchTerm' => postcode.gsub(/\s/, '') }
+ options.merge!(license_information)
- data = PostcodeSearch.get( ADDRESS_LOOKUP, {:query => options} )
- formatted_data = []
+ data = PostcodeSearch.get(ADDRESS_LOOKUP, { query: options })
+ formatted_data = []
- return formatted_data if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
+ return formatted_data if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == 'Error'
- puts formatted_data
+ puts formatted_data
- unless data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
+ unless data.parsed_response['Table']['Columns']['Column'][0]['Name'] == 'Error'
- begin
- data.parsed_response["Table"]["Rows"]["Row"].each do |item|
- data_item = AddressListItem.new
- data_item.id = item['Id']
- data_item.street_address = item['StreetAddress']
- data_item.place = item['Place']
+ begin
+ data.parsed_response['Table']['Rows']['Row'].each do |item|
+ data_item = AddressListItem.new
+ data_item.id = item['Id']
+ data_item.street_address = item['StreetAddress']
+ data_item.place = item['Place']
- formatted_data << data_item
- end
- rescue
- item = data.parsed_response["Table"]["Rows"]["Row"]
- data_item = AddressListItem.new
- data_item.id = item['Id']
- data_item.street_address = item['StreetAddress']
- data_item.place = item['Place']
+ formatted_data << data_item
+ end
+ rescue StandardError
+ item = data.parsed_response['Table']['Rows']['Row']
+ data_item = AddressListItem.new
+ data_item.id = item['Id']
+ data_item.street_address = item['StreetAddress']
+ data_item.place = item['Place']
- formatted_data << data_item
+ formatted_data << data_item
end
- end
- formatted_data
- end
-
- def fetch_by_parts(options={})
- options.merge!(self.license_information)
-
- if options['postcode']
- options['postcode'] = options['postcode'].gsub(/\s/, '')
end
+ formatted_data
+ end
- data = PostcodeSearch.get( RETRIEVE_BY_PARTS_URL, {:query => options} )
-
- process_address(data)
- end
-
- def fetch(id)
- options={ :id => id }
- options.merge!(self.license_information)
+ def fetch_by_parts(options = {})
+ options.merge!(license_information)
- data = PostcodeSearch.get( ADDRESS_FETCH, {:query => options} )
+ options['postcode'] = options['postcode'].gsub(/\s/, '') if options['postcode']
- process_address(data)
- end
+ data = PostcodeSearch.get(RETRIEVE_BY_PARTS_URL, { query: options })
- def license_information
- {:account_code => PostcodeAnywhere.account_code, :license_code => PostcodeAnywhere.license_code}
- end
+ process_address(data)
+ end
+ def fetch(id)
+ options = { id: id }
+ options.merge!(license_information)
- private
- def process_address(data)
+ data = PostcodeSearch.get(ADDRESS_FETCH, { query: options })
- raise 'No Data Found' if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == "Error"
+ process_address(data)
+ end
- formatted_data = data.parsed_response["Table"]["Rows"]["Row"]
+ def license_information
+ { account_code: PostcodeAnywhere.account_code, license_code: PostcodeAnywhere.license_code }
+ end
- address_lookup = AddressLookup.new
+ private
- address_lookup.mailsort = formatted_data["Mailsort"]
- address_lookup.barcode = formatted_data["Barcode"]
- address_lookup.type = formatted_data["Type"]
+ def process_address(data)
+ raise 'No Data Found' if data.parsed_response['Table']['Columns']['Column'][0]['Name'] == 'Error'
- address_lookup.udprn = formatted_data["Udprn"]
- address_lookup.company = formatted_data["Company"]
- address_lookup.department = formatted_data["Department"]
- address_lookup.postcode = formatted_data["Postcode"]
- address_lookup.address_line_1 = formatted_data["Line1"]
- address_lookup.address_line_2 = formatted_data["Line2"]
- address_lookup.address_line_3 = formatted_data["Line3"]
- address_lookup.address_line_4 = formatted_data["Line4"]
- address_lookup.address_line_5 = formatted_data["Line5"]
- address_lookup.building_name = formatted_data["BuildingName"]
- address_lookup.building_number = formatted_data["BuildingNumber"]
- address_lookup.street = formatted_data["PrimaryStreet"]
- address_lookup.flat = formatted_data["SubBuilding"]
- address_lookup.district = formatted_data["DependentLocality"]
- address_lookup.post_town = formatted_data["PostTown"]
- address_lookup.county = formatted_data["County"].blank? ? formatted_data["PostTown"] : formatted_data["County"]
+ formatted_data = data.parsed_response['Table']['Rows']['Row']
+ address_lookup = AddressLookup.new
- address_lookup
- end
+ address_lookup.mailsort = formatted_data['Mailsort']
+ address_lookup.barcode = formatted_data['Barcode']
+ address_lookup.type = formatted_data['Type']
+ address_lookup.udprn = formatted_data['Udprn']
+ address_lookup.company = formatted_data['Company']
+ address_lookup.department = formatted_data['Department']
+ address_lookup.postcode = formatted_data['Postcode']
+ address_lookup.address_line_1 = formatted_data['Line1']
+ address_lookup.address_line_2 = formatted_data['Line2']
+ address_lookup.address_line_3 = formatted_data['Line3']
+ address_lookup.address_line_4 = formatted_data['Line4']
+ address_lookup.address_line_5 = formatted_data['Line5']
+ address_lookup.building_name = formatted_data['BuildingName']
+ address_lookup.building_number = formatted_data['BuildingNumber']
+ address_lookup.street = formatted_data['PrimaryStreet']
+ address_lookup.flat = formatted_data['SubBuilding']
+ address_lookup.district = formatted_data['DependentLocality']
+ address_lookup.post_town = formatted_data['PostTown']
+ address_lookup.county = formatted_data['County'].blank? ? formatted_data['PostTown'] : formatted_data['County']
+ address_lookup
+ end
end
class AddressLookup
-
- attr_accessor :building_name, :building_number, :street, :flat, :district
- attr_accessor :postcode, :address_line_1, :address_line_2, :address_line_3, :address_line_4, :address_line_5
- attr_accessor :post_town, :county, :city, :county_name, :zip4, :state, :udprn, :company, :department
- attr_accessor :mailsort, :barcode, :type
-
+ attr_accessor :building_name, :building_number, :street, :flat, :district, :postcode, :address_line_1,
+ :address_line_2, :address_line_3, :address_line_4, :address_line_5, :post_town, :county, :city, :county_name, :zip4, :state, :udprn, :company, :department, :mailsort, :barcode, :type
end
class AddressListItem
-
- attr_accessor :id, :street_address, :place
-
+ attr_accessor :id, :street_address, :place
end
end
-
diff --git a/ruby-postcodeanywhere.gemspec b/ruby-postcodeanywhere.gemspec
index 38d3a7d..2e0384d 100644
--- a/ruby-postcodeanywhere.gemspec
+++ b/ruby-postcodeanywhere.gemspec
@@ -1,64 +1,50 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
-# -*- encoding: utf-8 -*-
+# frozen_string_literal: true
+
+# stub: ruby-postcodeanywhere 0.2.0 ruby lib
Gem::Specification.new do |s|
- s.name = %q{ruby-postcodeanywhere}
- s.version = "0.1.3"
+ s.name = 'ruby-postcodeanywhere'
+ s.version = '0.2.0'
+
+ s.required_ruby_version = '>= 2.5.0'
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = [%q{Chris Norman}]
- s.date = %q{2011-08-04}
- s.description = %q{Gem to provide basic access to PostcodeAnywhere services}
- s.email = %q{chris@norman.me}
+ s.authors = ['Funding Circle']
+ s.email = ['engineering@fundingcircle.com']
+ s.summary = 'Gem to provide basic access to PostcodeAnywhere services'
+ s.description = 'Gem to provide basic access to PostcodeAnywhere services'
+ s.homepage = 'http://github.com/FundingCircle/ruby-postcodeanywhere'
+ s.licenses = ['MIT']
+
+ s.require_paths = ['lib']
s.extra_rdoc_files = [
- "LICENSE.txt",
- "README.rdoc"
+ 'LICENSE.txt',
+ 'README.rdoc'
]
s.files = [
- ".document",
- ".rspec",
- "Gemfile",
- "Gemfile.lock",
- "LICENSE.txt",
- "Postcode Anywhere.tmproj",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "lib/ruby-postcodeanywhere.rb",
- "ruby-postcodeanywhere.gemspec",
- "spec/ruby-postcodeanywhere_spec.rb",
- "spec/spec_helper.rb"
+ '.document',
+ '.github/workflows/ci.yml',
+ '.rspec',
+ '.rubocop.yml',
+ '.rubocop_todo.yml',
+ '.ruby-version',
+ 'Gemfile',
+ 'Gemfile.lock',
+ 'LICENSE.txt',
+ 'README.rdoc',
+ 'Rakefile',
+ 'VERSION',
+ 'lib/postcode_anywhere/bank_account_validation.rb',
+ 'lib/ruby-postcodeanywhere.rb',
+ 'ruby-postcodeanywhere.gemspec',
+ 'spec/lib/postcode_anywhere/bank_account_validation_spec.rb',
+ 'spec/spec_helper.rb'
]
- s.homepage = %q{http://github.com/intothefire/ruby-postcodeanywhere}
- s.licenses = [%q{MIT}]
- s.require_paths = [%q{lib}]
- s.rubygems_version = %q{1.8.5}
- s.summary = %q{Gem to provide basic access to PostcodeAnywhere services}
- if s.respond_to? :specification_version then
- s.specification_version = 3
+ s.add_dependency('activesupport', '>= 0')
+ s.add_dependency('httparty', '>= 0')
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q, [">= 0"])
- s.add_development_dependency(%q, ["~> 2.3.0"])
- s.add_development_dependency(%q, [">= 0"])
- s.add_development_dependency(%q, ["~> 1.6.2"])
- s.add_development_dependency(%q, [">= 0"])
- else
- s.add_dependency(%q, [">= 0"])
- s.add_dependency(%q, ["~> 2.3.0"])
- s.add_dependency(%q, [">= 0"])
- s.add_dependency(%q, ["~> 1.6.2"])
- s.add_dependency(%q, [">= 0"])
- end
- else
- s.add_dependency(%q, [">= 0"])
- s.add_dependency(%q, ["~> 2.3.0"])
- s.add_dependency(%q, [">= 0"])
- s.add_dependency(%q, ["~> 1.6.2"])
- s.add_dependency(%q, [">= 0"])
- end
+ s.metadata['rubygems_mfa_required'] = 'true'
end
-
diff --git a/spec/lib/postcode_anywhere/bank_account_validation_spec.rb b/spec/lib/postcode_anywhere/bank_account_validation_spec.rb
index bbb436a..e7e1175 100644
--- a/spec/lib/postcode_anywhere/bank_account_validation_spec.rb
+++ b/spec/lib/postcode_anywhere/bank_account_validation_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
WebMock.disable_net_connect!
@@ -5,90 +7,89 @@
describe PostcodeAnywhere::BankAccountValidation do
subject { PostcodeAnywhere::BankAccountValidation.new 'key' }
let :json_response do
- <<-JSON
-{
- "Items": [
- {
- "IsCorrect": false,
- "IsDirectDebitCapable": false,
- "StatusInformation": "UnknownSortCode",
- "CorrectedSortCode": "",
- "CorrectedAccountNumber": "",
- "IBAN": "",
- "Bank": "",
- "BankBIC": "",
- "Branch": "",
- "BranchBIC": "",
- "ContactAddressLine1": "",
- "ContactAddressLine2": "",
- "ContactPostTown": "",
- "ContactPostcode": "",
- "ContactPhone": "",
- "ContactFax": "",
- "FasterPaymentsSupported": false,
- "CHAPSSupported": false
- }
- ]
-}
+ <<~JSON
+ {
+ "Items": [
+ {
+ "IsCorrect": false,
+ "IsDirectDebitCapable": false,
+ "StatusInformation": "UnknownSortCode",
+ "CorrectedSortCode": "",
+ "CorrectedAccountNumber": "",
+ "IBAN": "",
+ "Bank": "",
+ "BankBIC": "",
+ "Branch": "",
+ "BranchBIC": "",
+ "ContactAddressLine1": "",
+ "ContactAddressLine2": "",
+ "ContactPostTown": "",
+ "ContactPostcode": "",
+ "ContactPhone": "",
+ "ContactFax": "",
+ "FasterPaymentsSupported": false,
+ "CHAPSSupported": false
+ }
+ ]
+ }
JSON
end
let :json_error_response do
- <<-JSON
-{
- "Items": [
- {
- "Error": "1002",
- "Description": "SortCode Invalid",
- "Cause": "SortCode Invalid",
- "Resolution": "The SortCode parameter should be 6 digits in the form 00-00-00 or 000000. It should be prefixed with leading 0s if necessary."
- }
- ]
-}
+ <<~JSON
+ {
+ "Items": [
+ {
+ "Error": "1002",
+ "Description": "SortCode Invalid",
+ "Cause": "SortCode Invalid",
+ "Resolution": "The SortCode parameter should be 6 digits in the form 00-00-00 or 000000. It should be prefixed with leading 0s if necessary."
+ }
+ ]
+ }
JSON
end
- it "sends a valid request when validating a bank account" do
- ret = make_bav_request :response => json_response
-
- ret.should_not be_correct
- ret.should_not be_direct_debit_capable
- ret.status_information.should == 'UnknownSortCode'
- ret.corrected_sort_code.should == ''
- ret.corrected_account_number.should == ''
- ret.iban.should == ''
- ret.bank.should == ''
- ret.bank_bic.should == ''
- ret.branch.should == ''
- ret.branch_bic.should == ''
- ret.contact_address_line1.should == ''
- ret.contact_address_line2.should == ''
- ret.contact_post_town.should == ''
- ret.contact_postcode.should == ''
- ret.contact_phone.should == ''
- ret.contact_fax.should == ''
- ret.faster_payments_supported.should == false
- ret.should_not be_faster_payments_supported
- ret.chaps_supported.should == false
- ret.should_not be_chaps_supported
+ it 'sends a valid request when validating a bank account' do
+ ret = make_bav_request response: json_response
+
+ expect(ret).to_not be_correct
+ expect(ret).to_not be_direct_debit_capable
+ expect(ret.status_information).to eq 'UnknownSortCode'
+ expect(ret.corrected_sort_code).to eq ''
+ expect(ret.corrected_account_number).to eq ''
+ expect(ret.iban).to eq ''
+ expect(ret.bank).to eq ''
+ expect(ret.bank_bic).to eq ''
+ expect(ret.branch).to eq ''
+ expect(ret.branch_bic).to eq ''
+ expect(ret.contact_address_line1).to eq ''
+ expect(ret.contact_address_line2).to eq ''
+ expect(ret.contact_post_town).to eq ''
+ expect(ret.contact_postcode).to eq ''
+ expect(ret.contact_phone).to eq ''
+ expect(ret.contact_fax).to eq ''
+ expect(ret.faster_payments_supported).to eq false
+ expect(ret).to_not be_faster_payments_supported
+ expect(ret.chaps_supported).to eq false
+ expect(ret).to_not be_chaps_supported
end
-
- it "handles errors" do
- begin
- make_bav_request :response => json_error_response
- fail 'should raise exception'
- rescue PostcodeAnywhere::BankAccountException => e
- e.error.should == 1002
- e.description.should == "SortCode Invalid"
- e.cause.should == "SortCode Invalid"
- e.resolution.should == "The SortCode parameter should be 6 digits in the form 00-00-00 or 000000. It should be prefixed with leading 0s if necessary."
- end
+
+ it 'handles errors' do
+ make_bav_request response: json_error_response
+ raise 'should raise exception'
+ rescue PostcodeAnywhere::BankAccountException => e
+ expect(e.error).to eq 1002
+ expect(e.description).to eq 'SortCode Invalid'
+ expect(e.cause).to eq 'SortCode Invalid'
+ expect(e.resolution).to eq 'The SortCode parameter should be 6 digits in the form 00-00-00 or 000000. It should be prefixed with leading 0s if necessary.'
end
def make_bav_request(options)
- stub_request(:get,
- 'https://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive/Validate/v2.00/json3.ws?AccountNumber=account_number&Key=key&SortCode=sort_code'
- ).to_return(:body => options[:response])
- ret = subject.validate('sort_code', 'account_number')
+ stub_request(
+ :get,
+ 'https://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive/Validate/v2.00/json3.ws?AccountNumber=account_number&Key=key&SortCode=sort_code'
+ ).to_return(body: options[:response])
+
+ subject.validate('sort_code', 'account_number')
end
end
-
diff --git a/spec/ruby-postcodeanywhere_spec.rb b/spec/ruby-postcodeanywhere_spec.rb
deleted file mode 100644
index 33f4e5c..0000000
--- a/spec/ruby-postcodeanywhere_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'spec_helper'
-
-describe PostcodeAnywhere do
- it "fails" do
- fail "hey buddy, you should probably rename this file and start specing for real"
- end
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2c54baa..6455a86 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'rubygems'
require 'bundler/setup'
require 'webmock/rspec'
@@ -6,4 +8,3 @@
RSpec.configure do |config|
end
-