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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/engiven/client.rb +2 -1
- data/lib/engiven/error.rb +53 -0
- data/lib/engiven/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b9e3277613debfa55ed4ced861d24b44e36c54da384a11cecc6bfd4f13ea0bd
|
4
|
+
data.tar.gz: f805afb52aa0f1731b1c77f1cc01a9cf64a5828199d3ec9a0e446fdfc39c09b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62e78ee012a327d752f2d0ac6700ed7e7e2cb0d71d2caee3c03764b7414d94e015c6fea638707df3751724513ebaf16e3012cdcb22289230a4f8110651d2dabc
|
7
|
+
data.tar.gz: 01ceb9224a3e2122f923949f23ce7a027feb9c280c44323b60b9c5f52ce3e14cdaf5201473ba68c5387ae8eb8082596d7b17d81c205c2494314e6b61fd544699
|
data/Gemfile.lock
CHANGED
data/lib/engiven/client.rb
CHANGED
@@ -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 :
|
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)
|
data/lib/engiven/version.rb
CHANGED
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.
|
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
|