postcode-anywhere 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +247 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +72 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +319 -0
  9. data/Rakefile +2 -0
  10. data/config/pre_commit.yml +7 -0
  11. data/lib/postcode_anywhere.rb +10 -0
  12. data/lib/postcode_anywhere/bank_account_validation/bank_branch.rb +45 -0
  13. data/lib/postcode_anywhere/bank_account_validation/client.rb +13 -0
  14. data/lib/postcode_anywhere/bank_account_validation/interactive.rb +39 -0
  15. data/lib/postcode_anywhere/bank_account_validation/validation_result.rb +80 -0
  16. data/lib/postcode_anywhere/capture_plus/client.rb +13 -0
  17. data/lib/postcode_anywhere/capture_plus/interactive.rb +84 -0
  18. data/lib/postcode_anywhere/capture_plus/query_type.rb +8 -0
  19. data/lib/postcode_anywhere/capture_plus/retrieve_result.rb +45 -0
  20. data/lib/postcode_anywhere/capture_plus/search_result.rb +39 -0
  21. data/lib/postcode_anywhere/cleanse_plus/cleansed_address.rb +98 -0
  22. data/lib/postcode_anywhere/cleanse_plus/client.rb +13 -0
  23. data/lib/postcode_anywhere/cleanse_plus/interactive.rb +24 -0
  24. data/lib/postcode_anywhere/client.rb +86 -0
  25. data/lib/postcode_anywhere/configuration.rb +47 -0
  26. data/lib/postcode_anywhere/email_validation/client.rb +13 -0
  27. data/lib/postcode_anywhere/email_validation/interactive.rb +25 -0
  28. data/lib/postcode_anywhere/email_validation/validation_result.rb +24 -0
  29. data/lib/postcode_anywhere/error.rb +118 -0
  30. data/lib/postcode_anywhere/model_base.rb +72 -0
  31. data/lib/postcode_anywhere/request.rb +33 -0
  32. data/lib/postcode_anywhere/response/parse_json.rb +100 -0
  33. data/lib/postcode_anywhere/response/raise_error.rb +19 -0
  34. data/lib/postcode_anywhere/utils.rb +15 -0
  35. data/lib/postcode_anywhere/version.rb +3 -0
  36. data/postcode_anywhere.gemspec +31 -0
  37. data/spec/postcode_anywhere/bank_account_validation/interactive_spec.rb +82 -0
  38. data/spec/postcode_anywhere/capture_plus/interactive_spec.rb +240 -0
  39. data/spec/postcode_anywhere/cleanse_plus/interactive_spec.rb +65 -0
  40. data/spec/postcode_anywhere/client_spec.rb +124 -0
  41. data/spec/postcode_anywhere/configuration_spec.rb +62 -0
  42. data/spec/postcode_anywhere/email_validation/interactive_spec.rb +30 -0
  43. data/spec/postcode_anywhere/error_spec.rb +70 -0
  44. data/spec/postcode_anywhere/fixtures/bank_account_retrieve_by_sort.json +1 -0
  45. data/spec/postcode_anywhere/fixtures/bank_account_validate_account.json +1 -0
  46. data/spec/postcode_anywhere/fixtures/capture_plus_retrieve.json +1 -0
  47. data/spec/postcode_anywhere/fixtures/capture_plus_search.json +1 -0
  48. data/spec/postcode_anywhere/fixtures/cleanse_address_multi.json +1 -0
  49. data/spec/postcode_anywhere/fixtures/cleanse_address_single.json +1 -0
  50. data/spec/postcode_anywhere/fixtures/email_validation_validate_email.json +1 -0
  51. data/spec/postcode_anywhere/model_base_spec.rb +10 -0
  52. data/spec/spec_helper.rb +38 -0
  53. metadata +281 -0
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ ---
2
+ :checks_remove: []
3
+ :checks_add:
4
+ - :rubocop
5
+ - :white_space
6
+ - :merge_conflict
7
+ - :yaml
@@ -0,0 +1,10 @@
1
+ require 'postcode_anywhere/configuration'
2
+ require 'postcode_anywhere/version'
3
+ require 'postcode_anywhere/capture_plus/client'
4
+ require 'postcode_anywhere/cleanse_plus/client'
5
+ require 'postcode_anywhere/bank_account_validation/client'
6
+ require 'postcode_anywhere/email_validation/client'
7
+
8
+ module PostcodeAnywhere
9
+ extend Configuration
10
+ end
@@ -0,0 +1,45 @@
1
+ require 'postcode_anywhere/model_base'
2
+
3
+ module PostcodeAnywhere
4
+ module BankAccountValidation
5
+ class BankBranch < PostcodeAnywhere::ModelBase
6
+ # The name of the banking institution.
7
+ attr_reader :bank
8
+
9
+ # The banking institution's BIC, also know as the SWIFT BIC.
10
+ attr_reader :bank_bic
11
+
12
+ # The name of the account holding branch.
13
+ attr_reader :branch
14
+
15
+ # The branch's BIC.
16
+ attr_reader :branch_bic
17
+
18
+ # Line 1 of the branch's contact address.
19
+ # NB: This is the address to be used for BACs enquiries and may be a
20
+ # contact centre rather than the branch's address.
21
+ attr_reader :contact_address_line1
22
+
23
+ # Line 2 of the branch's contact address.
24
+ attr_reader :contact_address_line2
25
+
26
+ # The branch's contact post town.
27
+ attr_reader :contact_post_town
28
+
29
+ # The branch's contact postcode.
30
+ attr_reader :contact_postcode
31
+
32
+ # The branch's contact phone number.
33
+ attr_reader :contact_phone
34
+
35
+ # The branch's contact fax number.
36
+ attr_reader :contact_fax
37
+
38
+ # Indicates that the account supports the faster payments service.
39
+ attr_reader :faster_payments_supported
40
+
41
+ # Indicates that the account supports the CHAPS service.
42
+ attr_reader :chaps_supported
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ require 'postcode_anywhere/client'
2
+ require 'postcode_anywhere/bank_account_validation/interactive'
3
+
4
+ module PostcodeAnywhere
5
+ module BankAccountValidation
6
+ class Client < ::PostcodeAnywhere::Client
7
+ include PostcodeAnywhere::BankAccountValidation::Interactive
8
+ def initialize(options = {})
9
+ super(options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require 'postcode_anywhere/utils'
2
+ require 'postcode_anywhere/bank_account_validation/bank_branch'
3
+ require 'postcode_anywhere/bank_account_validation/validation_result'
4
+
5
+ module PostcodeAnywhere
6
+ module BankAccountValidation
7
+ module Interactive
8
+ include ::PostcodeAnywhere::Utils
9
+
10
+ API_VERSION = '1.00'
11
+
12
+ RETRIEVE_BY_SORTCODE_ENDPOINT =
13
+ "BankAccountValidation/Interactive/RetrieveBySortcode/v#{API_VERSION}/json.ws"
14
+
15
+ VALIDATE_ACCOUNT_ENDPOINT =
16
+ "BankAccountValidation/Interactive/Validate/v#{API_VERSION}/json.ws"
17
+
18
+ def retrieve_by_sortcode(sort_code, options = {})
19
+ options.merge!('SortCode' => sort_code)
20
+ perform_with_object(
21
+ :get,
22
+ RETRIEVE_BY_SORTCODE_ENDPOINT,
23
+ options,
24
+ PostcodeAnywhere::BankAccountValidation::BankBranch
25
+ )
26
+ end
27
+
28
+ def validate_account(account_number, sort_code, options = {})
29
+ options.merge!('SortCode' => sort_code, 'AccountNumber' => account_number)
30
+ perform_with_object(
31
+ :get,
32
+ VALIDATE_ACCOUNT_ENDPOINT,
33
+ options,
34
+ PostcodeAnywhere::BankAccountValidation::ValidationResult
35
+ )
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,80 @@
1
+ require 'postcode_anywhere/model_base'
2
+
3
+ module PostcodeAnywhere
4
+ module BankAccountValidation
5
+ class ValidationResult < PostcodeAnywhere::ModelBase
6
+ # Indicates whether the account number a sortcode are valid.
7
+ # Example: false
8
+ attr_reader :is_correct
9
+
10
+ # Indicates whether the account can accept direct debits.
11
+ # Certain accounts (e.g. savings) will not accept direct debits.
12
+ # Example: false
13
+ attr_reader :is_direct_debit_capable
14
+
15
+ # More detail about the outcome of the validation process.
16
+ # Describes reasons validation failed or changes made to pass validation.
17
+ # DetailsChanged indicates that the account and sortcode should be changed for
18
+ # BACs submission (check CorrectedAccountNumber and CorrectedSortCode).
19
+ # CautiousOK is set where the sortcode exists but no validation rules are
20
+ # set for the bank (very rare).
21
+ #
22
+ # Values:
23
+ # - None
24
+ # - UnknownSortCode
25
+ # - InvalidAccountNumber
26
+ # - OK
27
+ # - CautiousOK
28
+ # - DetailsChanged
29
+ attr_reader :status_information
30
+
31
+ # The correct version of the SortCode. This will be 6 digits long with no hyphens.
32
+ # It may differ from the original sortcode.
33
+ attr_reader :corrected_sort_code
34
+
35
+ # The correct version of the AccountNumber.
36
+ # This will be 8 digits long and in the form expected for BACs submission.
37
+ attr_reader :corrected_account_number
38
+
39
+ # The correctly formatted IBAN for the account.
40
+ attr_reader :iban
41
+
42
+ # The name of the banking institution.
43
+ attr_reader :bank
44
+
45
+ # The banking institution's BIC, also know as the SWIFT BIC.
46
+ attr_reader :bank_bic
47
+
48
+ # The name of the account holding branch.
49
+ attr_reader :branch
50
+
51
+ # The branch's BIC.
52
+ attr_reader :branch_bic
53
+
54
+ # Line 1 of the branch's contact address. NB: This is the address to be used for BACs
55
+ # enquiries and may be a contact centre rather than the branch's address.
56
+ attr_reader :contact_address_line1
57
+
58
+ # Line 2 of the branch's contact address.
59
+ attr_reader :contact_address_line2
60
+
61
+ # The branch's contact post town.
62
+ attr_reader :contact_post_town
63
+
64
+ # The branch's contact postcode.
65
+ attr_reader :contact_postcode
66
+
67
+ # The branch's contact phone number.
68
+ attr_reader :contact_phone
69
+
70
+ # The branch's contact fax number.
71
+ attr_reader :contact_fax
72
+
73
+ # Indicates that the account supports the faster payments service.
74
+ attr_reader :faster_payments_supported
75
+
76
+ # Indicates that the account supports the CHAPS service.
77
+ attr_reader :chaps_supported
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,13 @@
1
+ require 'postcode_anywhere/client'
2
+ require 'postcode_anywhere/capture_plus/interactive'
3
+
4
+ module PostcodeAnywhere
5
+ module CapturePlus
6
+ class Client < ::PostcodeAnywhere::Client
7
+ include PostcodeAnywhere::CapturePlus::Interactive
8
+ def initialize(options = {})
9
+ super(options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,84 @@
1
+ require 'postcode_anywhere/utils'
2
+ require 'postcode_anywhere/capture_plus/search_result'
3
+ require 'postcode_anywhere/capture_plus/retrieve_result'
4
+ require 'postcode_anywhere/capture_plus/query_type'
5
+
6
+ module PostcodeAnywhere
7
+ module CapturePlus
8
+ module Interactive
9
+ include ::PostcodeAnywhere::Utils
10
+
11
+ API_VERSION = '2.00'
12
+
13
+ FIND_ADDRESSES_ENDPOINT = "CapturePlus/Interactive/Find/v#{API_VERSION}/json.ws"
14
+
15
+ RETRIEVE_ADDRESS_ENDPOINT = "CapturePlus/Interactive/Retrieve/v#{API_VERSION}/json.ws"
16
+
17
+ def query(search_term, options = {})
18
+ options.merge!(
19
+ 'SearchTerm' => search_term
20
+ )
21
+ options['LastId'] = ParentIdExtractor.new(options.delete(:parent_query)).extract
22
+ options['SearchFor'] = options.delete(:search_for) || EVERYTHING
23
+ options['Country'] = options.delete(:country) || 'GBR'
24
+ options['LanguagePreference'] = options.delete(:language) || 'EN'
25
+ perform_with_objects(
26
+ :get,
27
+ FIND_ADDRESSES_ENDPOINT,
28
+ options,
29
+ PostcodeAnywhere::CapturePlus::SearchResult
30
+ )
31
+ end
32
+
33
+ def sub_query(search_term, parent_query, options = {})
34
+ options.merge!(parent_query: parent_query)
35
+ query(search_term, options)
36
+ end
37
+
38
+ def query_places(search_term, options = {})
39
+ options.merge!(search_for: PLACE)
40
+ query search_term, options
41
+ end
42
+
43
+ def query_companies(search_term, options = {})
44
+ options.merge!(search_for: COMPANY)
45
+ query search_term, options
46
+ end
47
+
48
+ def query_postcodes(search_term, options = {})
49
+ options.merge!(search_for: POSTCODE)
50
+ query search_term, options
51
+ end
52
+
53
+ def retrieve(search_result)
54
+ options = {}
55
+ options.merge!(
56
+ 'Id' => ParentIdExtractor.new(search_result).extract
57
+ )
58
+ perform_with_object(
59
+ :get,
60
+ RETRIEVE_ADDRESS_ENDPOINT,
61
+ options,
62
+ PostcodeAnywhere::CapturePlus::RetrieveResult
63
+ )
64
+ end
65
+
66
+ class ParentIdExtractor
67
+ attr_accessor :parent_query
68
+
69
+ def initialize(parent)
70
+ @parent_query = parent
71
+ end
72
+
73
+ def extract
74
+ if @parent_query &&
75
+ @parent_query.class == PostcodeAnywhere::CapturePlus::SearchResult
76
+ return @parent_query.id
77
+ else
78
+ return @parent_query
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,8 @@
1
+ module PostcodeAnywhere
2
+ module CapturePlus
3
+ EVERYTHING = 'Everything'
4
+ POSTCODE = 'PostalCodes'
5
+ COMPANY = 'Companies'
6
+ PLACE = 'Places'
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'postcode_anywhere/model_base'
2
+
3
+ module PostcodeAnywhere
4
+ module CapturePlus
5
+ class RetrieveResult < PostcodeAnywhere::ModelBase
6
+ attr_reader :id
7
+ attr_reader :domestic_id
8
+ attr_reader :language
9
+ attr_reader :language_alternatives
10
+ attr_reader :department
11
+ attr_reader :company
12
+ attr_reader :sub_building
13
+ attr_reader :building_number
14
+ attr_reader :building_name
15
+ attr_reader :secondary_street
16
+ attr_reader :street
17
+ attr_reader :block
18
+ attr_reader :neighbourhood
19
+ attr_reader :district
20
+ attr_reader :city
21
+ attr_reader :line1
22
+ attr_reader :line2
23
+ attr_reader :line3
24
+ attr_reader :line4
25
+ attr_reader :line5
26
+ attr_reader :admin_area_name
27
+ attr_reader :admin_area_code
28
+ attr_reader :province
29
+ attr_reader :province_name
30
+ attr_reader :province_code
31
+ attr_reader :postal_code
32
+ attr_reader :country_name
33
+ attr_reader :country_iso2
34
+ attr_reader :country_iso3
35
+ attr_reader :country_iso_number
36
+ attr_reader :sorting_number1
37
+ attr_reader :sorting_number2
38
+ attr_reader :barcode
39
+ attr_reader :po_box_number
40
+ attr_reader :label
41
+ attr_reader :type
42
+ attr_reader :data_level
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,39 @@
1
+ require 'postcode_anywhere/model_base'
2
+
3
+ module PostcodeAnywhere
4
+ module CapturePlus
5
+ class SearchResult < PostcodeAnywhere::ModelBase
6
+ # The Id to be used as the LastId with the Find method.
7
+ # Example: GBR|ST|27299|3739|6|0|0|
8
+ attr_reader :id
9
+
10
+ # The found item.
11
+ # Example: High Street, London
12
+ attr_reader :text
13
+
14
+ # A list of number ranges identifying the characters to highlight
15
+ # in the Text response (zero-based start position and end).
16
+ # Example: 0-2,6-4
17
+ attr_reader :highlight
18
+
19
+ # A zero-based position in the Text response indicating the suggested
20
+ # position of the cursor if this item is selected.
21
+ # A -1 response indicates no suggestion is available.
22
+ # 0
23
+ # Example: true
24
+ attr_reader :cursor
25
+
26
+ # Descriptive information about the found item, typically if it's a container.
27
+ # Example: 102 Streets
28
+ attr_reader :description
29
+
30
+ # The next step of the search process.
31
+ # Values:
32
+ # - Find
33
+ # - Retrieve
34
+ # - None
35
+ # Example: Retrieve
36
+ attr_reader :next
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,98 @@
1
+ require 'postcode_anywhere/model_base'
2
+
3
+ module PostcodeAnywhere
4
+ module CleansePlus
5
+ class CleansedAddress < PostcodeAnywhere::ModelBase
6
+ # The Royal Mail UDPRN (Unique Delivery Point Reference Number) for the address.
7
+ # Example: 26742632
8
+ attr_reader :udprn
9
+
10
+ # The name of the company.
11
+ # Example: Postcode Anywhere (Europe) Ltd
12
+ attr_reader :company
13
+
14
+ # Department name (rarely used).
15
+ attr_reader :department
16
+
17
+ # Line 1 of the address.
18
+ # Example: Enigma House
19
+ attr_reader :line1
20
+
21
+ # Line 2 of the address.
22
+ # Example: Elgar Business Centre
23
+ attr_reader :line2
24
+
25
+ # Line 3 of the address (rarely used).
26
+ # Example: Moseley Road
27
+ attr_reader :line3
28
+
29
+ # Line 4 of the address (rarely used).
30
+ # Example: Hallow
31
+ attr_reader :line4
32
+
33
+ # Line 5 of the address (rarely used).
34
+ attr_reader :line5
35
+
36
+ # The post town for the address.
37
+ # Example: Worcester
38
+ attr_reader :post_town
39
+
40
+ # The postal county for the address.
41
+ # Example: Worcestershire
42
+ attr_reader :county
43
+
44
+ # The postcode for the address.
45
+ # Example: WR2 6NJ
46
+ attr_reader :postcode
47
+
48
+ # The mailsort code for the address.
49
+ # Example: 70122
50
+ attr_reader :mailsort
51
+
52
+ # The barcode for the address.
53
+ # Example: (WR26NJ3UT)
54
+ attr_reader :barcode
55
+
56
+ # The type of address.
57
+ # Example: SmallBusiness
58
+ # Values:
59
+ # - Residential
60
+ # - SmallBusiness
61
+ # - LargeBusiness
62
+ # - Unknown
63
+ attr_reader :type
64
+
65
+ # The 2 character delivery point suffix.
66
+ # Example: 3U
67
+ attr_reader :delivery_point_suffix
68
+
69
+ # The name of the sub building (flat / unit etc).
70
+ # Example: Enigma House
71
+ attr_reader :sub_building
72
+
73
+ # The building name if present.
74
+ # Elgar Business Centre
75
+ attr_reader :building_name
76
+
77
+ # The number (or number range) of the building.
78
+ attr_reader :building_number
79
+
80
+ # The primary thoroughfare name.
81
+ # Example: Moseley Road
82
+ attr_reader :primary_street
83
+
84
+ # The secondary thoroughfare name. Usually a small street off the primary.
85
+ attr_reader :secondary_street
86
+
87
+ # The least significant locality (rarely used), possibly a hamlet.
88
+ attr_reader :double_dependent_locality
89
+
90
+ # Less significant locality name, possibly a village.
91
+ # Example: Hallow
92
+ attr_reader :dependent_locality
93
+
94
+ # The number of the PO Box if present (may contain non numeric items).
95
+ attr_reader :po_box
96
+ end
97
+ end
98
+ end