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
@@ -1,83 +0,0 @@
|
|
1
|
-
module Loqate
|
2
|
-
# A result from the address retrieve service.
|
3
|
-
class DetailedAddress
|
4
|
-
# For the first version, this will be a flat structure, exactly as it is defined in Loqate's API.
|
5
|
-
# But this many attributes is too much for a single object to hold.
|
6
|
-
#
|
7
|
-
# @api private
|
8
|
-
#
|
9
|
-
ATTRIBUTES = %i[
|
10
|
-
admin_area_code
|
11
|
-
admin_area_name
|
12
|
-
barcode
|
13
|
-
block
|
14
|
-
building_name
|
15
|
-
building_number
|
16
|
-
city
|
17
|
-
company
|
18
|
-
country_iso2
|
19
|
-
country_iso3
|
20
|
-
country_iso_number
|
21
|
-
country_name
|
22
|
-
data_level
|
23
|
-
department
|
24
|
-
district
|
25
|
-
domestic_id
|
26
|
-
field1
|
27
|
-
field2
|
28
|
-
field3
|
29
|
-
field4
|
30
|
-
field5
|
31
|
-
field6
|
32
|
-
field7
|
33
|
-
field8
|
34
|
-
field9
|
35
|
-
field10
|
36
|
-
field11
|
37
|
-
field12
|
38
|
-
field13
|
39
|
-
field14
|
40
|
-
field15
|
41
|
-
field16
|
42
|
-
field17
|
43
|
-
field18
|
44
|
-
field19
|
45
|
-
field20
|
46
|
-
id
|
47
|
-
label
|
48
|
-
language
|
49
|
-
language_alternatives
|
50
|
-
line1
|
51
|
-
line2
|
52
|
-
line3
|
53
|
-
line4
|
54
|
-
line5
|
55
|
-
neighbourhood
|
56
|
-
po_box_number
|
57
|
-
postal_code
|
58
|
-
province
|
59
|
-
province_code
|
60
|
-
province_name
|
61
|
-
secondary_street
|
62
|
-
sorting_number1
|
63
|
-
sorting_number2
|
64
|
-
street
|
65
|
-
sub_building
|
66
|
-
type
|
67
|
-
].freeze
|
68
|
-
|
69
|
-
ATTRIBUTES.each do |attribute|
|
70
|
-
attr_reader attribute
|
71
|
-
end
|
72
|
-
|
73
|
-
def initialize(options = {})
|
74
|
-
options.each_pair do |key, value|
|
75
|
-
instance_variable_set("@#{key}", value) if ATTRIBUTES.include?(key)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def ==(other)
|
80
|
-
other.is_a?(DetailedAddress) && id == other.id
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
data/lib/loqate/email_gateway.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'loqate/client'
|
2
|
-
require 'loqate/result'
|
3
|
-
require 'loqate/email_validation'
|
4
|
-
require 'loqate/batch_email_validation'
|
5
|
-
require 'loqate/mappers/error_mapper'
|
6
|
-
require 'loqate/mappers/generic_mapper'
|
7
|
-
|
8
|
-
module Loqate
|
9
|
-
# Validates the existence of email addresses.
|
10
|
-
#
|
11
|
-
class EmailGateway
|
12
|
-
BATCH_VALIDATE_ENDPOINT = '/EmailValidation/Batch/Validate/v1.20/json3.ws'.freeze
|
13
|
-
VALIDATE_ENDPOINT = '/EmailValidation/Interactive/Validate/v2.00/json3.ws'.freeze
|
14
|
-
|
15
|
-
include Result::Mixin
|
16
|
-
|
17
|
-
# Creates an email gateway.
|
18
|
-
#
|
19
|
-
# @param [Client] client The client responsible for the HTTP interactions
|
20
|
-
#
|
21
|
-
def initialize(client)
|
22
|
-
@client = client
|
23
|
-
@mapper = Mappers::GenericMapper.new
|
24
|
-
@error_mapper = Mappers::ErrorMapper.new
|
25
|
-
end
|
26
|
-
|
27
|
-
# Verifies the existence of an email address.
|
28
|
-
#
|
29
|
-
# @param [Hash] options The options to validate an email address.
|
30
|
-
# @option options [String] :email The email address to verify.
|
31
|
-
# @option options [Integer] :timeout The time (in milliseconds) you want to give for the validation attempt to be
|
32
|
-
# executed within. Value must be between 1 and 15000 (values outside of these ranges will fallback to the
|
33
|
-
# default of 15000).
|
34
|
-
#
|
35
|
-
# @example
|
36
|
-
# email_validation = email_gateway.validate(email: 'spam@example.com')
|
37
|
-
#
|
38
|
-
# @return [Result] A result wrapping an email address validation
|
39
|
-
#
|
40
|
-
def validate(options)
|
41
|
-
response = client.get(VALIDATE_ENDPOINT, options)
|
42
|
-
|
43
|
-
response.errors? && build_error_from(response.items.first) || build_email_validation_from(response.items.first)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Verifies the existence of an email address.
|
47
|
-
#
|
48
|
-
# @param [Hash] options The options to validate an email address.
|
49
|
-
# @option options [String] :email The email address to verify.
|
50
|
-
# @option options [Integer] :timeout The time (in milliseconds) you want to give for the validation attempt to be
|
51
|
-
# executed within. Value must be between 1 and 15000 (values outside of these ranges will fallback to the
|
52
|
-
# default of 15000).
|
53
|
-
#
|
54
|
-
# @example
|
55
|
-
# email_validation = email_gateway.validate!(email: 'spam@example.com')
|
56
|
-
#
|
57
|
-
# @raise [Error] If the result is not a success
|
58
|
-
#
|
59
|
-
# @return [EmailValidation> An email address validation
|
60
|
-
#
|
61
|
-
def validate!(options)
|
62
|
-
unwrap_result_or_raise { validate(options) }
|
63
|
-
end
|
64
|
-
|
65
|
-
# Verifies up to 100 emails per batch.
|
66
|
-
#
|
67
|
-
# @param [Hash] options The options to validate an email address.
|
68
|
-
# @option options [Array<String>] :emails The email addresses to verify. Maximum 100 records.
|
69
|
-
#
|
70
|
-
# @example
|
71
|
-
# result = email_gateway.batch_validate(emails: %w[spam@example.com example@example.com])
|
72
|
-
# result.value # => [#<Loqate::BatchEmailValidation status="Invalid" ...]
|
73
|
-
#
|
74
|
-
# @return [Result] A result wrapping a list of email address validations
|
75
|
-
#
|
76
|
-
def batch_validate(options)
|
77
|
-
options[:emails] = options[:emails].join(',') if options[:emails]
|
78
|
-
response = client.get(BATCH_VALIDATE_ENDPOINT, options)
|
79
|
-
|
80
|
-
response.errors? && build_error_from(response.items.first) || build_email_validations_from(response.items)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Verifies up to 100 emails per batch.
|
84
|
-
#
|
85
|
-
# @param [Hash] options The options to validate an email address.
|
86
|
-
# @option options [Array<String>] :emails The email addresses to verify. Maximum 100 records.
|
87
|
-
#
|
88
|
-
# @example
|
89
|
-
# email_validations = email_gateway.batch_validate!(emails: %w[spam@example.com example@example.com])
|
90
|
-
#
|
91
|
-
# @raise [Error] If the result is not a success
|
92
|
-
#
|
93
|
-
# @return [Array<BatchEmailValidation>] A list of email address validations
|
94
|
-
#
|
95
|
-
def batch_validate!(options)
|
96
|
-
unwrap_result_or_raise { batch_validate(options) }
|
97
|
-
end
|
98
|
-
|
99
|
-
private
|
100
|
-
|
101
|
-
# @api private
|
102
|
-
attr_reader :client, :mapper, :error_mapper
|
103
|
-
|
104
|
-
# @api private
|
105
|
-
def build_error_from(item)
|
106
|
-
error = error_mapper.map_one(item)
|
107
|
-
Failure(error)
|
108
|
-
end
|
109
|
-
|
110
|
-
# @api private
|
111
|
-
def build_email_validation_from(item)
|
112
|
-
email_validation = mapper.map_one(item, EmailValidation)
|
113
|
-
Success(email_validation)
|
114
|
-
end
|
115
|
-
|
116
|
-
# @api private
|
117
|
-
def build_email_validations_from(item)
|
118
|
-
email_validation = mapper.map(item, BatchEmailValidation)
|
119
|
-
Success(email_validation)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
module Loqate
|
2
|
-
# Result of a email address validation.
|
3
|
-
class EmailValidation < Dry::Struct::Value
|
4
|
-
ResponseCode = Types::Strict::String.enum('Valid', 'Valid_CatchAll', 'Invalid', 'Timeout')
|
5
|
-
|
6
|
-
# Valid - The email address has been fully validated (including the account portion)
|
7
|
-
# Valid_CatchAll - The domain has been validated but the account could not be validated
|
8
|
-
# Invalid - The email address is invalid and shouldn't be accepted
|
9
|
-
# Timeout - The validation could not be completed within the timeout specified (try increasing the timeout value)
|
10
|
-
#
|
11
|
-
# @return ['Valid', 'Valid_CatchAll', 'Invalid', 'Timeout']
|
12
|
-
#
|
13
|
-
attribute :response_code, ResponseCode
|
14
|
-
|
15
|
-
# A textual description of the ResponseCode returned
|
16
|
-
#
|
17
|
-
# @return [String]
|
18
|
-
#
|
19
|
-
attribute :response_message, Types::Strict::String
|
20
|
-
|
21
|
-
# The email address that verification was attempted on.
|
22
|
-
#
|
23
|
-
# @return [String]
|
24
|
-
#
|
25
|
-
attribute :email_address, Types::Strict::String
|
26
|
-
|
27
|
-
# The account portion of the email address provided.
|
28
|
-
#
|
29
|
-
# @return [String
|
30
|
-
#
|
31
|
-
attribute :user_account, Types::Strict::String
|
32
|
-
|
33
|
-
# The domain portion of the email address provided.
|
34
|
-
#
|
35
|
-
# @return [String]
|
36
|
-
#
|
37
|
-
attribute :domain, Types::Strict::String
|
38
|
-
|
39
|
-
# Whether the email address provided is a disposable mailbox (some companies create temporary mailboxes
|
40
|
-
# which shouldn't be used for marketing communications).
|
41
|
-
#
|
42
|
-
# @return [Boolean]
|
43
|
-
#
|
44
|
-
attribute :is_disposable_or_temporary, Types::Strict::Bool
|
45
|
-
|
46
|
-
# True if we recognise the email address against known lists of complainers and/or the email address has been
|
47
|
-
# used to defraud.
|
48
|
-
#
|
49
|
-
# @return [Boolean]
|
50
|
-
#
|
51
|
-
attribute :is_complainer_or_fraud_risk, Types::Strict::Bool
|
52
|
-
|
53
|
-
# The duration (in seconds) that the email validation took (maximum timeout enforced at 15 seconds).
|
54
|
-
# We recommend a high timeout (at least 5 seconds) value as it will minimise the number of "Timeout"
|
55
|
-
# responses returned.
|
56
|
-
#
|
57
|
-
# @return [Float]
|
58
|
-
#
|
59
|
-
attribute :duration, Types::Strict::Float
|
60
|
-
|
61
|
-
# Whether the email was fully validated (including the account portion).
|
62
|
-
def valid?
|
63
|
-
response_code == 'Valid'
|
64
|
-
end
|
65
|
-
|
66
|
-
# Whether the domain has been validated but the account hasn't.
|
67
|
-
def valid_domain?
|
68
|
-
response_code == 'Valid' || response_code == 'Valid_CatchAll'
|
69
|
-
end
|
70
|
-
|
71
|
-
# Whether the email is invalid and shouldn't be accepted.
|
72
|
-
def invalid?
|
73
|
-
response_code == 'Invalid'
|
74
|
-
end
|
75
|
-
|
76
|
-
# Whether the validation could not be completed within the timeout specified.
|
77
|
-
def timeout?
|
78
|
-
response_code == 'Timeout'
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/lib/loqate/phone_gateway.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'loqate/client'
|
2
|
-
require 'loqate/result'
|
3
|
-
require 'loqate/mappers/error_mapper'
|
4
|
-
require 'loqate/mappers/generic_mapper'
|
5
|
-
require 'loqate/phone_number_validation'
|
6
|
-
|
7
|
-
module Loqate
|
8
|
-
# Starts a new phone number validation request.
|
9
|
-
#
|
10
|
-
class PhoneGateway
|
11
|
-
VALIDATE_ENDPOINT = '/PhoneNumberValidation/Interactive/Validate/v2.20/json3.ws'.freeze
|
12
|
-
|
13
|
-
include Result::Mixin
|
14
|
-
|
15
|
-
# Creates a phone gateway
|
16
|
-
#
|
17
|
-
# @param [Client] client The client responsible for the HTTP interactions
|
18
|
-
#
|
19
|
-
def initialize(client)
|
20
|
-
@client = client
|
21
|
-
@mapper = Mappers::GenericMapper.new
|
22
|
-
@error_mapper = Mappers::ErrorMapper.new
|
23
|
-
end
|
24
|
-
|
25
|
-
# Validates phone numbers.
|
26
|
-
#
|
27
|
-
# @param [Hash] options The options to validate a phone number.
|
28
|
-
# @option options [String] :phone The mobile/cell phone number to verify. This must be in international format
|
29
|
-
# (+447528471411 or 447528471411) if no country code is provided or national format with a Country parameter
|
30
|
-
# provided (07528471411 and GB as the Country parameter).
|
31
|
-
# @option options [String] :country The ISO2 country code of the number you are trying to validate
|
32
|
-
# (if provided in national format).
|
33
|
-
#
|
34
|
-
# @example
|
35
|
-
# phone_validation = phone_gateway.validate(phone: '447440019210', country: 'GB')
|
36
|
-
#
|
37
|
-
# @return [Result] A result wrapping a phone number validation
|
38
|
-
#
|
39
|
-
def validate(options)
|
40
|
-
response = client.get(VALIDATE_ENDPOINT, options)
|
41
|
-
|
42
|
-
response.errors? && build_error_from(response.items.first) || build_phone_validation_from(response.items.first)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Validates phone numbers.
|
46
|
-
#
|
47
|
-
# @param [Hash] options The options to validate a phone number.
|
48
|
-
# @option options [String] :phone The mobile/cell phone number to verify. This must be in international format
|
49
|
-
# (+447528471411 or 447528471411) if no country code is provided or national format with a Country parameter
|
50
|
-
# provided (07528471411 and GB as the Country parameter).
|
51
|
-
# @option options [String] :country The ISO2 country code of the number you are trying to validate
|
52
|
-
# (if provided in national format).
|
53
|
-
#
|
54
|
-
# @example
|
55
|
-
# phone_validation = phone_gateway.validate(phone: '447440019210', country: 'GB')
|
56
|
-
#
|
57
|
-
# @raise [Error] If the result is not a success
|
58
|
-
#
|
59
|
-
# @return [PhoneNumberValidation> A phone number validation
|
60
|
-
#
|
61
|
-
def validate!(options)
|
62
|
-
unwrap_result_or_raise { validate(options) }
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
# @api private
|
68
|
-
attr_reader :client, :mapper, :error_mapper
|
69
|
-
|
70
|
-
# @api private
|
71
|
-
def build_error_from(item)
|
72
|
-
error = error_mapper.map_one(item)
|
73
|
-
Failure(error)
|
74
|
-
end
|
75
|
-
|
76
|
-
# @api private
|
77
|
-
def build_phone_validation_from(item)
|
78
|
-
phone_number_validation = mapper.map_one(item, PhoneNumberValidation)
|
79
|
-
Success(phone_number_validation)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module Loqate
|
2
|
-
# Result of a phone number validation.
|
3
|
-
class PhoneNumberValidation < Dry::Struct::Value
|
4
|
-
IsValid = Types::Strict::String.enum('Yes', 'No', 'Unknown')
|
5
|
-
NumberType = Types::Strict::String.enum('Mobile', 'Landline', 'Voip', 'Unknown')
|
6
|
-
|
7
|
-
# The recipient phone number in international format.
|
8
|
-
#
|
9
|
-
# @return [String]
|
10
|
-
#
|
11
|
-
attribute :phone_number, Types::Strict::String
|
12
|
-
|
13
|
-
# Returns true if we managed to process the request on the network or false if the validation
|
14
|
-
# attempt was unsuccessful.
|
15
|
-
#
|
16
|
-
# @return [Boolean]
|
17
|
-
#
|
18
|
-
attribute :request_processed, Types::Strict::Bool
|
19
|
-
|
20
|
-
# Whether the number is valid or not (Unknown returned if validation wasn't possible).
|
21
|
-
#
|
22
|
-
# @return [String]
|
23
|
-
#
|
24
|
-
attribute :is_valid, IsValid
|
25
|
-
|
26
|
-
# The current operator serving the supplied number.
|
27
|
-
#
|
28
|
-
# @return [String]
|
29
|
-
#
|
30
|
-
attribute :network_code, Types::Strict::String
|
31
|
-
|
32
|
-
# The name of the current operator serving the supplied number.
|
33
|
-
#
|
34
|
-
# @return [String]
|
35
|
-
#
|
36
|
-
attribute :network_name, Types::Strict::String
|
37
|
-
|
38
|
-
# The country code of the operator.
|
39
|
-
#
|
40
|
-
# @return [String]
|
41
|
-
#
|
42
|
-
attribute :network_country, Types::Strict::String
|
43
|
-
|
44
|
-
# The domestic network format (useful for dialling from within the same country).
|
45
|
-
#
|
46
|
-
# @return [String]
|
47
|
-
#
|
48
|
-
attribute :national_format, Types::Strict::String
|
49
|
-
|
50
|
-
# The country prefix that must be prepended to the number when dialling internationally.
|
51
|
-
#
|
52
|
-
# @return [Integer]
|
53
|
-
#
|
54
|
-
attribute :country_prefix, Types::Coercible::Integer
|
55
|
-
|
56
|
-
# The type of number that was detected in the request (Mobile, Landline, VOIP or Unknown).
|
57
|
-
#
|
58
|
-
# @return [String]
|
59
|
-
#
|
60
|
-
attribute :number_type, NumberType
|
61
|
-
|
62
|
-
# Whether the validation was successful or not.
|
63
|
-
def valid?
|
64
|
-
is_valid == 'Yes'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|