zaikio-client-helpers 0.1.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/zaikio/client/helpers/json_parser.rb +12 -6
- data/lib/zaikio/client/helpers/pagination.rb +6 -2
- data/lib/zaikio/client/helpers/version.rb +1 -1
- data/lib/zaikio/error.rb +31 -0
- data/lib/zaikio-client-helpers.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 429b80bf8b9d429a9cebbf05e6621a37d891d5cedb9c12f92cdf87f8902006da
|
4
|
+
data.tar.gz: 448b5a7fe652b0c2cc540da2f8f33b1f689c3f29f16401e0828787cd72385108
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb55ed4c40c35ae902df31aa4cc0a5e2600f9c48dfac43e50acde69f5af1ae1c76e46d3b94c5deb1205638ac30ca040b500c6dc9e16789dfd69e1d55ec6ac4f7
|
7
|
+
data.tar.gz: 0caa6bd56a7716321d8fb99b7b53132c23b0d83d7843e832b3c5cd557d86e9db249e3d6f6c41ec91b786a822e6a154a34c52d0d957deba26b2052e4065e7da06
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.3] - 2021-11-12
|
4
|
+
|
5
|
+
- Handle "uncountable" responses (i.e. those without a Total-Count or Total-Pages header)
|
6
|
+
|
7
|
+
## [0.2.2] - 2021-08-12
|
8
|
+
|
9
|
+
- Attempt to fix `NoMethodError` when looking for pagination headers
|
10
|
+
|
11
|
+
## [0.2.1] - 2021-08-05
|
12
|
+
|
13
|
+
- Fixed `with_fallback` from spyke by aliasing the correct error classes
|
14
|
+
|
15
|
+
## [0.2.0] - 2021-07-22
|
16
|
+
|
17
|
+
- Add `Zaikio:Error` and allow setting arbitrary attributes on the exceptions
|
18
|
+
- Add `Zaikio::RateLimitedError` when HTTP 429 occurs (note that this subclasses
|
19
|
+
`Zaikio::ConnectionError` so all existing error handling should continue to work).
|
20
|
+
|
3
21
|
## [0.1.1] - 2021-06-18
|
4
22
|
|
5
23
|
- Require `zaikio/client/model` as part of gem loading to avoid need to load it elsewhere
|
@@ -4,15 +4,21 @@ require "multi_json"
|
|
4
4
|
module Zaikio::Client::Helpers
|
5
5
|
class JSONParser < Faraday::Response::Middleware
|
6
6
|
def on_complete(env)
|
7
|
-
|
8
|
-
|
9
|
-
raise
|
10
|
-
|
11
|
-
|
7
|
+
case env.status
|
8
|
+
when 404 then raise Spyke::ResourceNotFound.new(nil, url: env.url)
|
9
|
+
when 429 then raise Zaikio::RateLimitedError.new(nil, url: env.url)
|
10
|
+
when (200..299), 422 then env.body = parse_body(env.body)
|
11
|
+
else connection_error(env)
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
15
|
def connection_error(env)
|
15
|
-
raise Spyke::ConnectionError
|
16
|
+
raise Spyke::ConnectionError.new(
|
17
|
+
"Status: #{env.status}, URL: #{env.url}, body: #{env.body}",
|
18
|
+
status: env.status,
|
19
|
+
url: env.url,
|
20
|
+
body: env.body
|
21
|
+
)
|
16
22
|
end
|
17
23
|
|
18
24
|
def parse_body(body)
|
@@ -63,7 +63,7 @@ module Zaikio::Client::Helpers
|
|
63
63
|
class Relation < Spyke::Relation
|
64
64
|
HEADERS.each_key do |symbol|
|
65
65
|
define_method(symbol) do
|
66
|
-
find_some.metadata
|
66
|
+
find_some.metadata.dig(METADATA_KEY, symbol)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
@@ -76,7 +76,11 @@ module Zaikio::Client::Helpers
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def last_page?
|
79
|
-
|
79
|
+
if total_pages.nil?
|
80
|
+
find_some.empty?
|
81
|
+
else
|
82
|
+
current_page >= total_pages
|
83
|
+
end
|
80
84
|
end
|
81
85
|
|
82
86
|
def supports_pagination?
|
data/lib/zaikio/error.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Zaikio
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(message = nil, **opts)
|
4
|
+
super(message)
|
5
|
+
|
6
|
+
opts.each do |key, value|
|
7
|
+
ivar = "@#{key}".to_sym
|
8
|
+
instance_variable_set(ivar, value)
|
9
|
+
define_singleton_method(key) { instance_variable_get(ivar) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ResourceNotFound < Zaikio::Error; end
|
15
|
+
|
16
|
+
class ConnectionError < Zaikio::Error; end
|
17
|
+
class RateLimitedError < ConnectionError; end
|
18
|
+
end
|
19
|
+
|
20
|
+
require "spyke"
|
21
|
+
|
22
|
+
module Spyke
|
23
|
+
instance_eval do
|
24
|
+
# avoid warning: already initialized constant
|
25
|
+
remove_const("ConnectionError")
|
26
|
+
remove_const("ResourceNotFound")
|
27
|
+
end
|
28
|
+
|
29
|
+
ConnectionError = Zaikio::ConnectionError
|
30
|
+
ResourceNotFound = Zaikio::ResourceNotFound
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-client-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio GMBH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/zaikio/client/helpers/pagination.rb
|
97
97
|
- lib/zaikio/client/helpers/version.rb
|
98
98
|
- lib/zaikio/client/model.rb
|
99
|
+
- lib/zaikio/error.rb
|
99
100
|
homepage: https://github.com/zaikio/zaikio-client-helpers
|
100
101
|
licenses:
|
101
102
|
- MIT
|
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
112
|
requirements:
|
112
113
|
- - ">="
|
113
114
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
115
|
+
version: '2.3'
|
115
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
117
|
requirements:
|
117
118
|
- - ">="
|