verifalia 1.2.0 → 2.1.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.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +5 -5
  3. data/LICENSE +3 -4
  4. data/README.md +415 -82
  5. data/Rakefile +4 -0
  6. data/lib/verifalia/client.rb +89 -0
  7. data/lib/verifalia/credits/balance.rb +59 -0
  8. data/lib/verifalia/credits/client.rb +54 -0
  9. data/lib/verifalia/email_validation/client.rb +237 -0
  10. data/lib/verifalia/email_validation/completion_callback.rb +44 -0
  11. data/lib/verifalia/email_validation/entry.rb +124 -0
  12. data/lib/verifalia/email_validation/entry_classification.rb +49 -0
  13. data/lib/verifalia/email_validation/entry_status.rb +181 -0
  14. data/lib/verifalia/email_validation/exported_entries_format.rb +46 -0
  15. data/lib/verifalia/email_validation/job.rb +107 -0
  16. data/lib/verifalia/email_validation/job_status.rb +49 -0
  17. data/lib/verifalia/email_validation/overview.rb +108 -0
  18. data/lib/verifalia/email_validation/progress.rb +48 -0
  19. data/lib/verifalia/email_validation/request.rb +48 -0
  20. data/lib/verifalia/email_validation/request_entry.rb +43 -0
  21. data/lib/verifalia/email_validation/wait_options.rb +82 -0
  22. data/lib/verifalia/rest/client.rb +111 -0
  23. data/lib/verifalia/security/certificate_authenticator.rb +50 -0
  24. data/lib/verifalia/security/username_password_authenticator.rb +51 -0
  25. data/lib/verifalia.rb +49 -21
  26. data/sig/completion_callback.rbs +5 -0
  27. data/sig/verifalia/client.rbs +11 -0
  28. data/sig/verifalia/credits/balance.rbs +11 -0
  29. data/sig/verifalia/credits/client.rbs +7 -0
  30. data/sig/verifalia/email_validations/client.rbs +24 -0
  31. data/sig/verifalia/email_validations/entry.rbs +24 -0
  32. data/sig/verifalia/email_validations/entry_classification.rbs +10 -0
  33. data/sig/verifalia/email_validations/entry_status.rbs +50 -0
  34. data/sig/verifalia/email_validations/exported_entries_format.rbs +9 -0
  35. data/sig/verifalia/email_validations/job.rbs +13 -0
  36. data/sig/verifalia/email_validations/job_status.rbs +10 -0
  37. data/sig/verifalia/email_validations/overview.rbs +20 -0
  38. data/sig/verifalia/email_validations/progress.rbs +8 -0
  39. data/sig/verifalia/email_validations/request.rbs +13 -0
  40. data/sig/verifalia/email_validations/request_entry.rbs +8 -0
  41. data/sig/verifalia/email_validations/wait_options.rbs +20 -0
  42. data/sig/verifalia/rest/client.rbs +12 -0
  43. data/sig/verifalia/rest.rbs +6 -0
  44. data/sig/verifalia/security/certificate_authenticator.rbs +8 -0
  45. data/sig/verifalia/security/username_password_authenticator.rbs +10 -0
  46. data/verifalia.gemspec +27 -18
  47. metadata +72 -64
  48. data/.gitignore +0 -24
  49. data/lib/rest/account_balance.rb +0 -93
  50. data/lib/rest/client.rb +0 -83
  51. data/lib/rest/email_validations.rb +0 -195
  52. data/lib/verifalia/util/configuration.rb +0 -7
  53. data/lib/verifalia/version.rb +0 -3
  54. data/spec/rest/account_balance_spec.rb +0 -93
  55. data/spec/rest/client_spec.rb +0 -105
  56. data/spec/rest/email_validations_spec.rb +0 -322
  57. data/spec/spec_helper.rb +0 -21
  58. data/spec/util/configuration_spec.rb +0 -15
  59. data/spec/verifalia_spec.rb +0 -17
@@ -0,0 +1,10 @@
1
+ module Verifalia
2
+ module Security
3
+ class UsernamePasswordAuthenticator
4
+ @password: String | nil
5
+ @username: String
6
+
7
+ def authenticate: -> void
8
+ end
9
+ end
10
+ end
data/verifalia.gemspec CHANGED
@@ -1,29 +1,38 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'verifalia/version'
5
+ require 'verifalia/client'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "verifalia"
8
- spec.version = Verifalia::VERSION
9
- spec.authors = ["Verifalia"]
10
- spec.email = ["support@verifalia.com"]
11
- spec.summary = "Verifalia API wrapper (email validation, list cleaning and scrubbing)"
12
- spec.description = "A simple library for communicating with the Verifalia RESTful API, validating lists of email addresses and checking whether or not they are deliverable."
13
- spec.homepage = "http://verifalia.com"
14
- spec.license = "MIT"
8
+ spec.name = 'verifalia'
9
+ spec.version = Verifalia::Client::VERSION
10
+ spec.authors = ['Verifalia', 'Efran Cobisi', 'Guido Tersilli', 'Rudy Chiappetta', 'Germano Mosconi']
11
+ spec.email = ['support@verifalia.com']
12
+ spec.summary = 'Verifalia - Ruby SDK and helper library'
13
+ spec.description = 'Verifalia provides a simple API for validating email addresses and checking whether they are deliverable or not. This library allows to easily integrate with Verifalia and verify email addresses in real-time.'
14
+ spec.homepage = 'https://verifalia.com/'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = '>= 2.6.0'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/verifalia/verifalia-ruby-sdk.git'
15
20
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
26
+ end
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
20
31
 
21
32
  spec.extra_rdoc_files = ['README.md']
22
- spec.rdoc_options = ['--line-numbers', '--inline-source', '--title', '--main', 'README.md']
23
33
 
24
- spec.add_dependency('builder', '>= 2.1.2')
25
- spec.add_dependency('rest-client', '>= 2.0.0')
34
+ spec.add_dependency('faraday', '~> 2.7')
26
35
 
27
- spec.add_development_dependency "bundler", "~> 1.6"
28
- spec.add_development_dependency "rake"
36
+ spec.add_development_dependency 'bundler', '~> 2.4.8'
37
+ spec.add_development_dependency 'rake', '~> 13.0'
29
38
  end
metadata CHANGED
@@ -1,73 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verifalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Verifalia
8
- autorequire:
9
- bindir: bin
8
+ - Efran Cobisi
9
+ - Guido Tersilli
10
+ - Rudy Chiappetta
11
+ - Germano Mosconi
12
+ autorequire:
13
+ bindir: exe
10
14
  cert_chain: []
11
- date: 2017-09-13 00:00:00.000000000 Z
15
+ date: 2024-01-18 00:00:00.000000000 Z
12
16
  dependencies:
13
17
  - !ruby/object:Gem::Dependency
14
- name: builder
18
+ name: faraday
15
19
  requirement: !ruby/object:Gem::Requirement
16
20
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 2.1.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 2.1.2
27
- - !ruby/object:Gem::Dependency
28
- name: rest-client
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
21
+ - - "~>"
32
22
  - !ruby/object:Gem::Version
33
- version: 2.0.0
23
+ version: '2.7'
34
24
  type: :runtime
35
25
  prerelease: false
36
26
  version_requirements: !ruby/object:Gem::Requirement
37
27
  requirements:
38
- - - ">="
28
+ - - "~>"
39
29
  - !ruby/object:Gem::Version
40
- version: 2.0.0
30
+ version: '2.7'
41
31
  - !ruby/object:Gem::Dependency
42
32
  name: bundler
43
33
  requirement: !ruby/object:Gem::Requirement
44
34
  requirements:
45
35
  - - "~>"
46
36
  - !ruby/object:Gem::Version
47
- version: '1.6'
37
+ version: 2.4.8
48
38
  type: :development
49
39
  prerelease: false
50
40
  version_requirements: !ruby/object:Gem::Requirement
51
41
  requirements:
52
42
  - - "~>"
53
43
  - !ruby/object:Gem::Version
54
- version: '1.6'
44
+ version: 2.4.8
55
45
  - !ruby/object:Gem::Dependency
56
46
  name: rake
57
47
  requirement: !ruby/object:Gem::Requirement
58
48
  requirements:
59
- - - ">="
49
+ - - "~>"
60
50
  - !ruby/object:Gem::Version
61
- version: '0'
51
+ version: '13.0'
62
52
  type: :development
63
53
  prerelease: false
64
54
  version_requirements: !ruby/object:Gem::Requirement
65
55
  requirements:
66
- - - ">="
56
+ - - "~>"
67
57
  - !ruby/object:Gem::Version
68
- version: '0'
69
- description: A simple library for communicating with the Verifalia RESTful API, validating
70
- lists of email addresses and checking whether or not they are deliverable.
58
+ version: '13.0'
59
+ description: Verifalia provides a simple API for validating email addresses and checking
60
+ whether they are deliverable or not. This library allows to easily integrate with
61
+ Verifalia and verify email addresses in real-time.
71
62
  email:
72
63
  - support@verifalia.com
73
64
  executables: []
@@ -75,57 +66,74 @@ extensions: []
75
66
  extra_rdoc_files:
76
67
  - README.md
77
68
  files:
78
- - ".gitignore"
79
69
  - Gemfile
80
70
  - LICENSE
81
71
  - README.md
82
72
  - Rakefile
83
- - lib/rest/account_balance.rb
84
- - lib/rest/client.rb
85
- - lib/rest/email_validations.rb
86
73
  - lib/verifalia.rb
87
- - lib/verifalia/util/configuration.rb
88
- - lib/verifalia/version.rb
89
- - spec/rest/account_balance_spec.rb
90
- - spec/rest/client_spec.rb
91
- - spec/rest/email_validations_spec.rb
92
- - spec/spec_helper.rb
93
- - spec/util/configuration_spec.rb
94
- - spec/verifalia_spec.rb
74
+ - lib/verifalia/client.rb
75
+ - lib/verifalia/credits/balance.rb
76
+ - lib/verifalia/credits/client.rb
77
+ - lib/verifalia/email_validation/client.rb
78
+ - lib/verifalia/email_validation/completion_callback.rb
79
+ - lib/verifalia/email_validation/entry.rb
80
+ - lib/verifalia/email_validation/entry_classification.rb
81
+ - lib/verifalia/email_validation/entry_status.rb
82
+ - lib/verifalia/email_validation/exported_entries_format.rb
83
+ - lib/verifalia/email_validation/job.rb
84
+ - lib/verifalia/email_validation/job_status.rb
85
+ - lib/verifalia/email_validation/overview.rb
86
+ - lib/verifalia/email_validation/progress.rb
87
+ - lib/verifalia/email_validation/request.rb
88
+ - lib/verifalia/email_validation/request_entry.rb
89
+ - lib/verifalia/email_validation/wait_options.rb
90
+ - lib/verifalia/rest/client.rb
91
+ - lib/verifalia/security/certificate_authenticator.rb
92
+ - lib/verifalia/security/username_password_authenticator.rb
93
+ - sig/completion_callback.rbs
94
+ - sig/verifalia/client.rbs
95
+ - sig/verifalia/credits/balance.rbs
96
+ - sig/verifalia/credits/client.rbs
97
+ - sig/verifalia/email_validations/client.rbs
98
+ - sig/verifalia/email_validations/entry.rbs
99
+ - sig/verifalia/email_validations/entry_classification.rbs
100
+ - sig/verifalia/email_validations/entry_status.rbs
101
+ - sig/verifalia/email_validations/exported_entries_format.rbs
102
+ - sig/verifalia/email_validations/job.rbs
103
+ - sig/verifalia/email_validations/job_status.rbs
104
+ - sig/verifalia/email_validations/overview.rbs
105
+ - sig/verifalia/email_validations/progress.rbs
106
+ - sig/verifalia/email_validations/request.rbs
107
+ - sig/verifalia/email_validations/request_entry.rbs
108
+ - sig/verifalia/email_validations/wait_options.rbs
109
+ - sig/verifalia/rest.rbs
110
+ - sig/verifalia/rest/client.rbs
111
+ - sig/verifalia/security/certificate_authenticator.rbs
112
+ - sig/verifalia/security/username_password_authenticator.rbs
95
113
  - verifalia.gemspec
96
- homepage: http://verifalia.com
114
+ homepage: https://verifalia.com/
97
115
  licenses:
98
116
  - MIT
99
- metadata: {}
100
- post_install_message:
101
- rdoc_options:
102
- - "--line-numbers"
103
- - "--inline-source"
104
- - "--title"
105
- - "--main"
106
- - README.md
117
+ metadata:
118
+ homepage_uri: https://verifalia.com/
119
+ source_code_uri: https://github.com/verifalia/verifalia-ruby-sdk.git
120
+ post_install_message:
121
+ rdoc_options: []
107
122
  require_paths:
108
123
  - lib
109
124
  required_ruby_version: !ruby/object:Gem::Requirement
110
125
  requirements:
111
126
  - - ">="
112
127
  - !ruby/object:Gem::Version
113
- version: '0'
128
+ version: 2.6.0
114
129
  required_rubygems_version: !ruby/object:Gem::Requirement
115
130
  requirements:
116
131
  - - ">="
117
132
  - !ruby/object:Gem::Version
118
133
  version: '0'
119
134
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.4.8
122
- signing_key:
135
+ rubygems_version: 3.3.15
136
+ signing_key:
123
137
  specification_version: 4
124
- summary: Verifalia API wrapper (email validation, list cleaning and scrubbing)
125
- test_files:
126
- - spec/rest/account_balance_spec.rb
127
- - spec/rest/client_spec.rb
128
- - spec/rest/email_validations_spec.rb
129
- - spec/spec_helper.rb
130
- - spec/util/configuration_spec.rb
131
- - spec/verifalia_spec.rb
138
+ summary: Verifalia - Ruby SDK and helper library
139
+ test_files: []
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- .rvmrc
24
- test.rb
@@ -1,93 +0,0 @@
1
- require 'rest_client'
2
- require 'json'
3
- module Verifalia
4
- module REST
5
- class AccountBalance
6
- ##
7
- # The Verifalia::REST::AccountBalance class allow you to comminucate
8
- # with Account balance Api. You don't need to instantiate this class, but
9
- # use the client for autoconfiguration. # The +args+ parameter is a hash of configuration
10
- def initialize(config, account_sid, account_token, args = {})
11
- @resources = build_resources(config, account_sid, account_token)
12
- end
13
-
14
- ##
15
- # Query the Account balance
16
- #
17
- def balance()
18
- begin
19
- response = multiplex_request do |resource|
20
- resource[@unique_id].get
21
- end
22
- @error = nil
23
- JSON.parse(response)
24
- rescue => e
25
- compute_error(e)
26
- false
27
- end
28
- end
29
-
30
- def error
31
- @error
32
- end
33
-
34
- private
35
-
36
- def multiplex_request
37
- @resources.shuffle.each do |resource|
38
- begin
39
- response = yield(resource)
40
- return response
41
- rescue => e
42
- if ((e.is_a? RestClient::Exception) && (e.http_code != 500))
43
- raise e
44
- end
45
- end
46
- end
47
- raise RestClient::Exception.new(nil, 500)
48
- end
49
-
50
- def compute_error(e)
51
- unless e.is_a? RestClient::Exception
52
- @error = :internal_server_error
53
- end
54
-
55
- case e.http_code
56
- when 400
57
- @error = :bad_request
58
- when 401
59
- @error = :unauthorized
60
- when 402
61
- @error = :payment_required
62
- when 403
63
- @error = :forbidden
64
- when 404
65
- @error = :not_found
66
- when 406
67
- @error = :not_acceptable
68
- when 410
69
- @error = :gone
70
- when 429
71
- @error = :too_many_request
72
- else
73
- @error = :internal_server_error
74
- end
75
- end
76
-
77
- def build_resources(config, account_sid, account_token)
78
- opts = {
79
- user: account_sid,
80
- password: account_token,
81
- headers: {
82
- content_type: :json,
83
- user_agent: "verifalia-rest-client/ruby/#{Verifalia::VERSION}"
84
- }
85
- }
86
- config[:hosts].map do |host|
87
- api_url = "#{host}/#{config[:api_version]}/account-balance"
88
- RestClient::Resource.new api_url, opts
89
- end
90
- end
91
- end
92
- end
93
- end
data/lib/rest/client.rb DELETED
@@ -1,83 +0,0 @@
1
- require 'rest/email_validations'
2
- require 'rest/account_balance'
3
-
4
- module Verifalia
5
- module REST
6
- ##
7
- # The Verifalia::REST::Client class caches authentication parameters and
8
- # exposes methods to make HTTP requests to Verifalia's REST API. However, you
9
- # should never really need to call these methods yourself since you can
10
- # work with the more pleasant wrapper objects like Verifalia::REST::EmailValidations
11
- #
12
- # Instantiate a client like so:
13
- #
14
- # @client = Verifalia::REST::Client.new account_sid, auth_token
15
- #
16
-
17
- # Once you have a client object you can use it to do fun things. Every
18
- # client object exposes a wrapper for a specific API. For example:
19
- #
20
- # ==== @client.email_validations
21
- #
22
- class Client
23
-
24
- attr_reader :account_sid, :account_token
25
-
26
- API_VERSION = 'v1.4'
27
-
28
- DEFAULTS = {
29
- hosts: ['https://api-1.verifalia.com', 'https://api-2.verifalia.com'],
30
- api_version: 'v1.4'
31
- }
32
-
33
- ##
34
- # Instantiate a new HTTP client to talk to Verifalia. The parameters
35
- # +account_sid+ and +auth_token+ are required, unless you have configured
36
- # them already using the block configure syntax, and used to generate the
37
- # HTTP basic auth header in each request. The +args+ parameter is a
38
- # hash of connection configuration options. the following keys are
39
- # supported:
40
- #
41
- # === <tt>host: 'https://api.verifalia.com'</tt>
42
- #
43
- # === <tt>api_version: 'v1.1'</tt>
44
- #
45
- def initialize(*args)
46
- options = args.last.is_a?(Hash) ? args.pop : {}
47
- @config = DEFAULTS.merge! options
48
- @account_sid = args[0] || Verifalia.account_sid
49
- @auth_token = args[1] || Verifalia.auth_token
50
-
51
- if @account_sid.nil? || @auth_token.nil?
52
- raise ArgumentError, 'Account SID and auth token are required'
53
- end
54
-
55
- end
56
-
57
- ##
58
- # Instantiate a new HTTP client to talk to Verifalia Email Validation Api.
59
- # The +args+ parameter is a hash of configuration
60
- # The following keys are supported:
61
- #
62
- # === <tt>unique_id: 'example-example'</tt>
63
- #
64
- # The unique if of the Verifalia Email Validation resource
65
- #
66
- def email_validations(args = {})
67
- if (args.empty?)
68
- @email_validations ||= EmailValidations.new @config, @account_sid, @auth_token
69
- else
70
- EmailValidations.new @config, @account_sid, @auth_token, args
71
- end
72
- end
73
-
74
- ##
75
- # Instantiate a new HTTP client to talk to Verifalia Account Balance Api.
76
- #
77
- def account_balance()
78
- @account_balance ||= AccountBalance.new @config, @account_sid, @auth_token
79
- end
80
-
81
- end
82
- end
83
- end
@@ -1,195 +0,0 @@
1
- require 'rest_client'
2
- require 'json'
3
- module Verifalia
4
- module REST
5
- class EmailValidations
6
-
7
- COMPLETION_MAX_RETRY = 5
8
- COMPLETION_INTERVAL = 1
9
- ##
10
- # The Verifalia::REST::EmailValidations class allow you to comminucate
11
- # with Email Validations Api. You don't need to instantiate this class, but
12
- # use the client for autoconfiguration. # The +args+ parameter is a hash of configuration
13
- # The following keys are supported:
14
- #
15
- # === <tt>unique_id: 'example-example'</tt>
16
- #
17
- # The unique if of the Verifalia Email Validation resource
18
- #
19
- def initialize(config, account_sid, account_token, args = {})
20
- @resources = build_resources(config, account_sid, account_token)
21
- @unique_id = args[:unique_id] if args[:unique_id]
22
- end
23
-
24
- ##
25
- # Query the Email Validations Api with:
26
- #
27
- # === <tt> inputs: ['test@test.com']
28
- # === <tt> inputs: data = [{ inputData: 'first@first.it' }, { inputData: 'first@first.it' } ]
29
- # === <tt> options: { quality: 'high', priority: 100, deduplication: 'safe' } view verifalia API documentation
30
- #
31
- # An array of emails to validate
32
- #
33
- def verify(inputs, options = {})
34
- raise ArgumentError, 'inputs must be not empty' if (inputs.nil? || inputs.empty?)
35
- raise ArgumentError, 'options must be hash' if (!options.is_a?(Hash))
36
- data = inputs.map do |input|
37
- if (input.is_a? String)
38
- { inputData: input }
39
- elsif (input.is_a? Hash)
40
- raise ArgumentError, 'if inputs content is a Hash you need to supply :inputData as key' if (!input.has_key?(:inputData))
41
- input
42
- else
43
- raise ArgumentError, 'inputs content must be a String or a Hash'
44
- end
45
- end
46
- content = ({ entries: data }.merge(options)).to_json
47
- begin
48
- @response = multiplex_request do |resource|
49
- resource.post content
50
- end
51
- @query_result = JSON.parse(@response)
52
- @unique_id = @query_result["uniqueID"]
53
- @error = nil
54
- @unique_id
55
- rescue => e
56
- compute_error(e)
57
- false
58
- end
59
- end
60
-
61
- ##
62
- # Query the Email Validations Api for specific result. In order to use
63
- # this method you need to supply unique_id uring initialization or call verify first. If request fail,
64
- # you can call <tt>error</tt> to receive detailed information
65
- #
66
- # === <tt> options: { wait_for_completion: true, completion_max_retry: 5, completion_interval: 1(seconds) }
67
- def query(options = {})
68
- raise ArgumentError, 'You must call verify first or supply and uniqueId' unless @unique_id
69
- opts = {
70
- wait_for_completion: false,
71
- completion_max_retry: COMPLETION_MAX_RETRY,
72
- completion_interval: COMPLETION_INTERVAL,
73
- }
74
- .merge! options
75
- if @query_result == nil || !completed?
76
- begin
77
- loop_count = 0
78
- loop do
79
- @response = multiplex_request do |resource|
80
- resource[@unique_id].get
81
- end
82
- @query_result = JSON.parse(@response)
83
- @error = nil
84
- loop_count += 1
85
- sleep opts[:completion_interval] if opts[:wait_for_completion]
86
- break if !opts[:wait_for_completion] || (completed? || loop_count >= opts[:completion_max_retry])
87
- end
88
- rescue => e
89
- compute_error(e)
90
- return false
91
- end
92
- end
93
- if (opts[:wait_for_completion] && !completed?)
94
- @error = :not_completed
95
- false
96
- else
97
- @query_result
98
- end
99
- end
100
-
101
- ##
102
- # Destroy an Email Validations entity. In order to use
103
- # this method you need to supply unique_id during initialization or call verify first. If request fail,
104
- # you can call <tt>error</tt> to receive detailed information
105
- #
106
- def destroy
107
- raise ArgumentError, 'You must call verify first or supply and uniqueId' unless @unique_id
108
- begin
109
- r = multiplex_request do |resource|
110
- resource[@unique_id].delete
111
- end
112
- @error = nil
113
- @response = nil
114
- @query_result = nil
115
- @unique_id = nil
116
- true
117
- rescue => e
118
- return true if (e.is_a? RestClient::Exception && e.http_code == 410)
119
- compute_error(e)
120
- return false
121
- end
122
- end
123
-
124
- ##
125
- # Check if the Email validation entity is completed processed. In order to use
126
- # this method you need to supply unique_id during initialization or call verify first.
127
- #
128
- def completed?
129
- @response.code == 200
130
- end
131
-
132
- def error
133
- @error
134
- end
135
-
136
- private
137
-
138
- def multiplex_request
139
- @resources.shuffle.each do |resource|
140
- begin
141
- response = yield(resource)
142
- return response
143
- rescue => e
144
- if ((e.is_a? RestClient::Exception) && (e.http_code != 500))
145
- raise e
146
- end
147
- end
148
- end
149
- raise RestClient::Exception.new(nil, 500)
150
- end
151
-
152
- def compute_error(e)
153
- unless e.is_a? RestClient::Exception
154
- @error = :internal_server_error
155
- end
156
-
157
- case e.http_code
158
- when 400
159
- @error = :bad_request
160
- when 401
161
- @error = :unauthorized
162
- when 402
163
- @error = :payment_required
164
- when 403
165
- @error = :forbidden
166
- when 404
167
- @error = :not_found
168
- when 406
169
- @error = :not_acceptable
170
- when 410
171
- @error = :gone
172
- when 429
173
- @error = :too_many_request
174
- else
175
- @error = :internal_server_error
176
- end
177
- end
178
-
179
- def build_resources(config, account_sid, account_token)
180
- opts = {
181
- user: account_sid,
182
- password: account_token,
183
- headers: {
184
- content_type: :json,
185
- user_agent: "verifalia-rest-client/ruby/#{Verifalia::VERSION}"
186
- }
187
- }
188
- config[:hosts].map do |host|
189
- api_url = "#{host}/#{config[:api_version]}/email-validations"
190
- RestClient::Resource.new api_url, opts
191
- end
192
- end
193
- end
194
- end
195
- end
@@ -1,7 +0,0 @@
1
- module Verifalia
2
- module Util
3
- class Configuration
4
- attr_accessor :account_sid, :auth_token, :hosts
5
- end
6
- end
7
- end
@@ -1,3 +0,0 @@
1
- module Verifalia
2
- VERSION = "1.2.0"
3
- end