my_api_client 0.26.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +5 -5
  3. data/.rubocop.yml +1 -1
  4. data/.rubocop_todo.yml +15 -4
  5. data/CHANGELOG.md +55 -0
  6. data/Gemfile.lock +39 -27
  7. data/README.jp.md +7 -7
  8. data/README.md +5 -5
  9. data/example/api_clients/my_pagination_api_client.rb +11 -2
  10. data/lib/my_api_client/errors/network_error.rb +1 -1
  11. data/lib/my_api_client/errors.rb +1 -1
  12. data/lib/my_api_client/request/basic.rb +10 -2
  13. data/lib/my_api_client/request/pagination.rb +23 -2
  14. data/lib/my_api_client/rspec/stub.rb +1 -0
  15. data/lib/my_api_client/service_abstract.rb +2 -2
  16. data/lib/my_api_client/version.rb +1 -1
  17. data/my_api/.ruby-version +1 -1
  18. data/my_api/Gemfile +2 -2
  19. data/my_api/Gemfile.lock +77 -76
  20. data/my_api/public/index.html +2 -2
  21. data/my_api_client.gemspec +2 -2
  22. metadata +6 -38
  23. data/gemfiles/rails_6.0.gemfile +0 -16
  24. data/rails_app/rails_6.0/.rspec +0 -3
  25. data/rails_app/rails_6.0/Gemfile +0 -18
  26. data/rails_app/rails_6.0/Gemfile.lock +0 -188
  27. data/rails_app/rails_6.0/README.md +0 -24
  28. data/rails_app/rails_6.0/Rakefile +0 -8
  29. data/rails_app/rails_6.0/app/controllers/application_controller.rb +0 -4
  30. data/rails_app/rails_6.0/app/jobs/application_job.rb +0 -9
  31. data/rails_app/rails_6.0/bin/rails +0 -6
  32. data/rails_app/rails_6.0/bin/rake +0 -6
  33. data/rails_app/rails_6.0/bin/setup +0 -27
  34. data/rails_app/rails_6.0/config/application.rb +0 -39
  35. data/rails_app/rails_6.0/config/boot.rb +0 -6
  36. data/rails_app/rails_6.0/config/credentials.yml.enc +0 -1
  37. data/rails_app/rails_6.0/config/environment.rb +0 -7
  38. data/rails_app/rails_6.0/config/environments/development.rb +0 -39
  39. data/rails_app/rails_6.0/config/environments/production.rb +0 -90
  40. data/rails_app/rails_6.0/config/environments/test.rb +0 -41
  41. data/rails_app/rails_6.0/config/initializers/application_controller_renderer.rb +0 -9
  42. data/rails_app/rails_6.0/config/initializers/backtrace_silencers.rb +0 -8
  43. data/rails_app/rails_6.0/config/initializers/cors.rb +0 -17
  44. data/rails_app/rails_6.0/config/initializers/filter_parameter_logging.rb +0 -6
  45. data/rails_app/rails_6.0/config/initializers/inflections.rb +0 -17
  46. data/rails_app/rails_6.0/config/initializers/mime_types.rb +0 -5
  47. data/rails_app/rails_6.0/config/initializers/wrap_parameters.rb +0 -11
  48. data/rails_app/rails_6.0/config/locales/en.yml +0 -33
  49. data/rails_app/rails_6.0/config/routes.rb +0 -5
  50. data/rails_app/rails_6.0/config/spring.rb +0 -8
  51. data/rails_app/rails_6.0/config.ru +0 -7
  52. data/rails_app/rails_6.0/public/robots.txt +0 -1
  53. data/rails_app/rails_6.0/spec/rails_helper.rb +0 -14
  54. data/rails_app/rails_6.0/spec/spec_helper.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04b65801b00f389260d1c5e565c9bf62141dca015f7d63a1f2f55a9432202971
4
- data.tar.gz: 0cb50201bdc0877a6bff65300907be74910c62ee29112c782ac513f6e153c243
3
+ metadata.gz: 9a7c0e59912fcb57831b996cda5b2d18d6488e33609eac9c1cc227b8d2699177
4
+ data.tar.gz: 6cf555c678a2537db8fe85dfe2c6a98385c61d00b92bc4d931c3bfdfdf04442b
5
5
  SHA512:
6
- metadata.gz: f2404378034857782c548971e5812a791ebe7902b5a73b63a56eb85a52e5d29aef6eee64c654377a4564ee33ac30f11e3d0c2e60dca391a658d7786cddb4ea50
7
- data.tar.gz: 5daea5828a938350e909238b2c3d217e5dc49f792626689791b033648650ffc6b8f99eaa4edbe4a100d41212d811732d2072d40d4f79252752e034a4cbc413bd
6
+ metadata.gz: 289f20431d12e8c625e15da365c85607da2324cb4990f8ad100ef8fd31b1c1acd5dae6e964b20191ef4be3b98518b77c792e5a5616d4e506cf01407f5038f822
7
+ data.tar.gz: 61b0c21d3b43b5492d84bd6eb5107efcf4b7f6b8573685c9f85097276ae86c97ca27beb988d7482b864b17f18a8655a1e43251bb827de36e23a1aa46e314365f
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", "3.2"]
15
+ enum: &ruby_version_enum ["3.0", "3.1", "3.2"]
16
16
  default: "3.2"
17
17
  - &rails_version
18
18
  rails_version:
19
19
  type: enum
20
- enum: &rails_version_enum ["6.0", "6.1", "7.0"]
20
+ enum: &rails_version_enum ["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: v2-dependencies-<< parameters.ruby_version >>
156
+ cache_key_prefix: v3-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: 24
255
+ parts: 12
256
256
  - code-climate/upload-coverage
257
257
  rubocop:
258
258
  executor: gem_executor
@@ -294,7 +294,7 @@ workflows:
294
294
  ruby_version: *ruby_version_enum
295
295
  rails_version: *rails_version_enum
296
296
  - test_api:
297
- ruby_version: "2.7" # Jets supports only Ruby 2.x
297
+ ruby_version: "3.2"
298
298
  - rubocop
299
299
  - yardoc
300
300
  - upload-coverage:
data/.rubocop.yml CHANGED
@@ -6,7 +6,7 @@ require:
6
6
  inherit_from: .rubocop_todo.yml
7
7
 
8
8
  AllCops:
9
- TargetRubyVersion: 2.7
9
+ TargetRubyVersion: 3.0
10
10
  NewCops: enable
11
11
  Exclude:
12
12
  - rails_app/**/*
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2023-02-06 23:31:23 UTC using RuboCop version 1.41.1.
3
+ # on 2023-11-13 01:22:13 UTC using RuboCop version 1.57.2.
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
@@ -14,7 +14,8 @@ Lint/EmptyBlock:
14
14
  - 'spec/support/complete_about.rb'
15
15
  - 'spec/support/complete_within.rb'
16
16
 
17
- # Offense count: 5
17
+ # Offense count: 6
18
+ # Configuration parameters: AllowedParentClasses.
18
19
  Lint/MissingSuper:
19
20
  Exclude:
20
21
  - 'lib/my_api_client/error_handling/generator.rb'
@@ -27,17 +28,27 @@ Lint/MissingSuper:
27
28
  # Offense count: 6
28
29
  # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
29
30
  # SupportedStyles: snake_case, normalcase, non_integer
30
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
31
+ # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
31
32
  Naming/VariableNumber:
32
33
  Exclude:
33
34
  - 'spec/lib/my_api_client/error_handling_spec.rb'
34
35
  - 'spec/lib/my_api_client/request/executor_spec.rb'
35
36
 
36
- # Offense count: 101
37
+ # Offense count: 103
37
38
  # Configuration parameters: AllowSubject.
38
39
  RSpec/MultipleMemoizedHelpers:
39
40
  Max: 15
40
41
 
42
+ # Offense count: 3
43
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
44
+ # Include: **/*_spec.rb
45
+ RSpec/SpecFilePathFormat:
46
+ Exclude:
47
+ - '**/spec/routing/**/*'
48
+ - 'spec/lib/my_api_client/errors/error_spec.rb'
49
+ - 'spec/lib/my_api_client/errors/network_error_spec.rb'
50
+ - 'spec/lib/my_api_client/rspec/stub_spec.rb'
51
+
41
52
  # Offense count: 3
42
53
  Style/DocumentDynamicEvalDefinition:
43
54
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,60 @@
1
1
  # Change log
2
2
 
3
+ ## v1.0.0 (Dec 07, 2023)
4
+
5
+ ### Feature
6
+
7
+ - [#955](https://github.com/ryz310/my_api_client/pull/955) Enable Dynamic URL Generation for `#pageable_get` via `Proc` Objects ([@ryz310](https://github.com/ryz310))
8
+
9
+ ```ruby
10
+ # Example of using a Proc with pageable_get
11
+ pget 'api/example', headers:, query:, paging: ->(response) {
12
+ # Custom logic to generate the next URL
13
+ }
14
+ ```
15
+
16
+ ### Dependabot
17
+
18
+ - [#950](https://github.com/ryz310/my_api_client/pull/950) Bump faraday from 2.7.11 to 2.7.12 ([@ryz310](https://github.com/ryz310))
19
+
20
+ ## v0.27.0 (Nov 13, 2023)
21
+
22
+ ### Feature
23
+
24
+ - [#944](https://github.com/ryz310/my_api_client/pull/944) Add block to retrieve sawyer response ([@okumud](https://github.com/okumud))
25
+
26
+ ```rb
27
+ api_clinet = ExampleApiClient.new(access_token: 'access_token')
28
+
29
+ # You can retrieve sawyer response with return value
30
+ api_clinet.get_users #=> #<Sawyer::Resource>
31
+
32
+ # You can retrieve sawyer response with block
33
+ api_clinet.get_users do |response|
34
+ response #=> #<Sawyer::Response>
35
+ response.headers #=> #<Hash>
36
+ response.data #=> #<Sawyer::Resource>
37
+ end
38
+ ```
39
+
40
+ ### Breaking Change
41
+
42
+ - [#931](https://github.com/ryz310/my_api_client/pull/931) End of support for ruby 2.7 and rails 6.0 ([@ryz310](https://github.com/ryz310))
43
+
44
+ ### Dependabot
45
+
46
+ - [#919](https://github.com/ryz310/my_api_client/pull/919) Bump bugsnag from 6.25.2 to 6.26.0 ([@ryz310](https://github.com/ryz310))
47
+ - [#929](https://github.com/ryz310/my_api_client/pull/929) Bump webmock from 3.19.0 to 3.19.1 ([@ryz310](https://github.com/ryz310))
48
+ - [#934](https://github.com/ryz310/my_api_client/pull/934) Bump rubocop-performance from 1.19.0 to 1.19.1 ([@ryz310](https://github.com/ryz310))
49
+ - [#933](https://github.com/ryz310/my_api_client/pull/933) Bump faraday from 2.7.10 to 2.7.11 ([@ryz310](https://github.com/ryz310))
50
+ - [#939](https://github.com/ryz310/my_api_client/pull/939) Bump jsonpath from 1.1.4 to 1.1.5 ([@ryz310](https://github.com/ryz310))
51
+ - [#942](https://github.com/ryz310/my_api_client/pull/942) Bump rake from 13.0.6 to 13.1.0 ([@ryz310](https://github.com/ryz310))
52
+ - [#945](https://github.com/ryz310/my_api_client/pull/945) Bump activesupport from 7.1.1 to 7.1.2 ([@ryz310](https://github.com/ryz310))
53
+
54
+ ### Misc
55
+
56
+ - [#946](https://github.com/ryz310/my_api_client/pull/946) Fix a broken spec ([@ryz310](https://github.com/ryz310))
57
+
3
58
  ## v0.26.0 (Jul 04, 2023)
4
59
 
5
60
  ### Bugfix
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_api_client (0.26.0)
5
- activesupport (>= 6.0.0)
4
+ my_api_client (1.0.0)
5
+ activesupport (>= 6.1.0)
6
6
  faraday (>= 0.17.1)
7
7
  jsonpath
8
8
  sawyer (>= 0.8.2)
@@ -10,39 +10,51 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.0.6)
13
+ activesupport (7.1.2)
14
+ base64
15
+ bigdecimal
14
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ connection_pool (>= 2.2.5)
18
+ drb
15
19
  i18n (>= 1.6, < 2)
16
20
  minitest (>= 5.1)
21
+ mutex_m
17
22
  tzinfo (~> 2.0)
18
- addressable (2.8.4)
23
+ addressable (2.8.5)
19
24
  public_suffix (>= 2.0.2, < 6.0)
20
25
  ast (2.4.2)
21
- bugsnag (6.25.2)
26
+ base64 (0.2.0)
27
+ bigdecimal (3.1.4)
28
+ bugsnag (6.26.0)
22
29
  concurrent-ruby (~> 1.0)
23
30
  byebug (11.1.3)
24
31
  coderay (1.1.3)
25
32
  concurrent-ruby (1.2.2)
33
+ connection_pool (2.4.1)
26
34
  crack (0.4.5)
27
35
  rexml
28
36
  diff-lcs (1.5.0)
29
37
  docile (1.4.0)
30
- faraday (2.7.9)
38
+ drb (2.2.0)
39
+ ruby2_keywords
40
+ faraday (2.7.12)
41
+ base64
31
42
  faraday-net_http (>= 2.0, < 3.1)
32
43
  ruby2_keywords (>= 0.0.4)
33
44
  faraday-net_http (3.0.2)
34
45
  hashdiff (1.0.1)
35
46
  i18n (1.14.1)
36
47
  concurrent-ruby (~> 1.0)
37
- json (2.6.3)
38
- jsonpath (1.1.3)
48
+ json (2.7.1)
49
+ jsonpath (1.1.5)
39
50
  multi_json
40
51
  language_server-protocol (3.17.0.3)
41
52
  method_source (1.0.0)
42
- minitest (5.18.1)
53
+ minitest (5.20.0)
43
54
  multi_json (1.15.0)
55
+ mutex_m (0.2.0)
44
56
  parallel (1.23.0)
45
- parser (3.2.2.3)
57
+ parser (3.2.2.4)
46
58
  ast (~> 2.4.1)
47
59
  racc
48
60
  pry (0.14.2)
@@ -51,12 +63,12 @@ GEM
51
63
  pry-byebug (3.10.1)
52
64
  byebug (~> 11.0)
53
65
  pry (>= 0.13, < 0.15)
54
- public_suffix (5.0.1)
55
- racc (1.7.1)
66
+ public_suffix (5.0.4)
67
+ racc (1.7.3)
56
68
  rainbow (3.1.1)
57
- rake (13.0.6)
58
- regexp_parser (2.8.1)
59
- rexml (3.2.5)
69
+ rake (13.1.0)
70
+ regexp_parser (2.8.3)
71
+ rexml (3.2.6)
60
72
  rspec (3.12.0)
61
73
  rspec-core (~> 3.12.0)
62
74
  rspec-expectations (~> 3.12.0)
@@ -66,36 +78,36 @@ GEM
66
78
  rspec-expectations (3.12.3)
67
79
  diff-lcs (>= 1.2.0, < 2.0)
68
80
  rspec-support (~> 3.12.0)
69
- rspec-mocks (3.12.5)
81
+ rspec-mocks (3.12.6)
70
82
  diff-lcs (>= 1.2.0, < 2.0)
71
83
  rspec-support (~> 3.12.0)
72
84
  rspec-support (3.12.1)
73
85
  rspec_junit_formatter (0.6.0)
74
86
  rspec-core (>= 2, < 4, != 2.12.0)
75
- rubocop (1.54.0)
87
+ rubocop (1.58.0)
76
88
  json (~> 2.3)
77
89
  language_server-protocol (>= 3.17.0)
78
90
  parallel (~> 1.10)
79
- parser (>= 3.2.2.3)
91
+ parser (>= 3.2.2.4)
80
92
  rainbow (>= 2.2.2, < 4.0)
81
93
  regexp_parser (>= 1.8, < 3.0)
82
94
  rexml (>= 3.2.5, < 4.0)
83
- rubocop-ast (>= 1.28.0, < 2.0)
95
+ rubocop-ast (>= 1.30.0, < 2.0)
84
96
  ruby-progressbar (~> 1.7)
85
97
  unicode-display_width (>= 2.4.0, < 3.0)
86
- rubocop-ast (1.29.0)
98
+ rubocop-ast (1.30.0)
87
99
  parser (>= 3.2.1.0)
88
- rubocop-capybara (2.18.0)
100
+ rubocop-capybara (2.19.0)
89
101
  rubocop (~> 1.41)
90
- rubocop-factory_bot (2.23.1)
102
+ rubocop-factory_bot (2.24.0)
91
103
  rubocop (~> 1.33)
92
- rubocop-performance (1.18.0)
104
+ rubocop-performance (1.19.1)
93
105
  rubocop (>= 1.7.0, < 2.0)
94
106
  rubocop-ast (>= 0.4.0)
95
107
  rubocop-rake (0.6.0)
96
108
  rubocop (~> 1.0)
97
- rubocop-rspec (2.22.0)
98
- rubocop (~> 1.33)
109
+ rubocop-rspec (2.25.0)
110
+ rubocop (~> 1.40)
99
111
  rubocop-capybara (~> 2.17)
100
112
  rubocop-factory_bot (~> 2.22)
101
113
  ruby-progressbar (1.13.0)
@@ -111,8 +123,8 @@ GEM
111
123
  simplecov_json_formatter (0.1.4)
112
124
  tzinfo (2.0.6)
113
125
  concurrent-ruby (~> 1.0)
114
- unicode-display_width (2.4.2)
115
- webmock (3.18.1)
126
+ unicode-display_width (2.5.0)
127
+ webmock (3.19.1)
116
128
  addressable (>= 2.8.0)
117
129
  crack (>= 0.3.2)
118
130
  hashdiff (>= 0.4.0, < 2.0.0)
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, 3.2
16
- - Rails 6.0, 6.1, 7.0
15
+ - Ruby 3.0, 3.1, 3.2
16
+ - Rails 6.1, 7.0
17
17
 
18
18
  ## Installation
19
19
 
@@ -52,7 +52,7 @@ class ExampleApiClient < MyApiClient::Base
52
52
 
53
53
  # GET https://example.com/v1/users
54
54
  #
55
- # @return [Sawyer::Response] HTTP response parameter
55
+ # @return [Sawyer::Resource] HTTP resource parameter
56
56
  def get_users
57
57
  get 'users', headers: headers, query: { key: 'value' }
58
58
  end
@@ -60,7 +60,7 @@ class ExampleApiClient < MyApiClient::Base
60
60
  # POST https://example.com/v1/users
61
61
  #
62
62
  # @param name [String] Username which want to create
63
- # @return [Sawyer::Response] HTTP response parameter
63
+ # @return [Sawyer::Resource] HTTP resource parameter
64
64
  def post_user(name:)
65
65
  post 'users', headers: headers, body: { name: name }
66
66
  end
@@ -76,7 +76,7 @@ class ExampleApiClient < MyApiClient::Base
76
76
  end
77
77
 
78
78
  api_clinet = ExampleApiClient.new(access_token: 'access_token')
79
- api_clinet.get_users #=> #<Sawyer::Response>
79
+ api_clinet.get_users #=> #<Sawyer::Resource>
80
80
  ```
81
81
 
82
82
  クラス定義の最初に記述される `endpoint` にはリクエスト URL の共通部分を定義します。後述の各メソッドで後続の path を定義しますが、上記の例だと `get 'users'` と定義すると、 `GET https://example.com/v1/users` というリクエストが実行されます。
@@ -416,7 +416,7 @@ class GetUsersApiClient < ExampleApiClient
416
416
 
417
417
  # GET https://example.com/users
418
418
  #
419
- # @return [Sawyer::Response] HTTP response parameter
419
+ # @return [Sawyer::Resource] HTTP resource parameter
420
420
  def request
421
421
  get 'users', query: { key: 'value' }, headers: headers
422
422
  end
@@ -428,7 +428,7 @@ class PostUserApiClient < ExampleApiClient
428
428
  # POST https://example.com/users
429
429
  #
430
430
  # @param name [String] Username which want to create
431
- # @return [Sawyer::Response] HTTP response parameter
431
+ # @return [Sawyer::Resource] HTTP resource parameter
432
432
  def request(name:)
433
433
  post 'users', headers: headers, body: { name: name }
434
434
  end
data/README.md CHANGED
@@ -16,8 +16,8 @@ It is supposed to be used in Ruby on Rails, but it is made to work in other envi
16
16
 
17
17
  ## Supported Versions
18
18
 
19
- - Ruby 2.7, 3.0, 3.1, 3.2
20
- - Rails 6.0, 6.1, 7.0
19
+ - Ruby 3.0, 3.1, 3.2
20
+ - Rails 6.1, 7.0
21
21
 
22
22
  ## Installation
23
23
 
@@ -56,7 +56,7 @@ class ExampleApiClient < MyApiClient::Base
56
56
 
57
57
  # GET https://example.com/v1/users
58
58
  #
59
- # @return [Sawyer::Response] HTTP response parameter
59
+ # @return [Sawyer::Resource] HTTP resource parameter
60
60
  def get_users
61
61
  get 'users', headers: headers, query: { key: 'value' }
62
62
  end
@@ -64,7 +64,7 @@ class ExampleApiClient < MyApiClient::Base
64
64
  # POST https://example.com/v1/users
65
65
  #
66
66
  # @param name [String] Username which want to create
67
- # @return [Sawyer::Response] HTTP response parameter
67
+ # @return [Sawyer::Resource] HTTP resource parameter
68
68
  def post_user(name:)
69
69
  post 'users', headers: headers, body: { name: name }
70
70
  end
@@ -80,7 +80,7 @@ class ExampleApiClient < MyApiClient::Base
80
80
  end
81
81
 
82
82
  api_clinet = ExampleApiClient.new(access_token: 'access_token')
83
- api_clinet.get_users #=> #<Sawyer::Response>
83
+ api_clinet.get_users #=> #<Sawyer::Resource>
84
84
  ```
85
85
 
86
86
  The `endpoint` defines the intersection of the request URL. Each method described below defines a subsequent path. In the above example, `get 'users'` will request to `GET https://example.com/v1/users`.
@@ -5,9 +5,18 @@ require_relative 'application_api_client'
5
5
  # An usage example of the `my_api_client`.
6
6
  # See also: my_api/app/controllers/pagination_controller.rb
7
7
  class MyPaginationApiClient < ApplicationApiClient
8
+ # Paging with JSONPath
8
9
  # GET pagination?page=1
9
- def pagination
10
- pget 'pagination', paging: '$.links.next', headers: headers, query: { page: 1 }
10
+ def paging_with_jsonpath
11
+ pget 'pagination', headers: headers, query: { page: 1 }, paging: '$.links.next'
12
+ end
13
+
14
+ # Paging with Proc
15
+ # GET pagination?page=1
16
+ def paging_with_proc
17
+ pget 'pagination', headers: headers, query: { page: 1 }, paging: lambda { |response|
18
+ response.data.links.next
19
+ }
11
20
  end
12
21
 
13
22
  private
@@ -23,7 +23,7 @@ module MyApiClient
23
23
  # Some network error
24
24
  def initialize(params = nil, original_error = nil)
25
25
  @original_error = original_error
26
- super params, original_error&.message
26
+ super(params, original_error&.message)
27
27
  end
28
28
 
29
29
  # Returns contents as string for to be readable for human
@@ -16,7 +16,7 @@ module MyApiClient
16
16
  # The error description
17
17
  def initialize(params = nil, error_message = nil)
18
18
  @params = params
19
- super error_message
19
+ super(error_message)
20
20
  end
21
21
 
22
22
  # Returns contents as string for to be readable for human
@@ -20,10 +20,18 @@ module MyApiClient
20
20
  # @param body [Hash, nil]
21
21
  # Request body. You should not specify it when use GET method.
22
22
  # @return [Sawyer::Resource]
23
- # Response body instance.
23
+ # Response body instance if the block is not given.
24
+ # @yield
25
+ # Process the response body with the given block.
26
+ # @yieldparam response [Sawyer::Response]
27
+ # Response instance.
28
+ # @yieldreturn [Object]
29
+ # The block result.
30
+ # @return [Object]
31
+ # Whatever the block returns if the block is given.
24
32
  def #{http_method}(pathname, headers: nil, query: nil, body: nil)
25
33
  response = call(:_request_with_relative_uri, :#{http_method}, pathname, headers, query, body)
26
- response.data
34
+ block_given? ? yield(response) : response.data
27
35
  end
28
36
  METHOD
29
37
  end
@@ -9,7 +9,7 @@ module MyApiClient
9
9
  #
10
10
  # @param pathname [String]
11
11
  # Pathname of the request target URL. It's joined with the defined by `endpoint`.
12
- # @param paging [String]
12
+ # @param paging [String, Proc]
13
13
  # Specify the pagination link path included in the response body as JsonPath expression
14
14
  # @param headers [Hash, nil]
15
15
  # Request headers.
@@ -25,7 +25,7 @@ module MyApiClient
25
25
  loop do
26
26
  y << response.data
27
27
 
28
- next_uri = JsonPath.new(paging).first(response.body)
28
+ next_uri = get_next_url(paging, response)
29
29
  break if next_uri.blank?
30
30
 
31
31
  response = call(:_request_with_absolute_uri, :get, next_uri, headers, nil)
@@ -34,6 +34,27 @@ module MyApiClient
34
34
  end
35
35
 
36
36
  alias pget pageable_get
37
+
38
+ private
39
+
40
+ # Returns the next URL for pagination
41
+ #
42
+ # @param paging [String, Proc]
43
+ # Specify the pagination link path included in the response body as JsonPath expression
44
+ # @param response [MyApiClient::Response]
45
+ # The response object
46
+ # @return [String, nil]
47
+ # The next URL for pagination
48
+ def get_next_url(paging, response)
49
+ case paging
50
+ when String
51
+ JsonPath.new(paging).first(response.body)
52
+ when Proc
53
+ paging.call(response)
54
+ else
55
+ raise ArgumentError, "Invalid paging argument: #{paging}"
56
+ end
57
+ end
37
58
  end
38
59
  end
39
60
  end
@@ -144,6 +144,7 @@ module MyApiClient
144
144
  status: status_code.presence || 400,
145
145
  headers: {},
146
146
  data: stub_as_resource(params),
147
+ body: params.to_json,
147
148
  timing: 0.123
148
149
  )
149
150
  end
@@ -5,8 +5,8 @@ module MyApiClient
5
5
  class ServiceAbstract
6
6
  private_class_method :new
7
7
 
8
- def self.call(**args, &block)
9
- new(**args, &block).send(:call)
8
+ def self.call(...)
9
+ new(...).send(:call)
10
10
  end
11
11
 
12
12
  # private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyApiClient
4
- VERSION = '0.26.0'
4
+ VERSION = '1.0.0'
5
5
  end
data/my_api/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.0.6
data/my_api/Gemfile CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'jets', '~> 4.0.1'
5
+ gem 'jets', '~> 4.0.10'
6
6
 
7
7
  gem 'dynomite'
8
8
 
9
9
  # See: https://github.com/boltops-tools/jets/issues/523
10
- gem 'nokogiri', '~> 1.15.2'
10
+ gem 'nokogiri', '~> 1.15.5'
11
11
 
12
12
  # development and test groups are not bundled as part of the deployment
13
13
  group :development, :test do