loqate 0.6.0 → 0.7.0
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.
- checksums.yaml +4 -4
- data/.yardstick.yml +96 -96
- data/CHANGELOG.md +5 -0
- data/README.md +8 -40
- data/ROADMAP.md +1 -1
- data/lib/loqate/address/address.rb +37 -0
- data/lib/loqate/address/detailed_address.rb +85 -0
- data/lib/loqate/address/gateway.rb +149 -0
- data/lib/loqate/email/batch_email_validation.rb +68 -0
- data/lib/loqate/email/email_validation.rb +83 -0
- data/lib/loqate/email/gateway.rb +124 -0
- data/lib/loqate/gateway.rb +10 -10
- data/lib/loqate/phone/gateway.rb +84 -0
- data/lib/loqate/phone/phone_number_validation.rb +69 -0
- data/lib/loqate/version.rb +1 -1
- metadata +9 -9
- data/lib/loqate/address.rb +0 -35
- data/lib/loqate/address_gateway.rb +0 -147
- data/lib/loqate/batch_email_validation.rb +0 -66
- data/lib/loqate/detailed_address.rb +0 -83
- data/lib/loqate/email_gateway.rb +0 -122
- data/lib/loqate/email_validation.rb +0 -81
- data/lib/loqate/phone_gateway.rb +0 -82
- data/lib/loqate/phone_number_validation.rb +0 -67
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'loqate/client'
|
2
|
+
require 'loqate/result'
|
3
|
+
require 'loqate/mappers/error_mapper'
|
4
|
+
require 'loqate/mappers/generic_mapper'
|
5
|
+
require 'loqate/phone/phone_number_validation'
|
6
|
+
|
7
|
+
module Loqate
|
8
|
+
module Phone
|
9
|
+
# Starts a new phone number validation request.
|
10
|
+
#
|
11
|
+
class Gateway
|
12
|
+
VALIDATE_ENDPOINT = '/PhoneNumberValidation/Interactive/Validate/v2.20/json3.ws'.freeze
|
13
|
+
|
14
|
+
include Result::Mixin
|
15
|
+
|
16
|
+
# Creates a phone gateway
|
17
|
+
#
|
18
|
+
# @param [Client] client The client responsible for the HTTP interactions
|
19
|
+
#
|
20
|
+
def initialize(client)
|
21
|
+
@client = client
|
22
|
+
@mapper = Mappers::GenericMapper.new
|
23
|
+
@error_mapper = Mappers::ErrorMapper.new
|
24
|
+
end
|
25
|
+
|
26
|
+
# Validates phone numbers.
|
27
|
+
#
|
28
|
+
# @param [Hash] options The options to validate a phone number.
|
29
|
+
# @option options [String] :phone The mobile/cell phone number to verify. This must be in international format
|
30
|
+
# (+447528471411 or 447528471411) if no country code is provided or national format with a Country parameter
|
31
|
+
# provided (07528471411 and GB as the Country parameter).
|
32
|
+
# @option options [String] :country The ISO2 country code of the number you are trying to validate
|
33
|
+
# (if provided in national format).
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# phone_validation = phone_gateway.validate(phone: '447440019210', country: 'GB')
|
37
|
+
#
|
38
|
+
# @return [Result] A result wrapping a phone number validation
|
39
|
+
#
|
40
|
+
def validate(options)
|
41
|
+
response = client.get(VALIDATE_ENDPOINT, options)
|
42
|
+
|
43
|
+
response.errors? && build_error_from(response.items.first) || build_phone_validation_from(response.items.first)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Validates phone numbers.
|
47
|
+
#
|
48
|
+
# @param [Hash] options The options to validate a phone number.
|
49
|
+
# @option options [String] :phone The mobile/cell phone number to verify. This must be in international format
|
50
|
+
# (+447528471411 or 447528471411) if no country code is provided or national format with a Country parameter
|
51
|
+
# provided (07528471411 and GB as the Country parameter).
|
52
|
+
# @option options [String] :country The ISO2 country code of the number you are trying to validate
|
53
|
+
# (if provided in national format).
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# phone_validation = phone_gateway.validate(phone: '447440019210', country: 'GB')
|
57
|
+
#
|
58
|
+
# @raise [Error] If the result is not a success
|
59
|
+
#
|
60
|
+
# @return [PhoneNumberValidation> A phone number validation
|
61
|
+
#
|
62
|
+
def validate!(options)
|
63
|
+
unwrap_result_or_raise { validate(options) }
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# @api private
|
69
|
+
attr_reader :client, :mapper, :error_mapper
|
70
|
+
|
71
|
+
# @api private
|
72
|
+
def build_error_from(item)
|
73
|
+
error = error_mapper.map_one(item)
|
74
|
+
Failure(error)
|
75
|
+
end
|
76
|
+
|
77
|
+
# @api private
|
78
|
+
def build_phone_validation_from(item)
|
79
|
+
phone_number_validation = mapper.map_one(item, PhoneNumberValidation)
|
80
|
+
Success(phone_number_validation)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Loqate
|
2
|
+
module Phone
|
3
|
+
# Result of a phone number validation.
|
4
|
+
class PhoneNumberValidation < Dry::Struct::Value
|
5
|
+
IsValid = Types::Strict::String.enum('Yes', 'No', 'Unknown')
|
6
|
+
NumberType = Types::Strict::String.enum('Mobile', 'Landline', 'Voip', 'Unknown')
|
7
|
+
|
8
|
+
# The recipient phone number in international format.
|
9
|
+
#
|
10
|
+
# @return [String]
|
11
|
+
#
|
12
|
+
attribute :phone_number, Types::Strict::String
|
13
|
+
|
14
|
+
# Returns true if we managed to process the request on the network or false if the validation
|
15
|
+
# attempt was unsuccessful.
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
#
|
19
|
+
attribute :request_processed, Types::Strict::Bool
|
20
|
+
|
21
|
+
# Whether the number is valid or not (Unknown returned if validation wasn't possible).
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
#
|
25
|
+
attribute :is_valid, IsValid
|
26
|
+
|
27
|
+
# The current operator serving the supplied number.
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
#
|
31
|
+
attribute :network_code, Types::Strict::String
|
32
|
+
|
33
|
+
# The name of the current operator serving the supplied number.
|
34
|
+
#
|
35
|
+
# @return [String]
|
36
|
+
#
|
37
|
+
attribute :network_name, Types::Strict::String
|
38
|
+
|
39
|
+
# The country code of the operator.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
#
|
43
|
+
attribute :network_country, Types::Strict::String
|
44
|
+
|
45
|
+
# The domestic network format (useful for dialling from within the same country).
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
#
|
49
|
+
attribute :national_format, Types::Strict::String
|
50
|
+
|
51
|
+
# The country prefix that must be prepended to the number when dialling internationally.
|
52
|
+
#
|
53
|
+
# @return [Integer]
|
54
|
+
#
|
55
|
+
attribute :country_prefix, Types::Coercible::Integer
|
56
|
+
|
57
|
+
# The type of number that was detected in the request (Mobile, Landline, VOIP or Unknown).
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
#
|
61
|
+
attribute :number_type, NumberType
|
62
|
+
|
63
|
+
# Whether the validation was successful or not.
|
64
|
+
def valid?
|
65
|
+
is_valid == 'Yes'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/loqate/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loqate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Silva
|
@@ -344,8 +344,9 @@ files:
|
|
344
344
|
- bin/console
|
345
345
|
- bin/setup
|
346
346
|
- lib/loqate.rb
|
347
|
-
- lib/loqate/address.rb
|
348
|
-
- lib/loqate/
|
347
|
+
- lib/loqate/address/address.rb
|
348
|
+
- lib/loqate/address/detailed_address.rb
|
349
|
+
- lib/loqate/address/gateway.rb
|
349
350
|
- lib/loqate/api_result.rb
|
350
351
|
- lib/loqate/bank/account_validation.rb
|
351
352
|
- lib/loqate/bank/batch_account_validation.rb
|
@@ -353,18 +354,17 @@ files:
|
|
353
354
|
- lib/loqate/bank/card_validation.rb
|
354
355
|
- lib/loqate/bank/gateway.rb
|
355
356
|
- lib/loqate/bank/international_account_validation.rb
|
356
|
-
- lib/loqate/batch_email_validation.rb
|
357
357
|
- lib/loqate/client.rb
|
358
358
|
- lib/loqate/configuration.rb
|
359
|
-
- lib/loqate/
|
360
|
-
- lib/loqate/
|
361
|
-
- lib/loqate/
|
359
|
+
- lib/loqate/email/batch_email_validation.rb
|
360
|
+
- lib/loqate/email/email_validation.rb
|
361
|
+
- lib/loqate/email/gateway.rb
|
362
362
|
- lib/loqate/error.rb
|
363
363
|
- lib/loqate/gateway.rb
|
364
364
|
- lib/loqate/mappers/error_mapper.rb
|
365
365
|
- lib/loqate/mappers/generic_mapper.rb
|
366
|
-
- lib/loqate/
|
367
|
-
- lib/loqate/phone_number_validation.rb
|
366
|
+
- lib/loqate/phone/gateway.rb
|
367
|
+
- lib/loqate/phone/phone_number_validation.rb
|
368
368
|
- lib/loqate/result.rb
|
369
369
|
- lib/loqate/types.rb
|
370
370
|
- lib/loqate/util.rb
|
data/lib/loqate/address.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module Loqate
|
2
|
-
# A result from the address find service.
|
3
|
-
class Address < Dry::Struct::Value
|
4
|
-
# An address ID or a container ID for further results
|
5
|
-
#
|
6
|
-
# @return [String]
|
7
|
-
#
|
8
|
-
attribute :id, Types::Strict::String
|
9
|
-
|
10
|
-
# If the Type is 'Address' then the ID can be passed to the Retrieve service.
|
11
|
-
# Any other ID should be passed as the Container to a further Find request to get more results.
|
12
|
-
#
|
13
|
-
# @return [String]
|
14
|
-
#
|
15
|
-
attribute :type, Types::Strict::String
|
16
|
-
|
17
|
-
# The name of the result
|
18
|
-
#
|
19
|
-
# @return [String]
|
20
|
-
#
|
21
|
-
attribute :text, Types::Strict::String
|
22
|
-
|
23
|
-
# A list of number ranges identifying the matched characters in the Text and Description
|
24
|
-
#
|
25
|
-
# @return [String]
|
26
|
-
#
|
27
|
-
attribute :highlight, Types::Strict::String
|
28
|
-
|
29
|
-
# Descriptive information about the result
|
30
|
-
#
|
31
|
-
# @return [String]
|
32
|
-
#
|
33
|
-
attribute :description, Types::Strict::String
|
34
|
-
end
|
35
|
-
end
|
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'loqate/address'
|
2
|
-
require 'loqate/detailed_address'
|
3
|
-
require 'loqate/error'
|
4
|
-
require 'loqate/client'
|
5
|
-
require 'loqate/result'
|
6
|
-
require 'loqate/mappers/error_mapper'
|
7
|
-
require 'loqate/mappers/generic_mapper'
|
8
|
-
|
9
|
-
module Loqate
|
10
|
-
# Address Verification consists of two main API requests: a Find request is used to narrow down a possible
|
11
|
-
# list of addresses; and a Retrieve request is used to retrieve a fully formatted address.
|
12
|
-
#
|
13
|
-
# A typical address search is made up of a series of Find requests, followed by a Retrieve based on the
|
14
|
-
# user selection. Choose a service below to find out how to use each request.
|
15
|
-
#
|
16
|
-
class AddressGateway
|
17
|
-
FIND_ENDPOINT = '/Capture/Interactive/Find/v1.00/json3.ws'.freeze
|
18
|
-
RETRIEVE_ENDPOINT = '/Capture/Interactive/Retrieve/v1.00/json3.ws'.freeze
|
19
|
-
|
20
|
-
include Result::Mixin
|
21
|
-
|
22
|
-
# Creates an address gateway
|
23
|
-
#
|
24
|
-
# @param [Client] client The client responsible for the HTTP interactions
|
25
|
-
#
|
26
|
-
def initialize(client)
|
27
|
-
@client = client
|
28
|
-
@mapper = Mappers::GenericMapper.new
|
29
|
-
@error_mapper = Mappers::ErrorMapper.new
|
30
|
-
end
|
31
|
-
|
32
|
-
# Find addresses and places.
|
33
|
-
#
|
34
|
-
# @param [Hash] options The options to find an address or a list of addresses.
|
35
|
-
# @option options [String] :text The search text to find. Ideally a postcode or the start of the address.
|
36
|
-
# @option options [String] countries A comma separated list of ISO 2 or 3 character country codes to limit
|
37
|
-
# the search within.
|
38
|
-
# @option options [String] origin A starting location for the search. This can be the name or ISO 2 or 3 character
|
39
|
-
# code of a country, WGS84 coordinates (comma separated) or IP address to search from.
|
40
|
-
# @option options [String] container A container for the search. This should only be another Id previously returned
|
41
|
-
# from this service when the Type of the result was not 'Address'.
|
42
|
-
# @option options [Integer] limit The maximum number of results to return.
|
43
|
-
# @option options [String] language The preferred language for results. This should be a 2 or 4 character language
|
44
|
-
# code e.g. (en, fr, en-gb, en-us etc).
|
45
|
-
#
|
46
|
-
# @example Retrieving an address in the UK
|
47
|
-
# address = address_gateway.find(countries: 'GB', text: 'Scrubs Lane')
|
48
|
-
#
|
49
|
-
# @return [Result] A result wrapping a list of addresses
|
50
|
-
#
|
51
|
-
def find(options)
|
52
|
-
response = client.get(FIND_ENDPOINT, options)
|
53
|
-
|
54
|
-
response.errors? && build_error_from(response.items.first) || build_addresses_from(response.items)
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns the full address details based on the id.
|
58
|
-
#
|
59
|
-
# @param [Hash] options The options to retrieve the address.
|
60
|
-
# @option options [String] :id The Id from a Find method to retrieve the details for.
|
61
|
-
# @option options [String] :field_1_format Format of a custom address field.
|
62
|
-
# @option options [String] :field_2_format Format of a custom address field.
|
63
|
-
# @option options [String] :field_3_format Format of a custom address field.
|
64
|
-
# @option options [String] :field_4_format Format of a custom address field.
|
65
|
-
# @option options [String] :field_5_format Format of a custom address field.
|
66
|
-
#
|
67
|
-
# @example Retrieving the details of an address
|
68
|
-
# detailed_address = gateway.retrieve(id: 'GB|RM|ENG|6RB-NW10')
|
69
|
-
#
|
70
|
-
# @return [Result] A result wrapping a detailed address
|
71
|
-
#
|
72
|
-
def retrieve(options)
|
73
|
-
response = client.get(RETRIEVE_ENDPOINT, options)
|
74
|
-
|
75
|
-
response.errors? && build_error_from(response.items.first) || build_detailed_address_from(response.items.first)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Find addresses and places.
|
79
|
-
#
|
80
|
-
# @param [Hash] options The options to find an address or a list of addresses.
|
81
|
-
# @option options [String] :text The search text to find. Ideally a postcode or the start of the address.
|
82
|
-
# @option options [String] countries A comma separated list of ISO 2 or 3 character country codes to limit
|
83
|
-
# the search within.
|
84
|
-
# @option options [String] origin A starting location for the search. This can be the name or ISO 2 or 3 character
|
85
|
-
# code of a country, WGS84 coordinates (comma separated) or IP address to search from.
|
86
|
-
# @option options [String] container A container for the search. This should only be another Id previously returned
|
87
|
-
# from this service when the Type of the result was not 'Address'.
|
88
|
-
# @option options [Integer] limit The maximum number of results to return.
|
89
|
-
# @option options [String] language The preferred language for results. This should be a 2 or 4 character language
|
90
|
-
# code e.g. (en, fr, en-gb, en-us etc).
|
91
|
-
#
|
92
|
-
# @example Retrieving addresses in the UK
|
93
|
-
# addresses = address_gateway.find!(countries: 'GB', text: 'Scrubs Lane')
|
94
|
-
#
|
95
|
-
# @raise [Error] If the result is not a success
|
96
|
-
#
|
97
|
-
# @return [Array<Address>] A list of addresses
|
98
|
-
#
|
99
|
-
def find!(options)
|
100
|
-
unwrap_result_or_raise { find(options) }
|
101
|
-
end
|
102
|
-
|
103
|
-
# Returns the full address details based on the id.
|
104
|
-
#
|
105
|
-
# @param [Hash] options The options to retrieve the address.
|
106
|
-
# @option options [String] :id The Id from a Find method to retrieve the details for.
|
107
|
-
# @option options [String] :field_1_format Format of a custom address field.
|
108
|
-
# @option options [String] :field_2_format Format of a custom address field.
|
109
|
-
# @option options [String] :field_3_format Format of a custom address field.
|
110
|
-
# @option options [String] :field_4_format Format of a custom address field.
|
111
|
-
# @option options [String] :field_5_format Format of a custom address field.
|
112
|
-
#
|
113
|
-
# @example Retrieving the details of an address
|
114
|
-
# detailed_address = gateway.retrieve!(id: 'GB|RM|ENG|6RB-NW10')
|
115
|
-
#
|
116
|
-
# @raise [Error] If the result is not a success
|
117
|
-
#
|
118
|
-
# @return [DetailedAddress] A detailed address
|
119
|
-
#
|
120
|
-
def retrieve!(options)
|
121
|
-
unwrap_result_or_raise { retrieve(options) }
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
|
126
|
-
# @api private
|
127
|
-
attr_reader :client, :mapper, :error_mapper
|
128
|
-
|
129
|
-
# @api private
|
130
|
-
def build_error_from(item)
|
131
|
-
error = error_mapper.map_one(item)
|
132
|
-
Failure(error)
|
133
|
-
end
|
134
|
-
|
135
|
-
# @api private
|
136
|
-
def build_addresses_from(items)
|
137
|
-
address = mapper.map(items, Address)
|
138
|
-
Success(address)
|
139
|
-
end
|
140
|
-
|
141
|
-
# @api private
|
142
|
-
def build_detailed_address_from(item)
|
143
|
-
detailed_address = mapper.map_one(item, DetailedAddress)
|
144
|
-
Success(detailed_address)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module Loqate
|
2
|
-
# Result of a batch email address validation.
|
3
|
-
class BatchEmailValidation < Dry::Struct::Value
|
4
|
-
Status = Types::Strict::String.enum('Valid', 'Invalid', 'Unknown', 'Accept_All')
|
5
|
-
|
6
|
-
# Valid - The email address is valid
|
7
|
-
# Invalid - The email address is invalid and shouldn't be accepted
|
8
|
-
# Unknown - Unable to complete the verification process (normally due to SMTP timeout)
|
9
|
-
# Accept_All - The mail server is set to accept all verification requests so full verification isn't possible
|
10
|
-
#
|
11
|
-
# @return ['Valid', 'Invalid', 'Unknown', 'Accept_All']
|
12
|
-
#
|
13
|
-
attribute :status, Status
|
14
|
-
|
15
|
-
# The email address that verification was attempted on.
|
16
|
-
#
|
17
|
-
# @return [String]
|
18
|
-
#
|
19
|
-
attribute :email_address, Types::Strict::String
|
20
|
-
|
21
|
-
# The account portion of the email address provided.
|
22
|
-
#
|
23
|
-
# @return [String
|
24
|
-
#
|
25
|
-
attribute :account, Types::Strict::String
|
26
|
-
|
27
|
-
# The domain portion of the email address provided.
|
28
|
-
#
|
29
|
-
# @return [String]
|
30
|
-
#
|
31
|
-
attribute :domain, Types::Strict::String
|
32
|
-
|
33
|
-
# Whether the email address provided is a disposable mailbox (some companies create temporary mailboxes
|
34
|
-
# which shouldn't be used for marketing communications).
|
35
|
-
#
|
36
|
-
# @return [Boolean]
|
37
|
-
#
|
38
|
-
attribute :is_disposible, Types::Strict::Bool
|
39
|
-
|
40
|
-
# Whether the email address provided is a system mailbox (e.g. sales@, support@, accounts@ etc).
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
#
|
44
|
-
attribute :is_system_mailbox, Types::Strict::Bool
|
45
|
-
|
46
|
-
# Whether the email was fully validated (including the account portion).
|
47
|
-
def valid?
|
48
|
-
status == 'Valid'
|
49
|
-
end
|
50
|
-
|
51
|
-
# Whether the email is invalid and shouldn't be accepted.
|
52
|
-
def invalid?
|
53
|
-
status == 'Invalid'
|
54
|
-
end
|
55
|
-
|
56
|
-
# Whether the email wasn't verified (normally due to SMTP timeout)
|
57
|
-
def unknown?
|
58
|
-
status == 'Unknown'
|
59
|
-
end
|
60
|
-
|
61
|
-
# Whether the email could be verified
|
62
|
-
def unverified?
|
63
|
-
status == 'Accept_All'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|