emailable 3.1.0 → 3.1.1

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: 708c483149a304ccfbac1757c300380475d579afa28a72c85738432ffeff7b6f
4
- data.tar.gz: 3350fc08596f6f3a7b6991a299ec52eee0d246fef52727103b6d927cdd62d23c
3
+ metadata.gz: 90f1d586f58f97cf11f78a6dac64fa169e9ff0d1a2902a4f5df86a32f9d16dae
4
+ data.tar.gz: 20e10632676d8374b41048c9324fe879c5da2cc0841a71ae9bf920ea752abc58
5
5
  SHA512:
6
- metadata.gz: '08863dd0a81fa48eeef2a871ca1b4249386c3b64f5246249bdd289dbd7d933242c24b50aa7817eac8f5defaa325a761bb96c98e9ddb49053801780577cddcd4d'
7
- data.tar.gz: a49925c87814ea286e45a337ab372c353cae67a094c78244ba73264e18e98e00c8b43a88f6d70a1e5c31d76f97fa90fe422f8a3645e6b8f5da27e169fc495812
6
+ metadata.gz: 644ea041fc96995db1c0121be0b494f1cbea6df42dbbf691afebce236ce567a5db4ee87d34bf222dc26e244a4624777ca8a08a4df899a980050902403a31a7e0
7
+ data.tar.gz: 54b5b43f725562bcae4a38385b70a9ff61e74c4fbe74200b288d1112ed7b640eea2326c618ea8f1adf815f5aad42ef69982029f70f7246bbf55746bfe752435f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- emailable (3.0.2)
4
+ emailable (3.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Emailable Ruby Library
2
2
 
3
- [![Build Status](https://app.travis-ci.com/emailable/emailable-ruby.svg)](https://travis-ci.com/emailable/emailable-ruby)
3
+ [![Build Status](https://app.travis-ci.com/emailable/emailable-ruby.svg)](https://app.travis-ci.com/emailable/emailable-ruby)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/e7eef54e491adec95e6d/maintainability)](https://codeclimate.com/github/emailable/emailable-ruby/maintainability)
5
5
 
6
6
  This is the official ruby wrapper for the Emailable API.
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "emailable/ruby"
3
+ require 'bundler/setup'
4
+ require 'emailable'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
10
+ # require 'pry'
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,5 +1,15 @@
1
1
  module Emailable
2
2
  class Client
3
+ ERRORS = {
4
+ 400 => BadRequestError,
5
+ 401 => UnauthorizedError,
6
+ 402 => PaymentRequiredError,
7
+ 403 => ForbiddenError,
8
+ 404 => NotFoundError,
9
+ 429 => TooManyRequestsError,
10
+ 500 => InternalServerError,
11
+ 503 => ServiceUnavailableError
12
+ }.freeze
3
13
 
4
14
  def initialize
5
15
  @base_url = 'https://api.emailable.com/v1'
@@ -33,22 +43,7 @@ module Emailable
33
43
  status = response.status
34
44
  return response if status.between?(200, 299)
35
45
 
36
- error_attributes = {
37
- message: response.body['message'],
38
- code: status
39
- }
40
- error_map = {
41
- '400' => BadRequestError,
42
- '401' => UnauthorizedError,
43
- '402' => PaymentRequiredError,
44
- '403' => ForbiddenError,
45
- '404' => NotFoundError,
46
- '429' => TooManyRequestsError,
47
- '500' => InternalServerError,
48
- '503' => ServiceUnavailableError
49
- }
50
-
51
- raise error_map[status.to_s].new(error_attributes)
46
+ raise ERRORS[status].new(response.body['message'])
52
47
  end
53
48
 
54
49
  private
@@ -0,0 +1,12 @@
1
+ module Emailable
2
+ class Error < StandardError; end
3
+ class BadRequestError < Error; end
4
+ class UnauthorizedError < Error; end
5
+ class PaymentRequiredError < Error; end
6
+ class ForbiddenError < Error; end
7
+ class NotFoundError < Error; end
8
+ class TooManyRequestsError < Error; end
9
+ class InternalServerError < Error; end
10
+ class ServiceUnavailableError < Error; end
11
+ class TimeoutError < Error; end
12
+ end
@@ -7,13 +7,21 @@ module Emailable
7
7
  end
8
8
  end
9
9
 
10
- def inspect
11
- ivars = instance_variables.map do |e|
12
- [e.to_s.delete('@'), instance_variable_get(e)]
10
+ def to_h
11
+ instance_variables.map do |e|
12
+ [e.to_s.delete('@').to_sym, instance_variable_get(e)]
13
13
  end.to_h
14
- fmtted_email = @email ? " #{@email}" : ''
15
- "#<#{self.class}:0x#{(object_id << 1).to_s(16)}#{fmtted_email}> JSON: " +
16
- JSON.pretty_generate(ivars)
14
+ end
15
+
16
+ alias_method :to_hash, :to_h
17
+
18
+ def to_json
19
+ JSON.generate(to_h)
20
+ end
21
+
22
+ def inspect
23
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)}> JSON: " +
24
+ JSON.pretty_generate(to_h)
17
25
  end
18
26
 
19
27
  end
@@ -11,5 +11,10 @@ module Emailable
11
11
  end
12
12
  end
13
13
 
14
+ def inspect
15
+ "#<#{self.class}:0x#{(object_id << 1).to_s(16)}#{@email}> JSON: " +
16
+ JSON.pretty_generate(to_h)
17
+ end
18
+
14
19
  end
15
20
  end
@@ -1,3 +1,3 @@
1
1
  module Emailable
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
data/lib/emailable.rb CHANGED
@@ -1,4 +1,8 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
1
4
  require 'emailable/version'
5
+ require 'emailable/errors'
2
6
  require 'emailable/client'
3
7
  require 'emailable/response'
4
8
  require 'emailable/batch'
@@ -33,9 +37,7 @@ module Emailable
33
37
  response = client.request(:get, 'verify', opts)
34
38
 
35
39
  if response.status == 249
36
- raise Emailable::TimeoutError.new(
37
- code: response.status, message: response.body
38
- )
40
+ raise Emailable::TimeoutError.new(response.body)
39
41
  else
40
42
  Verification.new(response.body)
41
43
  end
@@ -47,22 +49,4 @@ module Emailable
47
49
  Account.new(response.body)
48
50
  end
49
51
 
50
-
51
- class Error < StandardError
52
- attr_accessor :code, :message
53
-
54
- def initialize(code: nil, message: nil)
55
- @code = code
56
- @message = message
57
- end
58
- end
59
- class BadRequestError < Error; end
60
- class UnauthorizedError < Error; end
61
- class PaymentRequiredError < Error; end
62
- class ForbiddenError < Error; end
63
- class NotFoundError < Error; end
64
- class TooManyRequestsError < Error; end
65
- class InternalServerError < Error; end
66
- class ServiceUnavailableError < Error; end
67
- class TimeoutError < Error; end
68
52
  end
@@ -1,3 +1,4 @@
1
+ require 'active_model'
1
2
  require 'test_helper'
2
3
 
3
4
  class EmailValidatorTest < Minitest::Test
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module Emailable
4
+ module Resources
5
+ class APIResourceTest < Minitest::Test
6
+ class Example < APIResource
7
+ attr_accessor :foo, :bar, :baz
8
+ end
9
+
10
+ def setup
11
+ @e = Example.new(foo: 'abc', bar: 123, baz: true)
12
+ end
13
+
14
+ def test_init
15
+ assert_equal 'abc', @e.foo
16
+ assert_equal 123, @e.bar
17
+ assert_equal true, @e.baz
18
+ end
19
+
20
+ def test_to_h
21
+ correct = {
22
+ foo: 'abc',
23
+ bar: 123,
24
+ baz: true,
25
+ }
26
+ assert_equal correct, @e.to_h
27
+ assert_equal correct, @e.to_hash
28
+ end
29
+
30
+ def test_to_json
31
+ correct = %q|{"foo":"abc","bar":123,"baz":true}|
32
+ assert_equal correct, @e.to_json
33
+ end
34
+
35
+ def test_inspect
36
+ correct = <<~STR.chomp
37
+ #<> JSON: {
38
+ "foo": "abc",
39
+ "bar": 123,
40
+ "baz": true
41
+ }
42
+ STR
43
+ output = @e.inspect.gsub(/<.*>/, '<>')
44
+ assert_equal correct, output
45
+ end
46
+ end
47
+
48
+ end
49
+ end
data/test/test_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
- require 'active_model'
3
1
  require 'emailable'
4
2
 
5
3
  require 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emailable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emailable
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-19 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,6 +134,7 @@ files:
134
134
  - lib/emailable/batch.rb
135
135
  - lib/emailable/client.rb
136
136
  - lib/emailable/email_validator.rb
137
+ - lib/emailable/errors.rb
137
138
  - lib/emailable/resources/account.rb
138
139
  - lib/emailable/resources/api_resource.rb
139
140
  - lib/emailable/resources/batch_status.rb
@@ -142,6 +143,7 @@ files:
142
143
  - lib/emailable/version.rb
143
144
  - test/email_validator_test.rb
144
145
  - test/emailable/batch_test.rb
146
+ - test/emailable/resources/api_resource_test.rb
145
147
  - test/emailable_test.rb
146
148
  - test/test_helper.rb
147
149
  homepage: https://emailable.com
@@ -151,7 +153,7 @@ metadata:
151
153
  bug_tracker_uri: https://github.com/emailable/emailable-ruby/issues
152
154
  documentation_uri: https://docs.emailable.com/?ruby
153
155
  source_code_uri: https://github.com/emailable/emailable-ruby
154
- post_install_message:
156
+ post_install_message:
155
157
  rdoc_options: []
156
158
  require_paths:
157
159
  - lib
@@ -167,11 +169,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
169
  version: '0'
168
170
  requirements: []
169
171
  rubygems_version: 3.1.6
170
- signing_key:
172
+ signing_key:
171
173
  specification_version: 4
172
174
  summary: Ruby bindings for the Emailable API
173
175
  test_files:
174
176
  - test/email_validator_test.rb
175
177
  - test/emailable/batch_test.rb
178
+ - test/emailable/resources/api_resource_test.rb
176
179
  - test/emailable_test.rb
177
180
  - test/test_helper.rb