loqate 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1480f53219de60b29e6137f502c3b5c09af4fc0b9f8737a8248d2e71704b391a
4
- data.tar.gz: 7842ed023231d338d31ede50f77e87e3ddcfcf78131754539bb55e3d9744722f
3
+ metadata.gz: f33980e922897d782156083e90517425569e09426cc653d5812e8df8618b42fa
4
+ data.tar.gz: b8aaca5b1a67c7c0ed9fafa14956a348bdea44f0480ba5f0c8d9a9e3ffb81e67
5
5
  SHA512:
6
- metadata.gz: 8e65821f932b0e0c2c910e0e92c02c4ab68cbde159db6e50ae645931c0497d3b87f0f4b37ada680f56feadb6a1302b3ea6d118fd4fbfa7c828b8484ad68b1aaf
7
- data.tar.gz: a56f36319aa424b4fb368defd2bb03b76770d66faec41ebe5ac6efe8f9ffaef5edee87595c437a6f85269a7841a083adfc3ff6872d59500996021d0452143bc3
6
+ metadata.gz: 29926eba63928015dd96214ea4e7fe987b91521afa10415b74b866756d6da202fed82da9829417293fcd9910ecc875b1f2247eae019d3d9d3151576bb961e7a0
7
+ data.tar.gz: 02a4def39549a2c69583b1528e401e3712576e2b3c9a98535675961fdfe89e7bfd656720e0140e874c496fd5fdee0dc738a7deab4944286aafa38cfed896863f
data/.yardstick.yml CHANGED
@@ -27,12 +27,31 @@ rules:
27
27
  - Loqate::APIResult#errors?
28
28
  - Loqate::APIResult#items
29
29
  - Loqate::APIResult#initialize
30
+ - Loqate::BatchEmailValidation#status
31
+ - Loqate::BatchEmailValidation#email_address
32
+ - Loqate::BatchEmailValidation#account
33
+ - Loqate::BatchEmailValidation#domain
34
+ - Loqate::BatchEmailValidation#is_disposible
35
+ - Loqate::BatchEmailValidation#is_system_mailbox
30
36
  - Loqate::Configuration#api_key
31
37
  - Loqate::Configuration#host
32
38
  - Loqate::Configuration#language
33
39
  - Loqate::Configuration#initialize
34
40
  - Loqate::DetailedAddress#initialize
35
41
  - Loqate::DetailedAddress#==
42
+ - Loqate::EmailGateway#initialize
43
+ - Loqate::EmailValidation#response_code
44
+ - Loqate::EmailValidation#response_message
45
+ - Loqate::EmailValidation#email_address
46
+ - Loqate::EmailValidation#user_account
47
+ - Loqate::EmailValidation#domain
48
+ - Loqate::EmailValidation#is_disposable_or_temporary
49
+ - Loqate::EmailValidation#is_complainer_or_fraud_risk
50
+ - Loqate::EmailValidation#duration
51
+ - Loqate::EmailValidation#valid?
52
+ - Loqate::EmailValidation#valid_domain?
53
+ - Loqate::EmailValidation#invalid?
54
+ - Loqate::EmailValidation#timeout?
36
55
  - Loqate::Error#id
37
56
  - Loqate::Error#description
38
57
  - Loqate::Error#cause
@@ -41,6 +60,7 @@ rules:
41
60
  - Loqate::Gateway#config
42
61
  - Loqate::Gateway#initialize
43
62
  - Loqate::Gateway#address
63
+ - Loqate::Gateway#email
44
64
  - Loqate::Gateway#phone
45
65
  - Loqate::PhoneGateway#initialize
46
66
  - Loqate::PhoneNumberValidation#phone_number
@@ -81,6 +101,12 @@ rules:
81
101
  - Loqate::Client#format_params
82
102
  - Loqate::Client#headers
83
103
  - Loqate::DetailedAddress#==
104
+ - Loqate::EmailGateway#error_mapper
105
+ - Loqate::EmailGateway#client
106
+ - Loqate::EmailGateway#mapper
107
+ - Loqate::EmailGateway#build_error_from
108
+ - Loqate::EmailGateway#build_email_validation_from
109
+ - Loqate::EmailGateway#build_email_validations_from
84
110
  - Loqate::Util.camelize
85
111
  - Loqate::Util#camelize
86
112
  - Loqate::Util.underscore
@@ -115,6 +141,12 @@ rules:
115
141
  - Loqate::Client#headers
116
142
  - Loqate::DetailedAddress#initialize
117
143
  - Loqate::DetailedAddress#==
144
+ - Loqate::EmailGateway#error_mapper
145
+ - Loqate::EmailGateway#client
146
+ - Loqate::EmailGateway#mapper
147
+ - Loqate::EmailGateway#build_error_from
148
+ - Loqate::EmailGateway#build_email_validation_from
149
+ - Loqate::EmailGateway#build_email_validations_from
118
150
  - Loqate::Error#attributes
119
151
  - Loqate::Gateway#client
120
152
  - Loqate::PhoneGateway#mapper
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.0] - 2018-11-20
8
+ ### Added
9
+ - Email API
10
+
7
11
  ## [0.4.0] - 2018-11-14
8
12
  ### Changed
9
13
  - Updated the gem `HTTP` to version `4.0.0`
@@ -45,6 +49,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
45
49
  - Initial core functionality
46
50
  - Codebase maintenance tools
47
51
 
52
+ [0.4.0]: https://github.com/wilsonsilva/loqate/compare/v0.4.0...v0.5.0
48
53
  [0.4.0]: https://github.com/wilsonsilva/loqate/compare/v0.3.0...v0.4.0
49
54
  [0.3.0]: https://github.com/wilsonsilva/loqate/compare/v0.2.0...v0.3.0
50
55
  [0.2.0]: https://github.com/wilsonsilva/loqate/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -21,6 +21,9 @@ Client to address verification, postcode lookup, & data quality services from Lo
21
21
  - [Retrieving the details of an address](#retrieving-the-details-of-an-address)
22
22
  - [Phone API](#phone-api)
23
23
  - [Validating a phone number](#validating-a-phone-number)
24
+ - [Email API](#phone-api)
25
+ - [Validating an email address](#validating-an-email-address)
26
+ - [Validating multiple email addresses](#validating-multiple-email-addresses)
24
27
  - [Development](#development)
25
28
  - [Contributing](#contributing)
26
29
  - [License](#license)
@@ -142,6 +145,50 @@ phone_validation.country_prefix # => 44
142
145
  phone_validation.number_type # => 'Mobile'
143
146
  ```
144
147
 
148
+ ### Email API
149
+
150
+ The Email API consists of two main API requests:
151
+ [Validate](https://www.loqate.com/resources/support/apis/EmailValidation/Interactive/Validate/2/) request to validate
152
+ a single email adress; and a
153
+ [Batch Validate](https://www.loqate.com/resources/support/apis/EmailValidation/Batch/Validate/1.2/) request to
154
+ validate multiple emails at once.
155
+
156
+ #### Validating an email address
157
+ ```ruby
158
+ email_validation = gateway.email.validate!(email: 'person@gmail.com')
159
+
160
+ email_validation.response_code # => 'Valid'
161
+ email_validation.response_message # => 'Email address was fully validated'
162
+ email_validation.email_address # => 'person@gmail.com'
163
+ email_validation.user_account # => 'person'
164
+ email_validation.domain # => 'gmail.com'
165
+ email_validation.is_disposable_or_temporary # => false
166
+ email_validation.is_complainer_or_fraud_risk # => false
167
+ email_validation.duration # => 0.007366261
168
+ email_validation.valid? # => true
169
+ email_validation.valid_domain? # => true
170
+ email_validation.invalid? # => false
171
+ email_validation.timeout? # => false
172
+ ```
173
+
174
+ #### Validating multiple email addresses
175
+
176
+ ```ruby
177
+ email_validations = gateway.email.batch_validate!(emails: %w[person@gmail.com])
178
+ email_validation = email_validations.first
179
+
180
+ email_validation.status # => 'Valid'
181
+ email_validation.email_address # => 'person@gmail.com'
182
+ email_validation.account # => 'person'
183
+ email_validation.domain # => 'gmail.com'
184
+ email_validation.is_disposible # => false
185
+ email_validation.is_system_mailbox # => false
186
+ email_validation.valid? # => true
187
+ email_validation.invalid? # => false
188
+ email_validation.unknown? # => false
189
+ email_validation.unverified? # => false
190
+ ```
191
+
145
192
  ## Development
146
193
 
147
194
  After checking out the repo, run `bin/setup` to install dependencies, configure git hooks and create support files.
data/ROADMAP.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - [x] Address Verification
18
18
  - [ ] Geocode
19
19
  - [ ] Data Cleanse
20
- - [ ] Email Verification
20
+ - [x] Email Verification
21
21
  - [x] Phone Verification
22
22
  - [ ] Bank Verification
23
23
 
@@ -0,0 +1,66 @@
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
@@ -0,0 +1,122 @@
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
@@ -0,0 +1,81 @@
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
@@ -1,4 +1,5 @@
1
1
  require 'loqate/address_gateway'
2
+ require 'loqate/email_gateway'
2
3
  require 'loqate/phone_gateway'
3
4
 
4
5
  module Loqate
@@ -40,6 +41,14 @@ module Loqate
40
41
  @phone ||= PhoneGateway.new(client)
41
42
  end
42
43
 
44
+ # Gateway to the Email verification APIs.
45
+ #
46
+ # @return [EmailGateway] An instance of an email gateway.
47
+ #
48
+ def email
49
+ @email ||= EmailGateway.new(client)
50
+ end
51
+
43
52
  private
44
53
 
45
54
  # @api private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Loqate
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loqate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2018-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -347,9 +347,12 @@ files:
347
347
  - lib/loqate/address.rb
348
348
  - lib/loqate/address_gateway.rb
349
349
  - lib/loqate/api_result.rb
350
+ - lib/loqate/batch_email_validation.rb
350
351
  - lib/loqate/client.rb
351
352
  - lib/loqate/configuration.rb
352
353
  - lib/loqate/detailed_address.rb
354
+ - lib/loqate/email_gateway.rb
355
+ - lib/loqate/email_validation.rb
353
356
  - lib/loqate/error.rb
354
357
  - lib/loqate/gateway.rb
355
358
  - lib/loqate/mappers/error_mapper.rb