engiven 0.0.2 → 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: bb7adc6ec86850c83673eefb610012cee329626a2eba1a1c79a92eb0c2bb2f02
4
- data.tar.gz: 183e4e3cc7c8caab916c2d5193c1a833dcd2a904ee554767ec320751979ad949
3
+ metadata.gz: 5b9e3277613debfa55ed4ced861d24b44e36c54da384a11cecc6bfd4f13ea0bd
4
+ data.tar.gz: f805afb52aa0f1731b1c77f1cc01a9cf64a5828199d3ec9a0e446fdfc39c09b6
5
5
  SHA512:
6
- metadata.gz: 69f983599823ed2b7c7d6fff4b45be97ed4690c8168f22e8b159f8b0a475da5cb535531ed270bf107e266352675d90bad6143e9ff55a9c42cdd40e0a38e9cedd
7
- data.tar.gz: 0f78a164376393256a0110755e56723bbe65fa6f56eaac595b3bcb5da7067878162179aa809de752506f8c0a053a277eca40d515205744c7b412b6df533e59d9
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 (0.0.2)
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,6 +60,7 @@ module EngivenAPI
59
60
  Faraday.new(client_opts) do |conn|
60
61
  conn.request :json
61
62
  conn.response :logger if logger
63
+ conn.response :engiven_error_handler
62
64
  conn.response :json
63
65
  conn.adapter adapter
64
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 = '0.0.2'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: engiven
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-11 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -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