my_api_client 0.23.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +5 -23
- data/.rubocop.yml +8 -0
- data/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +45 -0
- data/Gemfile.lock +53 -45
- data/README.jp.md +17 -2
- data/README.md +22 -3
- data/example/api_clients/my_errors.rb +9 -0
- data/example/api_clients/my_header_api_client.rb +38 -0
- data/lib/my_api_client/error_handling/generator.rb +16 -3
- data/lib/my_api_client/rspec/stub.rb +1 -1
- data/lib/my_api_client/version.rb +1 -1
- data/my_api/Gemfile +2 -2
- data/my_api/Gemfile.lock +110 -96
- data/my_api/app/controllers/header_controller.rb +12 -0
- data/my_api/config/routes.rb +1 -0
- data/my_api/spec/controllers/error_controller_spec.rb +1 -1
- data/my_api/spec/controllers/header_controller_spec.rb +33 -0
- data/my_api/spec/controllers/pagination_controller_spec.rb +1 -1
- data/my_api/spec/controllers/rest_controller_spec.rb +1 -1
- data/my_api/spec/controllers/status_controller_spec.rb +1 -1
- data/my_api_client.gemspec +3 -2
- data/rails_app/rails_6.0/Gemfile.lock +21 -21
- data/rails_app/rails_6.1/Gemfile.lock +21 -21
- data/rails_app/rails_7.0/Gemfile.lock +20 -20
- metadata +24 -43
- data/gemfiles/rails_5.0.gemfile +0 -16
- data/gemfiles/rails_5.1.gemfile +0 -16
- data/gemfiles/rails_5.2.gemfile +0 -16
- data/rails_app/rails_5.2/.rspec +0 -3
- data/rails_app/rails_5.2/Gemfile +0 -17
- data/rails_app/rails_5.2/Gemfile.lock +0 -180
- data/rails_app/rails_5.2/README.md +0 -24
- data/rails_app/rails_5.2/Rakefile +0 -8
- data/rails_app/rails_5.2/app/controllers/application_controller.rb +0 -4
- data/rails_app/rails_5.2/app/jobs/application_job.rb +0 -4
- data/rails_app/rails_5.2/bin/bundle +0 -5
- data/rails_app/rails_5.2/bin/rails +0 -6
- data/rails_app/rails_5.2/bin/rake +0 -6
- data/rails_app/rails_5.2/bin/setup +0 -27
- data/rails_app/rails_5.2/bin/update +0 -27
- data/rails_app/rails_5.2/config/application.rb +0 -37
- data/rails_app/rails_5.2/config/boot.rb +0 -6
- data/rails_app/rails_5.2/config/credentials.yml.enc +0 -1
- data/rails_app/rails_5.2/config/environment.rb +0 -7
- data/rails_app/rails_5.2/config/environments/development.rb +0 -41
- data/rails_app/rails_5.2/config/environments/production.rb +0 -70
- data/rails_app/rails_5.2/config/environments/test.rb +0 -38
- data/rails_app/rails_5.2/config/initializers/application_controller_renderer.rb +0 -9
- data/rails_app/rails_5.2/config/initializers/backtrace_silencers.rb +0 -8
- data/rails_app/rails_5.2/config/initializers/cors.rb +0 -17
- data/rails_app/rails_5.2/config/initializers/filter_parameter_logging.rb +0 -6
- data/rails_app/rails_5.2/config/initializers/inflections.rb +0 -17
- data/rails_app/rails_5.2/config/initializers/mime_types.rb +0 -5
- data/rails_app/rails_5.2/config/initializers/wrap_parameters.rb +0 -11
- data/rails_app/rails_5.2/config/locales/en.yml +0 -33
- data/rails_app/rails_5.2/config/routes.rb +0 -5
- data/rails_app/rails_5.2/config/spring.rb +0 -8
- data/rails_app/rails_5.2/config.ru +0 -7
- data/rails_app/rails_5.2/public/robots.txt +0 -1
- data/rails_app/rails_5.2/spec/rails_helper.rb +0 -14
- data/rails_app/rails_5.2/spec/spec_helper.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6c284685be8f55566beede15458b1a37dc948b09ce05bc264f23187fc266478
|
4
|
+
data.tar.gz: 3cc7d5acf9b8d53fde96270b6ef63baca986ba459f819ad53c11d71744004049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36ae22feafaddcab8f70f1c755c89d6cacd2bced91fe04c373c56d1e45c157c5c64188de9b1edd2f43eaa9ab1a50339e8c19ec94bd6a67802f83e28d6deb5228
|
7
|
+
data.tar.gz: 980a73834aa0c2e5b0c95d111b19466c8918a8ab5e43fdfefc46f7e4e4bc033b206dca290cfb0c9d5122ff9d6e4fa02b441c180150ccc4e05b4cbb26cc4c3546
|
data/.circleci/config.yml
CHANGED
@@ -12,12 +12,12 @@ references:
|
|
12
12
|
- &ruby_version
|
13
13
|
ruby_version:
|
14
14
|
type: enum
|
15
|
-
enum: &ruby_version_enum ["2.7", "3.0", "3.1"]
|
16
|
-
default: "3.
|
15
|
+
enum: &ruby_version_enum ["2.7", "3.0", "3.1", "3.2"]
|
16
|
+
default: "3.2"
|
17
17
|
- &rails_version
|
18
18
|
rails_version:
|
19
19
|
type: enum
|
20
|
-
enum: &rails_version_enum ["
|
20
|
+
enum: &rails_version_enum ["6.0", "6.1", "7.0"]
|
21
21
|
default: "7.0"
|
22
22
|
- &bundler_options
|
23
23
|
bundler_options:
|
@@ -153,7 +153,7 @@ commands:
|
|
153
153
|
name: Install Bundler 2.x
|
154
154
|
command: gem install bundler -v '~> 2.0'
|
155
155
|
- ruby-orbs/bundle-install:
|
156
|
-
cache_key_prefix:
|
156
|
+
cache_key_prefix: v2-dependencies-<< parameters.ruby_version >>
|
157
157
|
bundle_extra_args: << parameters.bundler_options >>
|
158
158
|
restore_bundled_with: false
|
159
159
|
test_and_deploy_for_api:
|
@@ -252,7 +252,7 @@ jobs:
|
|
252
252
|
- code-climate/install
|
253
253
|
- code-climate/sum-coverage:
|
254
254
|
input: codeclimate.*.json
|
255
|
-
parts:
|
255
|
+
parts: 24
|
256
256
|
- code-climate/upload-coverage
|
257
257
|
rubocop:
|
258
258
|
executor: gem_executor
|
@@ -287,30 +287,12 @@ workflows:
|
|
287
287
|
ruby_version: *ruby_version_enum
|
288
288
|
rails_version: *rails_version_enum
|
289
289
|
bundler_options: ["--with integrations", "--without integrations"]
|
290
|
-
exclude:
|
291
|
-
- ruby_version: "3.0"
|
292
|
-
rails_version: "5.2"
|
293
|
-
bundler_options: "--with integrations"
|
294
|
-
- ruby_version: "3.0"
|
295
|
-
rails_version: "5.2"
|
296
|
-
bundler_options: "--without integrations"
|
297
|
-
- ruby_version: "3.1"
|
298
|
-
rails_version: "5.2"
|
299
|
-
bundler_options: "--with integrations"
|
300
|
-
- ruby_version: "3.1"
|
301
|
-
rails_version: "5.2"
|
302
|
-
bundler_options: "--without integrations"
|
303
290
|
- verify_generator:
|
304
291
|
name: verify_generator_on_ruby_<< matrix.ruby_version >>_and_rails_<< matrix.rails_version >>
|
305
292
|
matrix:
|
306
293
|
parameters:
|
307
294
|
ruby_version: *ruby_version_enum
|
308
295
|
rails_version: *rails_version_enum
|
309
|
-
exclude:
|
310
|
-
- ruby_version: "3.0"
|
311
|
-
rails_version: "5.2"
|
312
|
-
- ruby_version: "3.1"
|
313
|
-
rails_version: "5.2"
|
314
296
|
- test_api:
|
315
297
|
ruby_version: "2.7" # Jets supports only Ruby 2.x
|
316
298
|
- rubocop
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-performance
|
3
|
+
- rubocop-rake
|
3
4
|
- rubocop-rspec
|
4
5
|
|
5
6
|
inherit_from: .rubocop_todo.yml
|
@@ -11,6 +12,9 @@ AllCops:
|
|
11
12
|
- rails_app/**/*
|
12
13
|
- vendor/bundle/**/*
|
13
14
|
|
15
|
+
Gemspec/DevelopmentDependencies:
|
16
|
+
Enabled: false
|
17
|
+
|
14
18
|
Layout/LineLength:
|
15
19
|
Max: 100
|
16
20
|
Exclude:
|
@@ -56,3 +60,7 @@ RSpec/NestedGroups:
|
|
56
60
|
|
57
61
|
RSpec/MultipleExpectations:
|
58
62
|
Max: 4
|
63
|
+
|
64
|
+
RSpec/Rails/HaveHttpStatus:
|
65
|
+
Exclude:
|
66
|
+
- "my_api/spec/controllers/**/*"
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2023-02-06 23:31:23 UTC using RuboCop version 1.41.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -32,7 +32,7 @@ Naming/VariableNumber:
|
|
32
32
|
- 'spec/lib/my_api_client/error_handling_spec.rb'
|
33
33
|
- 'spec/lib/my_api_client/request/executor_spec.rb'
|
34
34
|
|
35
|
-
# Offense count:
|
35
|
+
# Offense count: 101
|
36
36
|
# Configuration parameters: AllowSubject.
|
37
37
|
RSpec/MultipleMemoizedHelpers:
|
38
38
|
Max: 15
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,50 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## v0.25.0 (Feb 12, 2023)
|
4
|
+
|
5
|
+
### Breaking Change
|
6
|
+
|
7
|
+
- [#864](https://github.com/ryz310/my_api_client/pull/864) Support Ruby 3.2 and drop support for Rails 5.2 ([@ryz310](https://github.com/ryz310))
|
8
|
+
|
9
|
+
### Rubocop Challenge
|
10
|
+
|
11
|
+
- [#809](https://github.com/ryz310/my_api_client/pull/809) Style/RedundantConstantBase-20221208233100 ([@ryz310](https://github.com/ryz310))
|
12
|
+
- [#812](https://github.com/ryz310/my_api_client/pull/812) Lint/RedundantCopDisableDirective-20221211233112 ([@ryz310](https://github.com/ryz310))
|
13
|
+
- [#862](https://github.com/ryz310/my_api_client/pull/862) Performance/StringInclude-20230206233100 ([@ryz310](https://github.com/ryz310))
|
14
|
+
|
15
|
+
### Dependabot
|
16
|
+
|
17
|
+
- [#830](https://github.com/ryz310/my_api_client/pull/830) ryz310/dependabot/bundler/simplecov-0.22.0 ([@ryz310](https://github.com/ryz310))
|
18
|
+
- [#858](https://github.com/ryz310/my_api_client/pull/858) Bump faraday from 2.7.3 to 2.7.4 ([@ryz310](https://github.com/ryz310))
|
19
|
+
- [#859](https://github.com/ryz310/my_api_client/pull/859) Bump activesupport from 7.0.4.1 to 7.0.4.2 ([@ryz310](https://github.com/ryz310))
|
20
|
+
- [#863](https://github.com/ryz310/my_api_client/pull/863) Bump bugsnag from 6.25.1 to 6.25.2 ([@ryz310](https://github.com/ryz310))
|
21
|
+
|
22
|
+
## v0.24.0 (Nov 07, 2022)
|
23
|
+
|
24
|
+
### Feature
|
25
|
+
|
26
|
+
- [#792](https://github.com/ryz310/my_api_client/pull/792) Support response header error handling ([@okumud](https://github.com/okumud))
|
27
|
+
|
28
|
+
### Rubocop Challenge
|
29
|
+
|
30
|
+
- [#757](https://github.com/ryz310/my_api_client/pull/757) RSpec/Rails/HaveHttpStatus-20220712233101 ([@ryz310](https://github.com/ryz310))
|
31
|
+
- [#777](https://github.com/ryz310/my_api_client/pull/777) RSpec/ClassCheck-20220912233101 ([@ryz310](https://github.com/ryz310))
|
32
|
+
- [#790](https://github.com/ryz310/my_api_client/pull/790) RSpec/Rails/InferredSpecType-20221023233100 ([@ryz310](https://github.com/ryz310))
|
33
|
+
|
34
|
+
### Dependabot
|
35
|
+
|
36
|
+
- [#758](https://github.com/ryz310/my_api_client/pull/758) ryz310/dependabot/bundler/rubocop-performance-1.14.3 ([@ryz310](https://github.com/ryz310))
|
37
|
+
- [#772](https://github.com/ryz310/my_api_client/pull/772) Bump pry-byebug from 3.10.0 to 3.10.1 ([@ryz310](https://github.com/ryz310))
|
38
|
+
- [#773](https://github.com/ryz310/my_api_client/pull/773) Bump webmock from 3.17.1 to 3.18.1 ([@ryz310](https://github.com/ryz310))
|
39
|
+
- [#775](https://github.com/ryz310/my_api_client/pull/775) Bump activesupport from 7.0.3.1 to 7.0.4 ([@ryz310](https://github.com/ryz310))
|
40
|
+
- [#778](https://github.com/ryz310/my_api_client/pull/778) Bump rspec_junit_formatter from 0.5.1 to 0.6.0 ([@ryz310](https://github.com/ryz310))
|
41
|
+
- [#780](https://github.com/ryz310/my_api_client/pull/780) Bump faraday from 2.5.2 to 2.6.0 ([@ryz310](https://github.com/ryz310))
|
42
|
+
- [#791](https://github.com/ryz310/my_api_client/pull/791) Bump rspec from 3.11.0 to 3.12.0 ([@ryz310](https://github.com/ryz310))
|
43
|
+
|
44
|
+
### Misc
|
45
|
+
|
46
|
+
- [#784](https://github.com/ryz310/my_api_client/pull/784) Pin the version of the jets gem ([@ryz310](https://github.com/ryz310))
|
47
|
+
|
3
48
|
## v0.23.0 (Jun 08, 2022)
|
4
49
|
|
5
50
|
### Feature
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
my_api_client (0.
|
5
|
-
activesupport (>=
|
4
|
+
my_api_client (0.25.0)
|
5
|
+
activesupport (>= 6.0.0)
|
6
6
|
faraday (>= 0.17.1)
|
7
7
|
jsonpath
|
8
8
|
sawyer (>= 0.8.2)
|
@@ -10,95 +10,102 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (7.0.
|
13
|
+
activesupport (7.0.4.2)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 1.6, < 2)
|
16
16
|
minitest (>= 5.1)
|
17
17
|
tzinfo (~> 2.0)
|
18
|
-
addressable (2.8.
|
19
|
-
public_suffix (>= 2.0.2, <
|
18
|
+
addressable (2.8.1)
|
19
|
+
public_suffix (>= 2.0.2, < 6.0)
|
20
20
|
ast (2.4.2)
|
21
|
-
bugsnag (6.
|
21
|
+
bugsnag (6.25.2)
|
22
22
|
concurrent-ruby (~> 1.0)
|
23
23
|
byebug (11.1.3)
|
24
24
|
coderay (1.1.3)
|
25
|
-
concurrent-ruby (1.
|
25
|
+
concurrent-ruby (1.2.0)
|
26
26
|
crack (0.4.5)
|
27
27
|
rexml
|
28
28
|
diff-lcs (1.5.0)
|
29
29
|
docile (1.4.0)
|
30
|
-
faraday (2.
|
31
|
-
faraday-net_http (
|
30
|
+
faraday (2.7.4)
|
31
|
+
faraday-net_http (>= 2.0, < 3.1)
|
32
32
|
ruby2_keywords (>= 0.0.4)
|
33
|
-
faraday-net_http (
|
33
|
+
faraday-net_http (3.0.2)
|
34
34
|
hashdiff (1.0.1)
|
35
|
-
i18n (1.
|
35
|
+
i18n (1.12.0)
|
36
36
|
concurrent-ruby (~> 1.0)
|
37
|
+
json (2.6.3)
|
37
38
|
jsonpath (1.1.2)
|
38
39
|
multi_json
|
39
40
|
method_source (1.0.0)
|
40
|
-
minitest (5.
|
41
|
+
minitest (5.17.0)
|
41
42
|
multi_json (1.15.0)
|
42
43
|
parallel (1.22.1)
|
43
|
-
parser (3.1.
|
44
|
+
parser (3.2.1.0)
|
44
45
|
ast (~> 2.4.1)
|
45
|
-
pry (0.
|
46
|
+
pry (0.14.2)
|
46
47
|
coderay (~> 1.1)
|
47
48
|
method_source (~> 1.0)
|
48
|
-
pry-byebug (3.
|
49
|
+
pry-byebug (3.10.1)
|
49
50
|
byebug (~> 11.0)
|
50
|
-
pry (
|
51
|
-
public_suffix (
|
51
|
+
pry (>= 0.13, < 0.15)
|
52
|
+
public_suffix (5.0.1)
|
52
53
|
rainbow (3.1.1)
|
53
54
|
rake (13.0.6)
|
54
|
-
regexp_parser (2.
|
55
|
+
regexp_parser (2.7.0)
|
55
56
|
rexml (3.2.5)
|
56
|
-
rspec (3.
|
57
|
-
rspec-core (~> 3.
|
58
|
-
rspec-expectations (~> 3.
|
59
|
-
rspec-mocks (~> 3.
|
60
|
-
rspec-core (3.
|
61
|
-
rspec-support (~> 3.
|
62
|
-
rspec-expectations (3.
|
57
|
+
rspec (3.12.0)
|
58
|
+
rspec-core (~> 3.12.0)
|
59
|
+
rspec-expectations (~> 3.12.0)
|
60
|
+
rspec-mocks (~> 3.12.0)
|
61
|
+
rspec-core (3.12.1)
|
62
|
+
rspec-support (~> 3.12.0)
|
63
|
+
rspec-expectations (3.12.2)
|
63
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
64
|
-
rspec-support (~> 3.
|
65
|
-
rspec-mocks (3.
|
65
|
+
rspec-support (~> 3.12.0)
|
66
|
+
rspec-mocks (3.12.3)
|
66
67
|
diff-lcs (>= 1.2.0, < 2.0)
|
67
|
-
rspec-support (~> 3.
|
68
|
-
rspec-support (3.
|
69
|
-
rspec_junit_formatter (0.
|
68
|
+
rspec-support (~> 3.12.0)
|
69
|
+
rspec-support (3.12.0)
|
70
|
+
rspec_junit_formatter (0.6.0)
|
70
71
|
rspec-core (>= 2, < 4, != 2.12.0)
|
71
|
-
rubocop (1.
|
72
|
+
rubocop (1.45.1)
|
73
|
+
json (~> 2.3)
|
72
74
|
parallel (~> 1.10)
|
73
|
-
parser (>= 3.
|
75
|
+
parser (>= 3.2.0.0)
|
74
76
|
rainbow (>= 2.2.2, < 4.0)
|
75
77
|
regexp_parser (>= 1.8, < 3.0)
|
76
78
|
rexml (>= 3.2.5, < 4.0)
|
77
|
-
rubocop-ast (>= 1.
|
79
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
78
80
|
ruby-progressbar (~> 1.7)
|
79
|
-
unicode-display_width (>=
|
80
|
-
rubocop-ast (1.
|
81
|
-
parser (>= 3.
|
82
|
-
rubocop-
|
81
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
82
|
+
rubocop-ast (1.26.0)
|
83
|
+
parser (>= 3.2.1.0)
|
84
|
+
rubocop-capybara (2.17.0)
|
85
|
+
rubocop (~> 1.41)
|
86
|
+
rubocop-performance (1.16.0)
|
83
87
|
rubocop (>= 1.7.0, < 2.0)
|
84
88
|
rubocop-ast (>= 0.4.0)
|
85
|
-
rubocop-
|
86
|
-
rubocop (~> 1.
|
89
|
+
rubocop-rake (0.6.0)
|
90
|
+
rubocop (~> 1.0)
|
91
|
+
rubocop-rspec (2.18.1)
|
92
|
+
rubocop (~> 1.33)
|
93
|
+
rubocop-capybara (~> 2.17)
|
87
94
|
ruby-progressbar (1.11.0)
|
88
95
|
ruby2_keywords (0.0.5)
|
89
96
|
sawyer (0.9.2)
|
90
97
|
addressable (>= 2.3.5)
|
91
98
|
faraday (>= 0.17.3, < 3)
|
92
|
-
simplecov (0.
|
99
|
+
simplecov (0.22.0)
|
93
100
|
docile (~> 1.1)
|
94
101
|
simplecov-html (~> 0.11)
|
95
102
|
simplecov_json_formatter (~> 0.1)
|
96
103
|
simplecov-html (0.12.3)
|
97
104
|
simplecov_json_formatter (0.1.4)
|
98
|
-
tzinfo (2.0.
|
105
|
+
tzinfo (2.0.6)
|
99
106
|
concurrent-ruby (~> 1.0)
|
100
|
-
unicode-display_width (2.
|
101
|
-
webmock (3.
|
107
|
+
unicode-display_width (2.4.2)
|
108
|
+
webmock (3.18.1)
|
102
109
|
addressable (>= 2.8.0)
|
103
110
|
crack (>= 0.3.2)
|
104
111
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -119,10 +126,11 @@ DEPENDENCIES
|
|
119
126
|
rspec_junit_formatter
|
120
127
|
rubocop
|
121
128
|
rubocop-performance
|
129
|
+
rubocop-rake
|
122
130
|
rubocop-rspec
|
123
|
-
simplecov (= 0.
|
131
|
+
simplecov (= 0.22.0)
|
124
132
|
webmock
|
125
133
|
yard
|
126
134
|
|
127
135
|
BUNDLED WITH
|
128
|
-
2.3.
|
136
|
+
2.3.26
|
data/README.jp.md
CHANGED
@@ -12,8 +12,8 @@ MyApiClient は API リクエストクラスを作成するための汎用的な
|
|
12
12
|
|
13
13
|
## Supported Versions
|
14
14
|
|
15
|
-
- Ruby 2.7, 3.0, 3.1
|
16
|
-
- Rails
|
15
|
+
- Ruby 2.7, 3.0, 3.1, 3.2
|
16
|
+
- Rails 6.0, 6.1, 7.0
|
17
17
|
|
18
18
|
## Installation
|
19
19
|
|
@@ -221,6 +221,21 @@ error_handling json: { '$.errors.code': 10..19 }, with: :my_error_handling
|
|
221
221
|
}
|
222
222
|
```
|
223
223
|
|
224
|
+
`headers` には `Hash` の Key に レスポンスのヘッダーキーを指定して、 Value とマッチするかどうかでエラーハンドリングできます。Value には `String` `Regexp` が指定可能です。
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
error_handling headers: { 'www-authenticate': /invalid token/ }, with: :my_error_handling
|
228
|
+
```
|
229
|
+
|
230
|
+
上記の場合であれば、以下のような レスポンスヘッダー にマッチします。
|
231
|
+
|
232
|
+
```text
|
233
|
+
cache-control: no-cache, no-store, max-age=0, must-revalidate
|
234
|
+
content-type: application/json
|
235
|
+
www-authenticate: Bearer error="invalid_token", error_description="invalid token"
|
236
|
+
content-length: 104
|
237
|
+
```
|
238
|
+
|
224
239
|
`with` にはインスタンスメソッド名を指定することで、エラーを検出した際、例外を発生させる前に任意のメソッドを実行させることができます。メソッドに渡される引数は `block` 定義の場合と同じく `params` と `logger` です。なお、 `block` と `with` は同時には利用できません。
|
225
240
|
|
226
241
|
```ruby
|
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
[![CircleCI](https://circleci.com/gh/ryz310/my_api_client.svg?style=svg)](https://circleci.com/gh/ryz310/my_api_client)
|
1
|
+
[![CircleCI](https://circleci.com/gh/ryz310/my_api_client.svg?style=svg)](https://circleci.com/gh/ryz310/my_api_client)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/my_api_client.svg)](https://badge.fury.io/rb/my_api_client)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/861a2c8f168bbe995107/maintainability)](https://codeclimate.com/github/ryz310/my_api_client/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/861a2c8f168bbe995107/test_coverage)](https://codeclimate.com/github/ryz310/my_api_client/test_coverage)
|
5
|
+
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ryz310/my_api_client)
|
2
6
|
|
3
7
|
日本語ドキュメントは [こちら](README.jp.md)
|
4
8
|
|
@@ -12,8 +16,8 @@ It is supposed to be used in Ruby on Rails, but it is made to work in other envi
|
|
12
16
|
|
13
17
|
## Supported Versions
|
14
18
|
|
15
|
-
- Ruby 2.7, 3.0, 3.1
|
16
|
-
- Rails
|
19
|
+
- Ruby 2.7, 3.0, 3.1, 3.2
|
20
|
+
- Rails 6.0, 6.1, 7.0
|
17
21
|
|
18
22
|
## Installation
|
19
23
|
|
@@ -223,6 +227,21 @@ In the above case, it matches JSON as below:
|
|
223
227
|
}
|
224
228
|
```
|
225
229
|
|
230
|
+
For `headers`, specify response header for the Key of `Hash`, get an arbitrary value from the response header, and check whether it matches value. You can handle errors. You can specify `String` and `Regexp` for value.
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
error_handling headers: { 'www-authenticate': /invalid token/ }, with: :my_error_handling
|
234
|
+
```
|
235
|
+
|
236
|
+
In the above case, it matches response header as below:
|
237
|
+
|
238
|
+
```text
|
239
|
+
cache-control: no-cache, no-store, max-age=0, must-revalidate
|
240
|
+
content-type: application/json
|
241
|
+
www-authenticate: Bearer error="invalid_token", error_description="invalid token"
|
242
|
+
content-length: 104
|
243
|
+
```
|
244
|
+
|
226
245
|
By specifying the instance method name in `with`, when an error is detected, any method can be executed before raising an exception. The arguments passed to the method are `params` and `logger` as in the `block` definition. Note that `block` and` with` cannot be used at the same time.
|
227
246
|
|
228
247
|
```ruby
|
@@ -24,4 +24,13 @@ module MyErrors
|
|
24
24
|
|
25
25
|
# Error code: other
|
26
26
|
class ErrorCodeOther < MyApiClient::ClientError; end
|
27
|
+
|
28
|
+
# Header: X-First-Header has invalid
|
29
|
+
class FirstHeaderIsInvalid < MyApiClient::ClientError; end
|
30
|
+
|
31
|
+
# Header: X-First-Header has nothing and status is 404
|
32
|
+
class FirstHeaderHasNothingAndNotFound < MyApiClient::ClientError; end
|
33
|
+
|
34
|
+
# Header: X-First-Header has unknown and X-Second-Header has error
|
35
|
+
class MultipleHeaderIsInvalid < MyApiClient::ClientError; end
|
27
36
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'application_api_client'
|
4
|
+
|
5
|
+
# An usage example of the `my_api_client`.
|
6
|
+
# See also: my_api/app/controllers/header_controller.rb
|
7
|
+
class MyHeaderApiClient < ApplicationApiClient
|
8
|
+
error_handling headers: { 'X-First-Header': /invalid/ },
|
9
|
+
raise: MyErrors::FirstHeaderIsInvalid
|
10
|
+
|
11
|
+
error_handling headers: {
|
12
|
+
'X-First-Header': /unknown/,
|
13
|
+
'X-Second-Header': /error/,
|
14
|
+
},
|
15
|
+
raise: MyErrors::MultipleHeaderIsInvalid
|
16
|
+
|
17
|
+
error_handling headers: { 'X-First-Header': /nothing/ },
|
18
|
+
status_code: 404,
|
19
|
+
raise: MyErrors::FirstHeaderHasNothingAndNotFound
|
20
|
+
|
21
|
+
# GET header
|
22
|
+
#
|
23
|
+
# @param first_header [String] X-First-Header
|
24
|
+
# @param second_header [String] X-Second-Header
|
25
|
+
# @return [Sawyer::Resource]
|
26
|
+
def get_header(first_header:, second_header:)
|
27
|
+
get 'header', headers: headers, query: {
|
28
|
+
'X-First-Header': first_header,
|
29
|
+
'X-Second-Header': second_header,
|
30
|
+
}.compact
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def headers
|
36
|
+
{ 'Content-Type': 'application/json;charset=UTF-8' }
|
37
|
+
end
|
38
|
+
end
|
@@ -4,7 +4,7 @@ module MyApiClient
|
|
4
4
|
module ErrorHandling
|
5
5
|
# Generates an error handler proc (or symbol)
|
6
6
|
class Generator < ServiceAbstract
|
7
|
-
ARGUMENTS = %i[instance response status_code json with raise block].freeze
|
7
|
+
ARGUMENTS = %i[instance response status_code headers json with raise block].freeze
|
8
8
|
|
9
9
|
# @param options [Hash]
|
10
10
|
# Options for this generator
|
@@ -14,6 +14,8 @@ module MyApiClient
|
|
14
14
|
# The target of verifying
|
15
15
|
# @option status_code [String, Range, Integer, Regexp]
|
16
16
|
# Verifies response HTTP status code and raises error if matched
|
17
|
+
# @option headers [String, Regexp]
|
18
|
+
# Verifies response HTTP header and raises error if matched
|
17
19
|
# @option json [Hash, Symbol]
|
18
20
|
# Verifies response body as JSON and raises error if matched.
|
19
21
|
# If specified `:forbid_nil`, it forbid `nil` on response_body.
|
@@ -36,7 +38,8 @@ module MyApiClient
|
|
36
38
|
|
37
39
|
def call
|
38
40
|
return unless match?(_status_code, _response.status)
|
39
|
-
return unless
|
41
|
+
return unless match_headers?(_headers, _response.headers)
|
42
|
+
return unless match_body?(_json, _response.body)
|
40
43
|
|
41
44
|
generate_error_handler
|
42
45
|
end
|
@@ -102,7 +105,17 @@ module MyApiClient
|
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
105
|
-
def
|
108
|
+
def match_headers?(headers, response_headers)
|
109
|
+
return true if headers.nil?
|
110
|
+
return false if response_headers.blank?
|
111
|
+
|
112
|
+
headers.all? do |header_key, operator|
|
113
|
+
target = response_headers[header_key]
|
114
|
+
match?(operator, target)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def match_body?(json, response_body)
|
106
119
|
return true if json.nil?
|
107
120
|
return response_body.nil? if json == :forbid_nil
|
108
121
|
return false if response_body.blank?
|
@@ -86,7 +86,7 @@ module MyApiClient
|
|
86
86
|
when Proc
|
87
87
|
stub_as_resource(options.call(*request))
|
88
88
|
when Hash
|
89
|
-
if options[:raise]
|
89
|
+
if options[:raise]
|
90
90
|
raise process_raise_option(options[:raise], options[:response], options[:status_code])
|
91
91
|
elsif options[:response]
|
92
92
|
stub_as_resource(options[:response])
|
data/my_api/Gemfile
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
gem 'jets'
|
5
|
+
gem 'jets', '~> 3.2.0'
|
6
6
|
|
7
7
|
gem 'dynomite'
|
8
8
|
|
9
9
|
# See: https://github.com/boltops-tools/jets/issues/523
|
10
|
-
gem 'nokogiri', '~> 1.
|
10
|
+
gem 'nokogiri', '~> 1.14.1'
|
11
11
|
|
12
12
|
# development and test groups are not bundled as part of the deployment
|
13
13
|
group :development, :test do
|