my_api_client 0.9.0 → 0.9.1
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 +6 -0
- data/Gemfile.lock +1 -1
- data/README.jp.md +2 -2
- data/lib/my_api_client/error_handling.rb +4 -6
- data/lib/my_api_client/error_handling/generator.rb +5 -6
- data/lib/my_api_client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a388b02739580f3208f34dc4e56f852f028a6acf2fce08abb3d6689bb3809b3
|
4
|
+
data.tar.gz: cdce875732354336fef4208b48616c9380d8f698865a0fc9a7d893a6f36a2064
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b85475c4e54fe188d7669ad06bbaae159bfef53a89ddbbc6ec3132a8286b8b9e8564d421b7c7e024de2b5f09d888b3ed736c0a98b6f9d12bbaa99e837cd97e8c
|
7
|
+
data.tar.gz: a97decaa49de365e30c9ed0d2a99a9cc290de61f581be5219fd85cbc4931b6267ee5253d000a3c43e664df6e3056e1376708a9e51762ea0b37eb117ef2798be6
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.jp.md
CHANGED
@@ -190,10 +190,10 @@ error_handling json: { '$.errors.code': :negative? }
|
|
190
190
|
#### forbid_nil
|
191
191
|
|
192
192
|
```ruby
|
193
|
-
error_handling status_code: 200,
|
193
|
+
error_handling status_code: 200, json: :forbid_nil
|
194
194
|
```
|
195
195
|
|
196
|
-
一部のサービスではサーバーから何らかの Response Body が返ってくる事を期待しているにも関わらず、空の結果が結果が返ってくるというケースがあるようです。こちらも実験的な機能ですが、そういったケースを検出するために `forbid_nil` オプションを用意しました。通常の場合、Response Body
|
196
|
+
一部のサービスではサーバーから何らかの Response Body が返ってくる事を期待しているにも関わらず、空の結果が結果が返ってくるというケースがあるようです。こちらも実験的な機能ですが、そういったケースを検出するために `json: :forbid_nil` オプションを用意しました。通常の場合、Response Body が空の場合はエラー判定をしませんが、このオプションを指定するとエラーとして検知する様になります。正常応答が空となる API も存在するので、誤検知にご注意下さい。
|
197
197
|
|
198
198
|
#### MyApiClient::Params::Params
|
199
199
|
|
@@ -7,7 +7,7 @@ module MyApiClient
|
|
7
7
|
# You need to define `class_attribute: error_handler, default: []` for the
|
8
8
|
# included class.
|
9
9
|
# @example
|
10
|
-
# error_handling status_code: 200,
|
10
|
+
# error_handling status_code: 200, json: :forbid_nil
|
11
11
|
# error_handling status_code: 400..499, raise: MyApiClient::ClientError
|
12
12
|
# error_handling status_code: 500..599 do |params, logger|
|
13
13
|
# logger.warn 'Server error occurred.'
|
@@ -28,10 +28,9 @@ module MyApiClient
|
|
28
28
|
# Options for this generator
|
29
29
|
# @option status_code [String, Range, Integer, Regexp]
|
30
30
|
# Verifies response HTTP status code and raises error if matched
|
31
|
-
# @option json [Hash]
|
32
|
-
# Verifies response body as JSON and raises error if matched
|
33
|
-
#
|
34
|
-
# Verifies response_body and raises error if it is `nil`. default: false.
|
31
|
+
# @option json [Hash, Symbol]
|
32
|
+
# Verifies response body as JSON and raises error if matched.
|
33
|
+
# If specified `:forbid_nil`, it forbid `nil` on response_body.
|
35
34
|
# @option with [Symbol]
|
36
35
|
# Calls specified method when error detected
|
37
36
|
# @option raise [MyApiClient::Error]
|
@@ -39,7 +38,6 @@ module MyApiClient
|
|
39
38
|
# @yield [MyApiClient::Params::Params, MyApiClient::Logger]
|
40
39
|
# Executes the block when error detected
|
41
40
|
def error_handling(**options, &block)
|
42
|
-
options[:forbid_nil] ||= false
|
43
41
|
options[:raise] ||= MyApiClient::Error
|
44
42
|
options[:block] = block if block_given?
|
45
43
|
|
@@ -12,10 +12,9 @@ module MyApiClient
|
|
12
12
|
# The target of verifying
|
13
13
|
# @option status_code [String, Range, Integer, Regexp]
|
14
14
|
# Verifies response HTTP status code and raises error if matched
|
15
|
-
# @option json [Hash]
|
16
|
-
# Verifies response body as JSON and raises error if matched
|
17
|
-
#
|
18
|
-
# Verifies response_body and raises error if it is `nil`
|
15
|
+
# @option json [Hash, Symbol]
|
16
|
+
# Verifies response body as JSON and raises error if matched.
|
17
|
+
# If specified `:forbid_nil`, it forbid `nil` on response_body.
|
19
18
|
# @option with [Symbol]
|
20
19
|
# Calls specified method when error detected
|
21
20
|
# @option raise [MyApiClient::Error]
|
@@ -32,7 +31,7 @@ module MyApiClient
|
|
32
31
|
|
33
32
|
private
|
34
33
|
|
35
|
-
attr_reader :_response, :_status_code, :_json, :
|
34
|
+
attr_reader :_response, :_status_code, :_json, :_with, :_raise, :_block
|
36
35
|
|
37
36
|
def initialize(**options)
|
38
37
|
options.each { |k, v| instance_variable_set("@_#{k}", v) }
|
@@ -72,7 +71,7 @@ module MyApiClient
|
|
72
71
|
|
73
72
|
def match_all?(json, response_body)
|
74
73
|
return true if json.nil?
|
75
|
-
return
|
74
|
+
return response_body.nil? if json == :forbid_nil
|
76
75
|
return false if response_body.blank?
|
77
76
|
|
78
77
|
json.all? do |path, operator|
|