engiven 1.0.0 → 1.1.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: b1974f9e73ae8733db7ae786b1e7f0a660a1508c501320b9cf9ea1e3fa04a5cb
4
- data.tar.gz: 5b5dea418a5fc58e4247859122e45b983558dc793a5fe752fc6927a8bdce1ab6
3
+ metadata.gz: 5b9e3277613debfa55ed4ced861d24b44e36c54da384a11cecc6bfd4f13ea0bd
4
+ data.tar.gz: f805afb52aa0f1731b1c77f1cc01a9cf64a5828199d3ec9a0e446fdfc39c09b6
5
5
  SHA512:
6
- metadata.gz: fe1dd4818224b8aeba00186477eea259a5e482ca39f466bba6ee52a0014620cebf0e0809d9523412633a67cd46b27a15bbdadd74033acab7dce46fccc96f603b
7
- data.tar.gz: 0dc4a0080d87192d1f6526f8faa1ef47647ce0918e9c11a61627d0205ab3b82a367e025cda964a2c13ff68f814655d95d887605bf4fdd8330afadbb2befe4176
6
+ metadata.gz: 62e78ee012a327d752f2d0ac6700ed7e7e2cb0d71d2caee3c03764b7414d94e015c6fea638707df3751724513ebaf16e3012cdcb22289230a4f8110651d2dabc
7
+ data.tar.gz: 01ceb9224a3e2122f923949f23ce7a027feb9c280c44323b60b9c5f52ce3e14cdaf5201473ba68c5387ae8eb8082596d7b17d81c205c2494314e6b61fd544699
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- engiven (1.0.0)
4
+ engiven (1.1.0)
5
5
  faraday
6
6
  json
7
7
 
@@ -1,6 +1,7 @@
1
1
  require 'faraday'
2
2
 
3
3
  require 'engiven/version'
4
+ require 'engiven/error'
4
5
  require 'engiven/resources/customer'
5
6
  require 'engiven/resources/fund'
6
7
  require 'engiven/resources/gift'
@@ -59,7 +60,7 @@ module EngivenAPI
59
60
  Faraday.new(client_opts) do |conn|
60
61
  conn.request :json
61
62
  conn.response :logger if logger
62
- conn.response :raise_error
63
+ conn.response :engiven_error_handler
63
64
  conn.response :json
64
65
  conn.adapter adapter
65
66
  end
@@ -0,0 +1,53 @@
1
+ module EngivenAPI
2
+ class Error < StandardError; end
3
+ class BadGateway < Error; end
4
+ class BadRequest < Error; end
5
+ class CloudflareError < Error; end
6
+ class Forbidden < Error; end
7
+ class GatewayTimeout < Error; end
8
+ class InternalServerError < Error; end
9
+ class NotFound < Error; end
10
+ class ServiceUnavailable < Error; end
11
+ class Unauthorized < Error; end
12
+ end
13
+
14
+ module Faraday
15
+ class Response
16
+ class EngivenErrorMiddleware < Middleware
17
+ ERROR_STATUSES = 400..600
18
+ def on_complete(env)
19
+ case env[:status]
20
+ when 400
21
+ raise EngivenAPI::BadRequest, error_message(env)
22
+ when 401
23
+ raise EngivenAPI::Unauthorized, error_message(env)
24
+ when 403
25
+ raise EngivenAPI::Forbidden, error_message(env)
26
+ when 404
27
+ raise EngivenAPI::NotFound, error_message(env)
28
+ when 500
29
+ raise EngivenAPI::InternalServerError, error_message(env)
30
+ when 502
31
+ raise EngivenAPI::BadGateway, error_message(env)
32
+ when 503
33
+ raise EngivenAPI::ServiceUnavailable, error_message(env)
34
+ when 504
35
+ raise EngivenAPI::GatewayTimeout, error_message(env)
36
+ when 520
37
+ raise EngivenAPI::CloudflareError, error_message(env)
38
+ when ERROR_STATUSES
39
+ raise EngivenAPI::Error, error_message(env)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def error_message(env)
46
+ "#{env[:status]}: #{env[:url]} #{env[:body]}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+
53
+ Faraday::Response.register_middleware(engiven_error_handler: Faraday::Response::EngivenErrorMiddleware)
@@ -1,3 +1,3 @@
1
1
  module EngivenAPI
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engiven
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
@@ -83,6 +83,7 @@ files:
83
83
  - engiven.gemspec
84
84
  - lib/engiven.rb
85
85
  - lib/engiven/client.rb
86
+ - lib/engiven/error.rb
86
87
  - lib/engiven/resources/customer.rb
87
88
  - lib/engiven/resources/fund.rb
88
89
  - lib/engiven/resources/gift.rb