zaikio-client-helpers 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/zaikio/client/helpers/configuration.rb +1 -1
- data/lib/zaikio/client/helpers/json_parser.rb +5 -3
- data/lib/zaikio/client/helpers/locale_middleware.rb +22 -0
- data/lib/zaikio/client/helpers/version.rb +1 -1
- data/lib/zaikio/client.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf5ba26a5d902d8754f9f415013df733258fec880ef3957ea9c6f24b9ca4a7f
|
4
|
+
data.tar.gz: e6a0e15a3d85f1817a2ae1c6020d5d7b37a616f86b527f7d7e3410e6f8d9da34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4f46bc71a87c569cc796f3c3174f431cd27f75514122c831b85a31db46068e5296cb345091ab7a88d0dd63bda4cd9d69b130472a6dbe1356f50dbe3a7017acd
|
7
|
+
data.tar.gz: 723a060aa1807cd9e78e272daaead50b6d556f7f209801067fbec01481416440fedf4711929b6660563e77335757c61a0d2b937d820d74175c425c0b62da9062
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.6.0] - 2023-03-20
|
2
|
+
|
3
|
+
- Remove errors from data hash
|
4
|
+
- Do include base error if server responds with a 422 to see that an error happened
|
5
|
+
|
6
|
+
## [0.5.0] - 2023-03-17
|
7
|
+
|
8
|
+
- Add new faraday middleware that automatically passes current `I18n.locale` to `Accept-Language` header
|
9
|
+
|
1
10
|
## [0.4.0] - 2023-02-09
|
2
11
|
|
3
12
|
- Add a default read timeout for Faraday connection of 5 seconds, and open timeout of 1 second.
|
@@ -13,7 +13,7 @@ module Zaikio::Client::Helpers
|
|
13
13
|
case env.status
|
14
14
|
when 404 then raise Spyke::ResourceNotFound.new(nil, url: env.url)
|
15
15
|
when 429 then raise Zaikio::RateLimitedError.new(nil, url: env.url)
|
16
|
-
when (200..299), 422 then env.body = parse_body(env.body)
|
16
|
+
when (200..299), 422 then env.body = parse_body(env.body, status: env.status)
|
17
17
|
else connection_error(env)
|
18
18
|
end
|
19
19
|
end
|
@@ -27,12 +27,14 @@ module Zaikio::Client::Helpers
|
|
27
27
|
)
|
28
28
|
end
|
29
29
|
|
30
|
-
def parse_body(body)
|
30
|
+
def parse_body(body, status: 200)
|
31
31
|
json = MultiJson.load(body, symbolize_keys: true)
|
32
|
+
errors = json.is_a?(Hash) ? json.delete(:errors) || {} : {}
|
33
|
+
errors = { base: ['unknown'] } if status == 422 && errors.empty?
|
32
34
|
{
|
33
35
|
data: json,
|
34
36
|
metadata: {},
|
35
|
-
errors:
|
37
|
+
errors: errors
|
36
38
|
}
|
37
39
|
rescue MultiJson::ParseError
|
38
40
|
{
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
module Zaikio
|
4
|
+
module Client
|
5
|
+
module Helpers
|
6
|
+
class LocaleMiddleware < Faraday::Middleware
|
7
|
+
def initialize(app, disable_i18n: false)
|
8
|
+
@disable_i18n = disable_i18n
|
9
|
+
super(app)
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(request_env)
|
13
|
+
if !@disable_i18n && Object.const_defined?("I18n")
|
14
|
+
request_env[:request_headers]["Accept-Language"] = ::I18n.try(:locale)&.to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
@app.call(request_env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/zaikio/client.rb
CHANGED
@@ -3,6 +3,7 @@ require "zaikio/client/helpers/json_parser"
|
|
3
3
|
require "zaikio/client/helpers/pagination"
|
4
4
|
require "zaikio/client/helpers/configuration"
|
5
5
|
require "zaikio/client/helpers/authorization_middleware"
|
6
|
+
require "zaikio/client/helpers/locale_middleware"
|
6
7
|
|
7
8
|
module Zaikio
|
8
9
|
module Client
|
@@ -25,6 +26,7 @@ module Zaikio
|
|
25
26
|
c.use Zaikio::Client::Helpers::Pagination::FaradayMiddleware
|
26
27
|
c.use Zaikio::Client::Helpers::JSONParser
|
27
28
|
c.use Zaikio::Client::Helpers::AuthorizationMiddleware
|
29
|
+
c.use Zaikio::Client::Helpers::LocaleMiddleware, disable_i18n: configuration.disable_i18n
|
28
30
|
c.adapter Faraday.default_adapter
|
29
31
|
end
|
30
32
|
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zaikio GMBH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/zaikio/client/helpers/authorization_middleware.rb
|
103
103
|
- lib/zaikio/client/helpers/configuration.rb
|
104
104
|
- lib/zaikio/client/helpers/json_parser.rb
|
105
|
+
- lib/zaikio/client/helpers/locale_middleware.rb
|
105
106
|
- lib/zaikio/client/helpers/pagination.rb
|
106
107
|
- lib/zaikio/client/helpers/version.rb
|
107
108
|
- lib/zaikio/client/model.rb
|