my_api_client 0.20.0 → 0.23.0

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +34 -18
  3. data/.github/dependabot.yml +32 -0
  4. data/.rubocop.yml +10 -10
  5. data/.rubocop_todo.yml +2 -2
  6. data/CHANGELOG.md +215 -249
  7. data/Gemfile.lock +54 -57
  8. data/README.jp.md +36 -34
  9. data/README.md +391 -8
  10. data/example/api_clients/application_api_client.rb +1 -1
  11. data/gemfiles/rails_5.0.gemfile +1 -0
  12. data/gemfiles/rails_5.1.gemfile +1 -0
  13. data/gemfiles/rails_5.2.gemfile +1 -0
  14. data/gemfiles/rails_6.0.gemfile +1 -0
  15. data/gemfiles/rails_7.0.gemfile +15 -0
  16. data/lib/generators/rails/templates/api_client.rb.erb +3 -5
  17. data/lib/generators/rspec/templates/api_client_spec.rb.erb +0 -8
  18. data/lib/my_api_client/errors/network_error.rb +3 -3
  19. data/lib/my_api_client/errors.rb +2 -2
  20. data/lib/my_api_client/integrations/bugsnag.rb +2 -2
  21. data/lib/my_api_client/rspec/matchers/be_handled_as_an_error.rb +3 -3
  22. data/lib/my_api_client/rspec/stub.rb +11 -7
  23. data/lib/my_api_client/version.rb +1 -1
  24. data/my_api/Gemfile +1 -1
  25. data/my_api/Gemfile.lock +100 -99
  26. data/my_api/app/controllers/pagination_controller.rb +1 -1
  27. data/my_api/public/index.html +2 -2
  28. data/my_api/spec/spec_helper.rb +1 -1
  29. data/my_api_client.gemspec +4 -1
  30. data/rails_app/rails_5.2/Gemfile.lock +70 -64
  31. data/rails_app/rails_6.0/Gemfile +1 -0
  32. data/rails_app/rails_6.0/Gemfile.lock +92 -94
  33. data/rails_app/rails_6.1/Gemfile +2 -2
  34. data/rails_app/rails_6.1/Gemfile.lock +91 -95
  35. data/rails_app/rails_6.1/Rakefile +3 -1
  36. data/rails_app/rails_6.1/bin/bundle +28 -20
  37. data/rails_app/rails_6.1/bin/rails +4 -2
  38. data/rails_app/rails_6.1/bin/rake +4 -2
  39. data/rails_app/rails_6.1/bin/setup +3 -1
  40. data/rails_app/rails_6.1/config.ru +3 -1
  41. data/rails_app/rails_7.0/Gemfile +13 -0
  42. data/rails_app/rails_7.0/Gemfile.lock +210 -0
  43. data/rails_app/rails_7.0/README.md +24 -0
  44. data/rails_app/rails_7.0/Rakefile +8 -0
  45. data/rails_app/rails_7.0/app/controllers/application_controller.rb +4 -0
  46. data/rails_app/rails_7.0/app/models/application_record.rb +5 -0
  47. data/rails_app/rails_7.0/bin/bundle +122 -0
  48. data/rails_app/rails_7.0/bin/rails +6 -0
  49. data/rails_app/rails_7.0/bin/rake +6 -0
  50. data/rails_app/rails_7.0/bin/setup +35 -0
  51. data/rails_app/rails_7.0/config/application.rb +41 -0
  52. data/rails_app/rails_7.0/config/boot.rb +5 -0
  53. data/rails_app/rails_7.0/config/credentials.yml.enc +1 -0
  54. data/rails_app/rails_7.0/config/database.yml +25 -0
  55. data/rails_app/rails_7.0/config/environment.rb +7 -0
  56. data/rails_app/rails_7.0/config/environments/development.rb +58 -0
  57. data/rails_app/rails_7.0/config/environments/production.rb +70 -0
  58. data/rails_app/rails_7.0/config/environments/test.rb +52 -0
  59. data/rails_app/rails_7.0/config/initializers/cors.rb +17 -0
  60. data/rails_app/rails_7.0/config/initializers/filter_parameter_logging.rb +8 -0
  61. data/rails_app/rails_7.0/config/initializers/inflections.rb +17 -0
  62. data/rails_app/rails_7.0/config/locales/en.yml +33 -0
  63. data/rails_app/rails_7.0/config/routes.rb +8 -0
  64. data/rails_app/rails_7.0/config.ru +8 -0
  65. data/rails_app/rails_7.0/db/seeds.rb +8 -0
  66. data/rails_app/rails_7.0/public/robots.txt +1 -0
  67. data/rails_app/rails_7.0/spec/rails_helper.rb +14 -0
  68. data/rails_app/rails_7.0/spec/spec_helper.rb +13 -0
  69. metadata +36 -6
  70. data/.dependabot/config.yml +0 -34
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_api_client (0.20.0)
4
+ my_api_client (0.23.0)
5
5
  activesupport (>= 5.2.0)
6
6
  faraday (>= 0.17.1)
7
7
  jsonpath
@@ -10,40 +10,37 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (6.1.3)
13
+ activesupport (7.0.3)
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
- zeitwerk (~> 2.3)
19
- addressable (2.7.0)
18
+ addressable (2.8.0)
20
19
  public_suffix (>= 2.0.2, < 5.0)
21
20
  ast (2.4.2)
22
- bugsnag (6.19.0)
21
+ bugsnag (6.24.2)
23
22
  concurrent-ruby (~> 1.0)
24
23
  byebug (11.1.3)
25
24
  coderay (1.1.3)
26
- concurrent-ruby (1.1.8)
25
+ concurrent-ruby (1.1.10)
27
26
  crack (0.4.5)
28
27
  rexml
29
- diff-lcs (1.4.4)
30
- docile (1.3.5)
31
- faraday (1.3.0)
32
- faraday-net_http (~> 1.0)
33
- multipart-post (>= 1.2, < 3)
34
- ruby2_keywords
35
- faraday-net_http (1.0.1)
28
+ diff-lcs (1.5.0)
29
+ docile (1.4.0)
30
+ faraday (2.3.0)
31
+ faraday-net_http (~> 2.0)
32
+ ruby2_keywords (>= 0.0.4)
33
+ faraday-net_http (2.0.3)
36
34
  hashdiff (1.0.1)
37
- i18n (1.8.9)
35
+ i18n (1.10.0)
38
36
  concurrent-ruby (~> 1.0)
39
- jsonpath (1.1.0)
37
+ jsonpath (1.1.2)
40
38
  multi_json
41
39
  method_source (1.0.0)
42
- minitest (5.14.4)
40
+ minitest (5.15.0)
43
41
  multi_json (1.15.0)
44
- multipart-post (2.1.1)
45
- parallel (1.20.1)
46
- parser (3.0.0.0)
42
+ parallel (1.22.1)
43
+ parser (3.1.2.0)
47
44
  ast (~> 2.4.1)
48
45
  pry (0.13.1)
49
46
  coderay (~> 1.1)
@@ -51,63 +48,63 @@ GEM
51
48
  pry-byebug (3.9.0)
52
49
  byebug (~> 11.0)
53
50
  pry (~> 0.13.0)
54
- public_suffix (4.0.6)
55
- rainbow (3.0.0)
56
- rake (13.0.3)
57
- regexp_parser (2.1.1)
58
- rexml (3.2.4)
59
- rspec (3.10.0)
60
- rspec-core (~> 3.10.0)
61
- rspec-expectations (~> 3.10.0)
62
- rspec-mocks (~> 3.10.0)
63
- rspec-core (3.10.1)
64
- rspec-support (~> 3.10.0)
65
- rspec-expectations (3.10.1)
51
+ public_suffix (4.0.7)
52
+ rainbow (3.1.1)
53
+ rake (13.0.6)
54
+ regexp_parser (2.5.0)
55
+ rexml (3.2.5)
56
+ rspec (3.11.0)
57
+ rspec-core (~> 3.11.0)
58
+ rspec-expectations (~> 3.11.0)
59
+ rspec-mocks (~> 3.11.0)
60
+ rspec-core (3.11.0)
61
+ rspec-support (~> 3.11.0)
62
+ rspec-expectations (3.11.0)
66
63
  diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.10.0)
68
- rspec-mocks (3.10.2)
64
+ rspec-support (~> 3.11.0)
65
+ rspec-mocks (3.11.1)
69
66
  diff-lcs (>= 1.2.0, < 2.0)
70
- rspec-support (~> 3.10.0)
71
- rspec-support (3.10.2)
72
- rspec_junit_formatter (0.4.1)
67
+ rspec-support (~> 3.11.0)
68
+ rspec-support (3.11.0)
69
+ rspec_junit_formatter (0.5.1)
73
70
  rspec-core (>= 2, < 4, != 2.12.0)
74
- rubocop (1.11.0)
71
+ rubocop (1.30.1)
75
72
  parallel (~> 1.10)
76
- parser (>= 3.0.0.0)
73
+ parser (>= 3.1.0.0)
77
74
  rainbow (>= 2.2.2, < 4.0)
78
75
  regexp_parser (>= 1.8, < 3.0)
79
- rexml
80
- rubocop-ast (>= 1.2.0, < 2.0)
76
+ rexml (>= 3.2.5, < 4.0)
77
+ rubocop-ast (>= 1.18.0, < 2.0)
81
78
  ruby-progressbar (~> 1.7)
82
79
  unicode-display_width (>= 1.4.0, < 3.0)
83
- rubocop-ast (1.4.1)
84
- parser (>= 2.7.1.5)
85
- rubocop-performance (1.10.1)
86
- rubocop (>= 0.90.0, < 2.0)
80
+ rubocop-ast (1.18.0)
81
+ parser (>= 3.1.1.0)
82
+ rubocop-performance (1.14.2)
83
+ rubocop (>= 1.7.0, < 2.0)
87
84
  rubocop-ast (>= 0.4.0)
88
- rubocop-rspec (2.2.0)
89
- rubocop (~> 1.0)
90
- rubocop-ast (>= 1.1.0)
85
+ rubocop-rspec (2.11.1)
86
+ rubocop (~> 1.19)
91
87
  ruby-progressbar (1.11.0)
92
- ruby2_keywords (0.0.4)
93
- sawyer (0.8.2)
88
+ ruby2_keywords (0.0.5)
89
+ sawyer (0.9.2)
94
90
  addressable (>= 2.3.5)
95
- faraday (> 0.8, < 2.0)
91
+ faraday (>= 0.17.3, < 3)
96
92
  simplecov (0.21.2)
97
93
  docile (~> 1.1)
98
94
  simplecov-html (~> 0.11)
99
95
  simplecov_json_formatter (~> 0.1)
100
96
  simplecov-html (0.12.3)
101
- simplecov_json_formatter (0.1.2)
97
+ simplecov_json_formatter (0.1.4)
102
98
  tzinfo (2.0.4)
103
99
  concurrent-ruby (~> 1.0)
104
- unicode-display_width (2.0.0)
105
- webmock (3.12.1)
106
- addressable (>= 2.3.6)
100
+ unicode-display_width (2.1.0)
101
+ webmock (3.14.0)
102
+ addressable (>= 2.8.0)
107
103
  crack (>= 0.3.2)
108
104
  hashdiff (>= 0.4.0, < 2.0.0)
109
- yard (0.9.26)
110
- zeitwerk (2.4.2)
105
+ webrick (1.7.0)
106
+ yard (0.9.28)
107
+ webrick (~> 1.7.0)
111
108
 
112
109
  PLATFORMS
113
110
  ruby
@@ -128,4 +125,4 @@ DEPENDENCIES
128
125
  yard
129
126
 
130
127
  BUNDLED WITH
131
- 2.2.3
128
+ 2.3.11
data/README.jp.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # MyApiClient
4
4
 
5
- MyApiClient は API リクエストクラスを作成するための汎用的な機能を提供します。Sawyer や Faraday をベースにエラーハンドリングの機能を強化した構造になっています。
5
+ MyApiClient は API リクエストクラスを作成するための汎用的な機能を提供します。[Sawyer](https://github.com/lostisland/sawyer)[Faraday](https://github.com/lostisland/faraday) をベースにエラーハンドリングの機能を強化した構造になっています。
6
6
 
7
7
  ただし、 Sawyer はダミーデータの作成が難しかったり、他の gem で競合することがよくあるので、将来的には依存しないように変更していくかもしれません。
8
8
 
@@ -12,12 +12,12 @@ MyApiClient は API リクエストクラスを作成するための汎用的な
12
12
 
13
13
  ## Supported Versions
14
14
 
15
- * Ruby 2.5, 2.6, 2.7, 3.0
16
- * Rails 5.2, 6.0, 6.1
15
+ - Ruby 2.7, 3.0, 3.1
16
+ - Rails 5.2, 6.0, 6.1, 7.0
17
17
 
18
18
  ## Installation
19
19
 
20
- この gem は macOS と Linux で作動します。まずは `my_api_client` を Gemfile に追加します:
20
+ `my_api_client` を Gemfile に追加して下さい:
21
21
 
22
22
  ```ruby
23
23
  gem 'my_api_client'
@@ -116,7 +116,7 @@ end
116
116
  {
117
117
  "links": {
118
118
  "next": "https://example.com/pagination?page=3",
119
- "previous": "https://example.com/pagination?page=1",
119
+ "previous": "https://example.com/pagination?page=1"
120
120
  },
121
121
  "page": 2
122
122
  }
@@ -130,13 +130,13 @@ api_clinet.pagination.each do |response|
130
130
  # Do something.
131
131
  end
132
132
 
133
- p = api_clinet.pagination
134
- p.next # => 1st page result
135
- p.next # => 2nd page result
136
- p.next # => 3rd page result
133
+ result = api_clinet.pagination
134
+ result.next # => 1st page result
135
+ result.next # => 2nd page result
136
+ result.next # => 3rd page result
137
137
  ```
138
138
 
139
- なお、`#each` はレスポンスに含まれる `paging` の値が nil になるまで繰り返されるのでご注意ください。例えば `#take` と組み合わせることでページネーションの上限を設定できます。
139
+ なお、`#each` はレスポンスに含まれる `paging` の値が `nil` になるまで繰り返されるのでご注意ください。例えば `#take` と組み合わせることでページネーションの上限を設定できます。
140
140
 
141
141
  `#pageable_get` の alias として `#pget` も利用可能です。
142
142
 
@@ -200,24 +200,24 @@ error_handling status_code: 500..599, raise: MyApiClient::ServerError do |_param
200
200
  end
201
201
  ```
202
202
 
203
- 上記の例であれば、ステータスコードが `500..599` の場合に `MyApiClient::ServerError` を発生させる前に `block` の内容が実行れます。引数の `params` にはリクエスト情報とレスポンス情報が含まれています。`logger` はログ出力用インスタンスですが、このインスタンスを使ってログ出力すると、以下のようにリクエスト情報がログ出力に含まれるようになり、デバッグの際に便利です。
203
+ 上記の例であれば、ステータスコードが `500..599` の場合に `MyApiClient::ServerError` を発生させる前に `block` の内容が実行れます。引数の `params` にはリクエスト情報とレスポンス情報が含まれています。`logger` はログ出力用インスタンスですが、このインスタンスを使ってログ出力すると、以下のようにリクエスト情報がログ出力に含まれるようになり、デバッグの際に便利です。
204
204
 
205
205
  ```text
206
206
  API request `GET https://example.com/path/to/resouce`: "Server error occurred."
207
207
  ```
208
208
 
209
+ `json` には `Hash` の Key に [JSONPath](https://goessner.net/articles/JsonPath/) を指定して、レスポンス JSON から任意の値を取得し、 Value とマッチするかどうかでエラーハンドリングできます。Value には `String` `Integer` `Range` `Regexp` が指定可能です。上記の場合であれば、以下のような JSON にマッチします。
210
+
209
211
  ```ruby
210
212
  error_handling json: { '$.errors.code': 10..19 }, with: :my_error_handling
211
213
  ```
212
214
 
213
- `json` には `Hash` の Key に [JSONPath](https://goessner.net/articles/JsonPath/) を指定して、レスポンス JSON から任意の値を取得し、 Value とマッチするかどうかでエラーハンドリングできます。Value には `String` `Integer` `Range` `Regexp` が指定可能です。上記の場合であれば、以下のような JSON にマッチします。
214
-
215
215
  ```json
216
216
  {
217
- "erros": {
218
- "code": 10,
219
- "message": "Some error has occurred."
220
- }
217
+ "erros": {
218
+ "code": 10,
219
+ "message": "Some error has occurred."
220
+ }
221
221
  }
222
222
  ```
223
223
 
@@ -253,10 +253,10 @@ error_handling json: { '$.errors.code': :negative? }
253
253
 
254
254
  ```json
255
255
  {
256
- "erros": {
257
- "code": -1,
258
- "message": "Some error has occurred."
259
- }
256
+ "erros": {
257
+ "code": -1,
258
+ "message": "Some error has occurred."
259
+ }
260
260
  }
261
261
  ```
262
262
 
@@ -344,8 +344,8 @@ error_handling json: { '$.errors.code': 20 },
344
344
 
345
345
  `retry` オプションを使用する際は以下の点に注意が必要です。
346
346
 
347
- * `error_handling` に `raise` オプションの指定が必須となります。
348
- * Block を使った `error_handling` の定義は禁止されます。
347
+ - `error_handling` に `raise` オプションの指定が必須となります。
348
+ - Block を使った `error_handling` の定義は禁止されます。
349
349
 
350
350
  #### MyApiClient::NetworkError
351
351
 
@@ -630,14 +630,15 @@ stub_api_client_all(ExampleApiClient, request: { raise: MyApiClient::Error })
630
630
  expect { execute_api_request }.to raise_error(MyApiClient::Error)
631
631
  ```
632
632
 
633
- なお、発生した例外に含まれるレスポンスパラメータもスタブ化したい場合は、 `response` オプションと同時に指定することが可能です。
633
+ なお、発生した例外に含まれるレスポンスパラメータやステータスコードもスタブ化したい場合は、 `response` オプションと同時に指定することが可能です。
634
634
 
635
635
  ```ruby
636
636
  stub_api_client_all(
637
637
  ExampleApiClient,
638
638
  request: {
639
639
  raise: MyApiClient::Error,
640
- response: { message: 'error' }
640
+ response: { message: 'error' },
641
+ status_code: 429
641
642
  }
642
643
  )
643
644
 
@@ -646,12 +647,14 @@ begin
646
647
  rescue MyApiClient::Error => e
647
648
  response_body = e.params.response.data.to_h
648
649
  expect(response_body).to eq(message: 'error')
650
+ status_code = e.params.response.status
651
+ expect(status_code).to eq(429)
649
652
  end
650
653
  ```
651
654
 
652
655
  #### `pageable` option
653
656
 
654
- `#pageable_get` (`#pget`) を使った実装用に `pageable` というオプションが利用できます。
657
+ `#pageable_get` (`#pget`) を使った実装用に `pageable` というオプションが利用できます。
655
658
  `pageable` に設定する値は `Enumerable` である必要があります。
656
659
 
657
660
  ```ruby
@@ -671,7 +674,7 @@ MyPaginationApiClient.new.pagination.each do |response|
671
674
  end
672
675
  ```
673
676
 
674
- なお、 `Enumerable` の各値にはここまで紹介した `response`, `raise`, `Prox` など全てのオプションが利用可能です。
677
+ なお、 `Enumerable` の各値にはここまで紹介した `response`, `raise`, `Proc` など全てのオプションが利用可能です。
675
678
 
676
679
  ```ruby
677
680
  stub_api_client_all(
@@ -689,7 +692,6 @@ stub_api_client_all(
689
692
 
690
693
  また、 `Enumerator` を使えば無限に続くページネーションを定義することもできます。
691
694
 
692
-
693
695
  ```ruby
694
696
  stub_api_client_all(
695
697
  MyPaginationApiClient,
@@ -739,10 +741,10 @@ $ gem_comet release {VERSION}
739
741
 
740
742
  実行すると、 https://github.com/ryz310/my_api_client/pulls に以下のような PR が作成されます。
741
743
 
742
- * [Update v0\.16\.1](https://github.com/ryz310/my_api_client/pull/297)
743
- * [Release v0\.16\.1](https://github.com/ryz310/my_api_client/pull/298)
744
+ - [Update v0\.16\.1](https://github.com/ryz310/my_api_client/pull/297)
745
+ - [Release v0\.16\.1](https://github.com/ryz310/my_api_client/pull/298)
744
746
 
745
- まず、 `Update v{VERSION}` という PR から merge に取り掛かります。
747
+ まず、 `Update v{VERSION}` という PR から merge に取り掛かります。
746
748
 
747
749
  PR のコメントにも TODO が記載されていますが、まず、バージョン番号が正しく採番されているかを確認します。
748
750
 
@@ -752,12 +754,12 @@ See: [314a4c0](https://github.com/ryz310/my_api_client/pull/297/commits/314a4c06
752
754
 
753
755
  See: [33a2d17](https://github.com/ryz310/my_api_client/pull/297/commits/33a2d1703c773813c837e74ee3181906b2f2e502)
754
756
 
755
- これらが整ったら、 `Update v{VERSION}` を merge します。
757
+ これらが整ったら、 `Update v{VERSION}` を merge します。
756
758
 
757
- これでリリース準備が整ったので、`Release v{VERSION}` の merge に取り掛かります。
759
+ これでリリース準備が整ったので、`Release v{VERSION}` の merge に取り掛かります。
758
760
 
759
761
  この PR にこれからリリースする gem に対する変更が全て載っています。
760
- 変更内容の最終確認をして、 CI も通ったことを確認したら `Release v{VERSION}` を merge します。
762
+ 変更内容の最終確認をして、 CI も通ったことを確認したら `Release v{VERSION}` を merge します。
761
763
 
762
764
  あとは Circle CI 側で gem のリリースが自動実行されるので、暫く待ちましょう。
763
765