verifalia 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f62d7d052459f6b915e2a063e82f365a193efef
4
- data.tar.gz: 56664aa94a510c5d84f8c57f2a2b3426e133e74d
3
+ metadata.gz: a9268cdfd8adf22bf8c53aaccb317df2ca89c73d
4
+ data.tar.gz: 0c875f61b52640e85ea599761af5eba0894d431e
5
5
  SHA512:
6
- metadata.gz: 3c7bdd1bd0b2f787bd7103f678b16a6c9707e943d9eee5625c55f4a40d8beaaaa1073657a0fdb1d45266e526cb340e2d8308de5c7791e1084ca945d96b017de4
7
- data.tar.gz: ebf691e4f825735b3b491ed0767598416ba3742fa2669f9db862d5c201898123d72de33c9e6e89c76823c3f351fb833b0f6553ee9e69454de75203e55df4e5b0
6
+ metadata.gz: 1fba2b844ea0d21a932f734804954ab41b9422ea4554edd340ac297283e463c5b29752cd62065541180c8f1f452e67e50377d3eaa5eebf646679af085ede140d
7
+ data.tar.gz: f35f86c72f10877bd0de0442241ac93284e5cd4cf49862420b01646f5a19c1d2abcf2a9840509dc6626463398f7051e3b6a5d5ed4a19ddba5c101129383375c5
data/Gemfile CHANGED
@@ -4,8 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- #gem 'rake', '~> 10.1'
8
7
  gem 'rspec', '~> 3.0'
9
- #gem 'fakeweb', '~> 1.3'
10
- #gem 'rack', '~> 1.3'
11
- end
8
+ gem 'coveralls', require: false
9
+ end
data/README.md CHANGED
@@ -1,3 +1,10 @@
1
+ [![Circle CI](https://circleci.com/gh/verifalia/verifalia-ruby-sdk.svg?style=shield)](https://circleci.com/gh/verifalia/verifalia-ruby-sdk)
2
+ [![Gem Version](https://badge.fury.io/rb/verifalia.svg)](https://badge.fury.io/rb/verifalia)
3
+ [![Dependency Status](https://gemnasium.com/verifalia/verifalia-ruby-sdk.svg)](https://gemnasium.com/verifalia/verifalia-ruby-sdk)
4
+ [![Code Climate](https://codeclimate.com/github/verifalia/verifalia-ruby-sdk/badges/gpa.svg)](https://codeclimate.com/github/verifalia/verifalia-ruby-sdk)
5
+ [![Coverage Status](https://coveralls.io/repos/verifalia/verifalia-ruby-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/verifalia/verifalia-ruby-sdk?branch=master)
6
+ [![Inline docs](http://inch-ci.org/github/verifalia/verifalia-ruby-sdk.svg?branch=master)](http://inch-ci.org/github/verifalia/verifalia-ruby-sdk)
7
+
1
8
  # Verifalia RESTful API - Ruby gem
2
9
 
3
10
  Verifalia provides a simple HTTPS-based API for validating email addresses and checking whether or not they are deliverable;
@@ -46,7 +53,7 @@ end
46
53
  ### Email Validations ###
47
54
 
48
55
  ```ruby
49
- #from scratch
56
+ ##from scratch
50
57
  emails = ['alice@example.com', 'bob@example.net']
51
58
  if (unique_id = @client.email_validations.verify(emails))
52
59
  #response is an hash with all the values returned
@@ -58,11 +65,18 @@ else
58
65
  end
59
66
 
60
67
 
61
- #with previous unique id
68
+ ##with previous unique id
62
69
  unique_id = "example-example"
63
70
 
64
- respone = @client.email_validations(unique_id: unique_id).query
71
+ #query job
72
+ response = @client.email_validations(unique_id: unique_id).query
65
73
 
74
+ #delete job
66
75
  @client.email_validations(unique_id: unique_id).destroy
67
76
 
77
+ # checking job status
78
+ if @client.email_validations(unique_id: unique_id).completed?
79
+ response = @client.email_validations(unique_id: unique_id).query
80
+ end
81
+
68
82
  ```
@@ -2,22 +2,21 @@ require 'rest_client'
2
2
  module Verifalia
3
3
  module REST
4
4
  class EmailValidations
5
-
6
5
  ##
7
6
  # The Verifalia::REST::EmailValidations class allow you to comminucate
8
7
  # with Email Validations Api. You don't need to instantiate this class, but
9
8
  # use the client for autoconfiguration. # The +args+ parameter is a hash of configuration
10
- # The following keys are supported:
9
+ # The following keys are supported:
11
10
  #
12
11
  # === <tt>unique_id: 'example-example'</tt>
13
12
  #
14
13
  # The unique if of the Verifalia Email Validation resource
15
14
  #
16
15
  def initialize(config, account_sid, account_token, args = {})
17
- @resource = RestClient::Resource.new "#{config[:host]}/#{config[:api_version]}/email-validations", account_sid, account_token
16
+ @resource = build_resource(config, account_sid, account_token)
18
17
  @unique_id = args[:unique_id] if args[:unique_id]
19
18
  end
20
-
19
+
21
20
  ##
22
21
  # Query the Email Validations Api with:
23
22
  #
@@ -30,7 +29,7 @@ module Verifalia
30
29
  data = emails.map { |email| { inputData: email }}
31
30
  content = { entries: data }.to_json
32
31
  begin
33
- r = @resource.post content, content_type: :json
32
+ r = @resource.post content
34
33
  @unique_id = JSON.parse(r)["uniqueID"]
35
34
  @response = nil
36
35
  @error = nil
@@ -40,7 +39,7 @@ module Verifalia
40
39
  false
41
40
  end
42
41
  end
43
-
42
+
44
43
  ##
45
44
  # Query the Email Validations Api for specific result. In order to use
46
45
  # this method you need to supply unique_id uring initialization or call verify first. If request fail,
@@ -49,8 +48,8 @@ module Verifalia
49
48
  def query
50
49
  raise ArgumentError, 'You must call verify first or supply and uniqueId' unless @unique_id
51
50
  unless @response
52
- begin
53
- r = @resource[@unique_id].get content_type: :json
51
+ begin
52
+ r = @resource[@unique_id].get
54
53
  @response = JSON.parse(r)
55
54
  @error = nil
56
55
  rescue => e
@@ -60,7 +59,7 @@ module Verifalia
60
59
  end
61
60
  @response
62
61
  end
63
-
62
+
64
63
  ##
65
64
  # Destroy an Email Validations entity. In order to use
66
65
  # this method you need to supply unique_id during initialization or call verify first. If request fail,
@@ -69,7 +68,7 @@ module Verifalia
69
68
  def destroy
70
69
  raise ArgumentError, 'You must call verify first or supply and uniqueId' unless @unique_id
71
70
  begin
72
- r = @resource[@unique_id].delete content_type: :json
71
+ r = @resource[@unique_id].delete
73
72
  @error = nil
74
73
  @response = nil
75
74
  @unique_id = nil
@@ -79,22 +78,27 @@ module Verifalia
79
78
  return false
80
79
  end
81
80
  end
82
-
81
+
83
82
  ##
84
83
  # Check if the Email validation entity is completed processed. In order to use
85
- # this method you need to supply unique_id during initialization or call verify first.
84
+ # this method you need to supply unique_id during initialization or call verify first.
86
85
  #
87
86
  def completed?
88
- query["noOfTotalEntries"] == query["noOfCompletedEntries"]
87
+ query_progress = query["progress"]
88
+ query_progress["noOfTotalEntries"] == query_progress["noOfCompletedEntries"]
89
89
  end
90
-
90
+
91
91
  def error
92
92
  @error
93
93
  end
94
-
95
- private
94
+
95
+ private
96
96
  def compute_error(e)
97
- case e.response.code
97
+ unless e.is_a? RestClient::Exception
98
+ @error = :internal_server_error
99
+ end
100
+
101
+ case e.http_code
98
102
  when 400
99
103
  @error = :bad_request
100
104
  when 401
@@ -111,6 +115,16 @@ module Verifalia
111
115
  @error = :internal_server_error
112
116
  end
113
117
  end
118
+
119
+ def build_resource(config, account_sid, account_token)
120
+ api_url = "#{config[:host]}/#{config[:api_version]}/email-validations"
121
+ opts = {
122
+ user: account_sid,
123
+ password: account_token,
124
+ headers: { content_type: :json }
125
+ }
126
+ return RestClient::Resource.new api_url, opts
127
+ end
114
128
  end
115
129
  end
116
- end
130
+ end
@@ -1,3 +1,3 @@
1
1
  module Verifalia
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -2,29 +2,36 @@ require 'spec_helper'
2
2
 
3
3
  describe Verifalia::REST::EmailValidations do
4
4
  let(:config) { { host: 'https://api.fake.com', api_version: "v" } }
5
-
5
+
6
6
  describe '#initialize' do
7
-
7
+
8
8
  it 'create RestClient::Resource with correct parameters' do
9
- expect(RestClient::Resource).to receive(:new).with("#{config[:host]}/#{config[:api_version]}/email-validations", 'someSid', 'someToken')
9
+ api_url = "#{config[:host]}/#{config[:api_version]}/email-validations"
10
+ opts = {
11
+ user: 'someSid',
12
+ password: 'someToken',
13
+ headers: { content_type: :json }
14
+ }
15
+
16
+ expect(RestClient::Resource).to receive(:new).with(api_url, opts)
10
17
  Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
11
18
  end
12
-
19
+
13
20
  it 'associate RestClient::Resource to @resource' do
14
21
  resource = double()
15
22
  allow(RestClient::Resource).to receive(:new).and_return(resource)
16
23
  email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
17
24
  expect(email_validations.instance_variable_get('@resource')).to eq(resource)
18
25
  end
19
-
26
+
20
27
  it 'associate :unique_id to @unique_id' do
21
28
  unique_id = double()
22
29
  email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken', unique_id: unique_id)
23
30
  expect(email_validations.instance_variable_get('@unique_id')).to eq(unique_id)
24
31
  end
25
-
32
+
26
33
  end
27
-
34
+
28
35
  context 'initialized' do
29
36
  let(:resource) { double().as_null_object }
30
37
  let(:response) { double().as_null_object }
@@ -32,26 +39,26 @@ describe Verifalia::REST::EmailValidations do
32
39
  @email_validations = Verifalia::REST::EmailValidations.new(config, 'someSid', 'someToken')
33
40
  @email_validations.instance_variable_set('@resource', resource)
34
41
  end
35
-
42
+
36
43
  describe '#verify' do
37
-
44
+
38
45
  it 'raise ArgumentError with nil emails' do
39
46
  expect{ @email_validations.verify(nil) }.to raise_error(ArgumentError)
40
47
  end
41
-
48
+
42
49
  it 'raise ArgumentError with empty emails' do
43
50
  expect{ @email_validations.verify([]) }.to raise_error(ArgumentError)
44
51
  end
45
-
52
+
46
53
  it 'call #post on @resources with correct parameters' do
47
54
  emails = ['first', 'second']
48
55
  data = emails.map { |email| { inputData: email }}
49
56
  content = { entries: data }.to_json
50
- expect(resource).to receive(:post).with(content, content_type: :json).and_return(response)
57
+ expect(resource).to receive(:post).with(content).and_return(response)
51
58
  expect(JSON).to receive(:parse).with(response).and_return(response)
52
59
  @email_validations.verify(emails)
53
60
  end
54
-
61
+
55
62
  it 'associate @unique_id and clear @response and @error' do
56
63
  emails = ['first', 'second']
57
64
  unique_id = 'fake'
@@ -63,7 +70,7 @@ describe Verifalia::REST::EmailValidations do
63
70
  expect(@email_validations.instance_variable_get('@response')).to eq(nil)
64
71
  expect(@email_validations.instance_variable_get('@error')).to eq(nil)
65
72
  end
66
-
73
+
67
74
  it 'return @unique_id' do
68
75
  emails = ['first', 'second']
69
76
  unique_id = 'fake'
@@ -73,38 +80,46 @@ describe Verifalia::REST::EmailValidations do
73
80
  result = @email_validations.verify(emails)
74
81
  expect(result).to eq(unique_id)
75
82
  end
76
-
83
+
77
84
  context 'request failed' do
78
-
85
+
79
86
  it 'raise exception, call #compute_error and return false' do
80
87
  emails = ['first', 'second']
81
88
  expect(resource).to receive(:post).and_raise(RestClient::Exception)
82
- expect(@email_validations).to receive(:compute_error).and_return(double())
83
89
  result = @email_validations.verify(emails)
84
90
  expect(result).to eq(false)
91
+ expect(@email_validations.error).to eq(:internal_server_error)
92
+ end
93
+
94
+ it 'raise exception, call #compute_error and return correct error' do
95
+ emails = ['first', 'second']
96
+ exception = RestClient::Exception.new(nil, 402)
97
+ expect(resource).to receive(:post).and_raise(exception)
98
+ result = @email_validations.verify(emails)
99
+ expect(result).to eq(false)
100
+ expect(@email_validations.error).to eq(:payment_required)
85
101
  end
86
-
87
102
  end
88
103
  end
89
-
104
+
90
105
  describe '#query' do
91
106
  it 'raise ArgumentError without @unique_id' do
92
107
  expect{ @email_validations.query }.to raise_error(ArgumentError)
93
108
  end
94
-
109
+
95
110
  context 'with @unique_id' do
96
111
  before(:each) do
97
112
  @email_validations.instance_variable_set('@unique_id', 'fake')
98
113
  end
99
-
114
+
100
115
  it 'call #get on @resource[@uniqueId] with correct parameters' do
101
116
  request = double()
102
117
  expect(resource).to receive(:[]).with('fake').and_return(request)
103
- expect(request).to receive(:get).with(content_type: :json).and_return(double().as_null_object)
118
+ expect(request).to receive(:get).and_return(double().as_null_object)
104
119
  expect(JSON).to receive(:parse)
105
120
  @email_validations.query
106
121
  end
107
-
122
+
108
123
  it 'return parsed json' do
109
124
  parsed = double()
110
125
  expect(resource).to receive(:[]).with('fake')
@@ -112,39 +127,58 @@ describe Verifalia::REST::EmailValidations do
112
127
  result = @email_validations.query
113
128
  expect(result).to eq(parsed)
114
129
  end
115
-
130
+
116
131
  context 'request failed' do
117
-
132
+
118
133
  it 'raise exception, call #compute_error and return false' do
119
134
  request = double()
120
135
  expect(resource).to receive(:[]).with('fake').and_return(request)
121
- expect(request).to receive(:get).with(content_type: :json).and_raise(RestClient::Exception)
136
+ expect(request).to receive(:get).and_raise(RestClient::Exception)
122
137
  expect(@email_validations).to receive(:compute_error).and_return(double())
123
138
  result = @email_validations.query
124
139
  expect(result).to eq(false)
125
140
  end
126
141
  end
127
-
142
+
143
+ end
144
+ end
145
+
146
+ describe '#completed?' do
147
+ let(:completed_query) do
148
+ { "progress"=> { "noOfTotalEntries" => 1, "noOfCompletedEntries" => 1 } }
149
+ end
150
+ let(:incompleted_query) do
151
+ { "progress"=> { "noOfTotalEntries" => 0, "noOfCompletedEntries" => 1 } }
152
+ end
153
+
154
+ it 'should return true if completed' do
155
+ expect(@email_validations).to receive(:query).and_return(completed_query)
156
+ expect(@email_validations.completed?).to be true
157
+ end
158
+
159
+ it 'should return false if not completed' do
160
+ expect(@email_validations).to receive(:query).and_return(incompleted_query)
161
+ expect(@email_validations.completed?).to be false
128
162
  end
129
163
  end
130
-
164
+
131
165
  describe '#destroy' do
132
166
  it 'raise ArgumentError without @unique_id' do
133
167
  expect{ @email_validations.destroy }.to raise_error(ArgumentError)
134
168
  end
135
-
169
+
136
170
  context 'with @unique_id' do
137
171
  before(:each) do
138
172
  @email_validations.instance_variable_set('@unique_id', 'fake')
139
173
  end
140
-
174
+
141
175
  it 'call #delete on @resource[@uniqueId]' do
142
176
  request = double()
143
177
  expect(resource).to receive(:[]).with('fake').and_return(request)
144
178
  expect(request).to receive(:delete).and_return(double().as_null_object)
145
179
  @email_validations.destroy
146
180
  end
147
-
181
+
148
182
  it 'clear @response, @unique_id and @error' do
149
183
  request = double()
150
184
  expect(resource).to receive(:[]).with('fake').and_return(request)
@@ -157,5 +191,5 @@ describe Verifalia::REST::EmailValidations do
157
191
  end
158
192
  end
159
193
  end
160
-
161
- end
194
+
195
+ end
@@ -3,12 +3,19 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'bundler'
4
4
  Bundler.setup
5
5
 
6
- Dir.glob(File.expand_path("../support/**/*.rb", __FILE__), &method(:require))
7
-
8
6
  require 'verifalia'
9
7
 
10
8
  RSpec.configure do |config|
11
9
  config.expect_with :rspec do |c|
12
10
  c.syntax = :expect
13
11
  end
14
- end
12
+ end
13
+
14
+ if ENV["CI"]
15
+ require 'coveralls'
16
+ Coveralls.wear!
17
+ else
18
+ require "simplecov"
19
+ SimpleCov.start
20
+ end
21
+
@@ -18,14 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.extra_rdoc_files = ['README.md', 'LICENSE']
21
+ spec.extra_rdoc_files = ['README.md']
22
22
  spec.rdoc_options = ['--line-numbers', '--inline-source', '--title', '--main', 'README.md']
23
23
 
24
24
  spec.add_dependency('builder', '>= 2.1.2')
25
- spec.add_dependency('rest-client', '~> 1.8.0')
25
+ spec.add_dependency('rest-client', '> 1.8.0')
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 1.6"
28
28
  spec.add_development_dependency "rake"
29
-
30
-
31
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verifalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Verifalia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -28,14 +28,14 @@ dependencies:
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.8.0
41
41
  - !ruby/object:Gem::Dependency
@@ -74,7 +74,6 @@ executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files:
76
76
  - README.md
77
- - LICENSE
78
77
  files:
79
78
  - ".gitignore"
80
79
  - Gemfile
@@ -87,7 +86,7 @@ files:
87
86
  - lib/verifalia/util/configuration.rb
88
87
  - lib/verifalia/version.rb
89
88
  - spec/rest/client_spec.rb
90
- - spec/rest/email_validations.spec.rb
89
+ - spec/rest/email_validations_spec.rb
91
90
  - spec/spec_helper.rb
92
91
  - spec/util/configuration_spec.rb
93
92
  - spec/verifalia_spec.rb
@@ -117,13 +116,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
116
  version: '0'
118
117
  requirements: []
119
118
  rubyforge_project:
120
- rubygems_version: 2.2.2
119
+ rubygems_version: 2.4.8
121
120
  signing_key:
122
121
  specification_version: 4
123
122
  summary: Verifalia API wrapper (email validation, list cleaning and scrubbing)
124
123
  test_files:
125
124
  - spec/rest/client_spec.rb
126
- - spec/rest/email_validations.spec.rb
125
+ - spec/rest/email_validations_spec.rb
127
126
  - spec/spec_helper.rb
128
127
  - spec/util/configuration_spec.rb
129
128
  - spec/verifalia_spec.rb