Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ name: CI

on:
push:
branches: [ master ]
branches: [ 'master' ]
pull_request:
branches: [ master ]

jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3']
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4']

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
rubocop-cache-ventures: rubocop.yml
7 changes: 0 additions & 7 deletions .rubocop_todo.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.0
3.4.4
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

# Specify your gem's dependencies in emailable-ruby.gemspec
gemspec
9 changes: 4 additions & 5 deletions emailable.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Gem::Specification.new do |s|
s.email = 'support@emailable.com'
s.license = 'MIT'
s.metadata = {
"bug_tracker_uri" => "https://github.com/emailable/emailable-ruby/issues",
"documentation_uri" => "https://docs.emailable.com/?ruby",
"source_code_uri" => "https://github.com/emailable/emailable-ruby"
'bug_tracker_uri' => 'https://github.com/emailable/emailable-ruby/issues',
'documentation_uri' => 'https://emailable.com/docs/api/?ruby',
'source_code_uri' => 'https://github.com/emailable/emailable-ruby'
}

s.files = `git ls-files`.split("\n")
Expand All @@ -29,8 +29,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'bundler'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'pry'
s.add_development_dependency 'awesome_print'
s.add_development_dependency 'amazing_print'
s.add_development_dependency 'minitest', '~> 5.0'
s.add_development_dependency 'minitest-reporters'
s.add_development_dependency 'activemodel'
Expand Down
6 changes: 3 additions & 3 deletions lib/emailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def verify(email, parameters = {})
parameters[:email] = email

client = Emailable::Client.new
response = client.request(:get, 'verify', parameters)
response = client.request(:post, 'verify', parameters)

if response.status == 249
raise Emailable::TimeoutError.new(response.body)
Expand All @@ -41,9 +41,9 @@ def verify(email, parameters = {})
end
end

def account
def account(parameters = {})
client = Emailable::Client.new
response = client.request(:get, 'account')
response = client.request(:get, 'account', parameters)
Account.new(response.body)
end

Expand Down
22 changes: 14 additions & 8 deletions lib/emailable/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ def initialize
end

def request(method, endpoint, params = {})
begin
tries ||= 3
api_key = params.delete(:api_key)
access_token = params.delete(:access_token)

uri = URI("#{@base_url}/#{endpoint}")
params[:api_key] = Emailable.api_key
uri = URI("#{@base_url}/#{endpoint}")
request_options = {
'Authorization': "Bearer #{Emailable.api_key || api_key || access_token}",
'Content-Type': 'application/json'
}

begin
tries ||= 3
http_response =
if method == :get
uri.query = URI.encode_www_form(params)
@connection.get(uri)
request = Net::HTTP::Get.new(uri, request_options)
request.set_form_data(params)
@connection.request(request)
elsif method == :post
request = Net::HTTP::Post.new(uri, 'Content-Type': 'application/json')
request = Net::HTTP::Post.new(uri, request_options)
request.body = params.to_json
@connection.request(request)
end
Expand Down Expand Up @@ -65,7 +71,7 @@ def create_connection(uri)
if connection.respond_to?(:write_timeout=)
connection.write_timeout = Emailable.write_timeout
end
connection.use_ssl = uri.scheme == "https"
connection.use_ssl = uri.scheme == 'https'

connection
end
Expand Down
4 changes: 2 additions & 2 deletions lib/emailable/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validate_each(record, attribute, value)
states = options.fetch(:states, %i(deliverable risky unknown))
allowed_states = %i[deliverable undeliverable risky unknown]
unless (states - allowed_states).empty?
raise ArgumentError, ":states must be an array of symbols containing "\
raise ArgumentError, ':states must be an array of symbols containing '\
"any or all of :#{allowed_states.join(', :')}"
end

Expand All @@ -29,7 +29,7 @@ def validate_each(record, attribute, value)

timeout = options.fetch(:timeout, 3)
unless timeout.is_a?(Integer) && timeout > 1
raise ArgumentError, ":timeout must be an Integer greater than 1"
raise ArgumentError, ':timeout must be an Integer greater than 1'
end

return if record.errors[attribute].present?
Expand Down
27 changes: 27 additions & 0 deletions test/authentication_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'test_helper'

class AuthenticationTest < Minitest::Test

def setup
@api_key = 'test_7aff7fc0142c65f86a00'
@email = 'jarrett@emailable.com'
@emails = ['jarrett@emailable.com', 'support@emailable.com']
end

def test_global_api_key_authentication
Emailable.api_key = @api_key

refute_nil Emailable.verify(@email).domain
refute_nil Emailable.account.owner_email
refute_nil bid = Emailable::Batch.new(@emails).verify
refute_nil Emailable::Batch.new(bid).status.id
end

def test_request_time_api_key_authentication
refute_nil Emailable.verify(@email, api_key: @api_key).domain
refute_nil Emailable.account(api_key: @api_key).owner_email
refute_nil bid = Emailable::Batch.new(@emails).verify(api_key: @api_key)
refute_nil Emailable::Batch.new(bid).status(api_key: @api_key).id
end

end
1 change: 0 additions & 1 deletion test/email_validator_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'active_model'
require 'test_helper'

class EmailValidatorTest < Minitest::Test
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'active_model'
require 'emailable'

require 'pry'
require 'minitest/autorun'
require 'minitest/reporters'
Minitest::Reporters.use! [
Expand Down