-
#1048 Support lazy evaluation for request headers and body parameters (@ryz310) The API client allows lazy evaluation for request headers and body parameters. For example, a time-limited token can be issued immediately before the request.
class ExampleApiClient < MyApiClient::Base def get_users get 'users', headers: headers, query: { key: 'value' } end private def headers lambda do new_access_token = issue_new_access_token! { 'Content-Type': 'application/json;charset=UTF-8', 'Authorization': "Bearer #{new_access_token}", } end end end
- #1049 Update supporting ruby and rails versions (@ryz310) Support Ruby 3.3, Rails 7.1 and 7.2 End of supporting Ruby 3.0 👋
- #982 Bump rspec from 3.12.0 to 3.13.0 (@ryz310)
- #1006 Bump rake from 13.2.0 to 13.2.1 (@ryz310)
- #1018 Bump bugsnag from 6.26.4 to 6.27.0 (@ryz310)
- #1020 Bump webmock from 3.23.0 to 3.23.1 (@ryz310)
- #1031 Bump rubocop-performance from 1.21.0 to 1.21.1 (@ryz310)
- #1032 Bump bugsnag from 6.27.0 to 6.27.1 (@ryz310)
- #1043 Bump rexml from 3.3.3 to 3.3.6 (@ryz310)
- #1045 Bump activesupport from 7.1.3.4 to 7.1.4 (@ryz310)
- #1046 Bump faraday from 2.10.1 to 2.11.0 (@ryz310)
- #1047 Bump yard from 0.9.36 to 0.9.37 (@ryz310)
- #970 Fix handling when the error changes after a retry (@ashimomura)
- #965 Bump faraday from 2.7.12 to 2.8.1 (@ryz310)
- #972 Bump rubocop-performance from 1.19.1 to 1.20.2 (@ryz310)
# Example of using a Proc with pageable_get
pget 'api/example', headers:, query:, paging: ->(response) {
# Custom logic to generate the next URL
}
api_clinet = ExampleApiClient.new(access_token: 'access_token')
# You can retrieve sawyer response with return value
api_clinet.get_users #=> #<Sawyer::Resource>
# You can retrieve sawyer response with block
api_clinet.get_users do |response|
response #=> #<Sawyer::Response>
response.headers #=> #<Hash>
response.data #=> #<Sawyer::Resource>
end
- #919 Bump bugsnag from 6.25.2 to 6.26.0 (@ryz310)
- #929 Bump webmock from 3.19.0 to 3.19.1 (@ryz310)
- #934 Bump rubocop-performance from 1.19.0 to 1.19.1 (@ryz310)
- #933 Bump faraday from 2.7.10 to 2.7.11 (@ryz310)
- #939 Bump jsonpath from 1.1.4 to 1.1.5 (@ryz310)
- #942 Bump rake from 13.0.6 to 13.1.0 (@ryz310)
- #945 Bump activesupport from 7.1.1 to 7.1.2 (@ryz310)
- #889 Bump yard from 0.9.32 to 0.9.34 (@ryz310)
- #893 Bump jsonpath from 1.1.2 to 1.1.3 (@ryz310)
- #897 Bump rubocop-performance from 1.17.1 to 1.18.0 (@ryz310)
- #912 Bump activesupport from 7.0.5.1 to 7.0.6 (@ryz310)
- #913 Bump faraday from 2.7.8 to 2.7.9 (@ryz310)
- #809 Style/RedundantConstantBase-20221208233100 (@ryz310)
- #812 Lint/RedundantCopDisableDirective-20221211233112 (@ryz310)
- #862 Performance/StringInclude-20230206233100 (@ryz310)
- #830 ryz310/dependabot/bundler/simplecov-0.22.0 (@ryz310)
- #858 Bump faraday from 2.7.3 to 2.7.4 (@ryz310)
- #859 Bump activesupport from 7.0.4.1 to 7.0.4.2 (@ryz310)
- #863 Bump bugsnag from 6.25.1 to 6.25.2 (@ryz310)
- #757 RSpec/Rails/HaveHttpStatus-20220712233101 (@ryz310)
- #777 RSpec/ClassCheck-20220912233101 (@ryz310)
- #790 RSpec/Rails/InferredSpecType-20221023233100 (@ryz310)
- #758 ryz310/dependabot/bundler/rubocop-performance-1.14.3 (@ryz310)
- #772 Bump pry-byebug from 3.10.0 to 3.10.1 (@ryz310)
- #773 Bump webmock from 3.17.1 to 3.18.1 (@ryz310)
- #775 Bump activesupport from 7.0.3.1 to 7.0.4 (@ryz310)
- #778 Bump rspec_junit_formatter from 0.5.1 to 0.6.0 (@ryz310)
- #780 Bump faraday from 2.5.2 to 2.6.0 (@ryz310)
- #791 Bump rspec from 3.11.0 to 3.12.0 (@ryz310)
- #698 RSpec/VerifiedDoubleReference-20220419233100 (@ryz310)
- #700 Style/FetchEnvVar-20220421233101 (@ryz310)
- #728 Re-generate .rubocop_todo.yml with RuboCop v1.30.1 (@ryz310)
- #658 ryz310/dependabot/bundler/rspec_junit_formatter-0.5.1 (@ryz310)
- #666 Bump bugsnag from 6.24.1 to 6.24.2 (@ryz310)
- #667 Bump rubocop-rspec from 2.7.0 to 2.8.0 (@ryz310)
- #671 Bump rspec from 3.10.0 to 3.11.0 (@ryz310)
- #678 Bump faraday from 1.10.0 to 2.2.0 (@ryz310)
- #702 Bump jsonpath from 1.1.0 to 1.1.2 (@ryz310)
- #715 Bump activesupport from 7.0.2.4 to 7.0.3 (@ryz310)
- #726 Bump yard from 0.9.27 to 0.9.28 (@ryz310)
- #729 Bump rubocop-performance from 1.14.1 to 1.14.2 (@ryz310)
- #730 Bump sawyer from 0.9.1 to 0.9.2 (@ryz310)
- #617 RSpec/ExcessiveDocstringSpacing-20210922233114 (@ryz310)
- #623 Security/IoMethods-20210930233112 (@ryz310)
- #624 Re-generate .rubocop_todo.yml with RuboCop v1.22.1 (@ryz310)
- #638 Gemspec/RequireMFA-20211115233105 (@ryz310)
- #576 Bump bugsnag from 6.21.0 to 6.22.1 (@ryz310)
- #612 ryz310/dependabot/bundler/faraday-1.8.0 (@ryz310)
- #625 ryz310/dependabot/bundler/bugsnag-6.24.0 (@ryz310)
- #635 Bump rubocop-performance from 1.11.5 to 1.12.0 (@ryz310)
- #636 ryz310/dependabot/bundler/rubocop-rspec-2.6.0 (@ryz310)
- #639 Bump yard from 0.9.26 to 0.9.27 (@ryz310)
- #640 Bump bugsnag from 6.24.0 to 6.24.1 (@ryz310)
- #641 Bump activesupport from 6.1.4.1 to 6.1.4.2 (@ryz310)
- #644 ryz310/dependabot/bundler/activesupport-6.1.4.4 (@ryz310)
- #523 Layout/LineEndStringConcatenationIndentation-20210629233103 (@ryz310)
- #562 Re-generate .rubocop_todo.yml with RuboCop v1.18.4 (@ryz310)
- #509 Fix the problem of mimemagic gem dependency (@ryz310)
- #559 Fix gemfiles compatibility (@ryz310)
- #414 Style/StringConcatenation-20210106033935 (@ryz310)
- #416 Style/HashTransformValues-20210106233116 (@ryz310)
- #433 Lint/SymbolConversion-20210128233108 (@ryz310)
- #452 Re-generate .rubocop_todo.yml with RuboCop v1.11.0 (@ryz310)
- #303 Change the duration format to milliseconds (@ryz310)
- #308 Add testing for api client generators (@ryz310)
- #311 Style/GlobalStdStream-20200906233350 (@ryz310)
- #312 Style/StringConcatenation-20200907233020 (@ryz310)
- #313 Style/HashTransformValues-20200908233016 (@ryz310)
- #316 Layout/EmptyLinesAroundAttributeAccessor-20200909233021 (@ryz310)
- #320 Re-generate .rubocop_todo.yml with RuboCop v0.91.0 (@ryz310)
- #256 Performance/StartWith-20200523233027 (@ryz310)
- #268 Lint/RedundantCopDisableDirective-20200622233019 (@ryz310)
- #289 Re-generate .rubocop_todo.yml with RuboCop v0.89.1 (@ryz310)
- #293 RSpec/LeadingSubject-20200817233022 (@ryz310)
Until now, using with
or block
in error_handling
did not automatically raise an exception, but will now always raise an exception when an error is detected.
You can specify raising error class with raise
option.
Before
error_handling json: { '$.errors.code': 10..19 }, with: :my_error_handling
def my_error_handling
# Executes this method when an error is detected.
# No exception is raised. You can raise an error if necessary.
end
error_handling status_code: 500..599 do |_params, logger|
# Executes this block when an error is detected.
# No exception is raised. You can raise an error if necessary.
end
After
error_handling json: { '$.errors.code': 10..19 }, with: :my_error_handling
def my_error_handling
# Executes this method when an error is detected.
# And then raise `MyApiClient::Error`.
end
error_handling status_code: 500..599 do |params, logger|
# Executes this block when an error is detected.
# And then raise `MyApiClient::Error`.
end
Until now, you needed define all error_handling
or retry_on
yourself. But will now some error_handling
and retry_on
are prepared as default.
You can check default error_handling
or retry_on
here.
See: https://github.com/ryz310/my_api_client/blob/master/lib/my_api_client/default_error_handlers.rb
-
#220 Pageable HTTP request (@ryz310)
-
Add
#pageable_get
method (alias:#pget
) -
For example:
-
API client definition
class MyPaginationApiClient < ApplicationApiClient endpoint 'https://example.com/v1' # GET pagination?page=1 def pagination pageable_get 'pagination', paging: '$.links.next', headers: headers, query: { page: 1 } end private def headers { 'Content-Type': 'application/json;charset=UTF-8' } end end
-
The pagination API response
{ "links": { "next": "https://example.com/pagination?page=3", "previous": "https://example.com/pagination?page=1" }, "page": 2 }
-
Usage
api_clinet = MyPaginationApiClient.new api_clinet.pagination.each do |response| # Do something. end p = api_clinet.pagination p.next # => 1st page result p.next # => 2nd page result p.next # => 3rd page result
-
-
- #211 Integration testing using the jets framework (@ryz310)
- #213 Add status API to integration testing (@ryz310)
- #214 Add error API to integration testing (@ryz310)
- #215 Update the REST API to enhance integration testing (@ryz310)
- #179 Change the "with" option structure (@ryz310)
- #206 Rebuild api request processing (@ryz310)
- #207 Fix offending codes (@ryz310)
before
I, [2020-02-02T15:26:53.788092 #93220] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts`: "Start" I, [2020-02-02T15:26:55.760452 #93220] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts`: "Duration 1.97186 sec" I, [2020-02-02T15:26:55.760739 #93220] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts`: "Success (200)"
after
Shows URL with query strings.
I, [2020-02-02T15:20:47.471040 #90870] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts?page=1&per_page=100&q=user%3Aryosuke_sato+category%3Aunsorted`: "Start" I, [2020-02-02T15:20:49.516099 #90870] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts?page=1&per_page=100&q=user%3Aryosuke_sato+category%3Aunsorted`: "Duration 2.034907 sec" I, [2020-02-02T15:20:49.516391 #90870] INFO -- : API request `GET https://api.esa.io/v1/teams/feedforce/posts?page=1&per_page=100&q=user%3Aryosuke_sato+category%3Aunsorted`: "Success (200)"
before
request_params.metadata # => # { # line: 'GET path/to/resource', # headers: { 'Content-Type': 'application/json; charset=utf-8' }, # query: { key: 'value' } # }after
The
#metadata
does not includequery
key and then includes full URL intoline
value.request_params.metadata # => # { # line: 'GET https://example.com/path/to/resource?key=value', # headers: { 'Content-Type': 'application/json; charset=utf-8' } # }
- #205 Re-generate .rubocop_todo.yml with RuboCop v0.80.0 (@ryz310)
- #210 Re-generate .rubocop_todo.yml with RuboCop v0.80.1 (@ryz310)
- #173 Avoid sleep on testing (@ryz310)
- #175 Verify arguments on error handling definition (@ryz310)
- #176 Provides a syntax sugar of
retry_on
onerror_handling
(@ryz310)
- #158 Re-generate .rubocop_todo.yml with RuboCop v0.78.0 (@ryz310)
- #168 Re-generate .rubocop_todo.yml with RuboCop v0.79.0 (@ryz310)
- #136 Re-generate .rubocop_todo.yml with RuboCop v0.76.0 (@ryz310)
- #148 Re-generate .rubocop_todo.yml with RuboCop v0.77.0 (@ryz310)
- Ignore error handling when using request to matcher (#130)
- Fix
be_handled_as_an_error
description (#131)
- Support
retry_on
testing at shoulda matcher (#127)
- Shoulda-matchers for my_api_client (#124)
- Fix endpoint parsing when including port number (#117)
- Fixes: Can't request to URL which includes port numbert (#116)
-
Re-generate .rubocop_todo.yml with RuboCop v0.74.0 (#100)
-
Re-generate .rubocop_todo.yml with RuboCop v0.75.0 (#112)
-
Support Rails 6.0 (#101)
-
deprecated/my_api_client_stub (#102)
- Fix forbid nil option (#97) Breaking Changes
- Forbid nil response (#93)
- RSpec/DescribedClass-20190723233015 (#92)
- Allow method calling on error handling (#89)
- Require sawyer gem v0.8.2 over (#88)
- Modify the generator to be simple (#82)
- Bump yard from
0.9.19
to0.9.20
(#72)- Fix a security risk
- New stubbing helper (#65)
stub_api_client_all(
ExampleApiClient,
get_user: { response: { id: 1 } }, # Returns an arbitrary response.
post_users: { id: 1 }, # You can ommit `response` keyword.
patch_user: ->(params) { { id: params[:id] } }, # Returns calculated result as response.
delete_user: { raise: MyApiClient::ClientError } # Raises an arbitrary error.
)
response = ExampleApiClient.new.get_user(id: 123)
response.id # => 1
api_client = stub_api_client(
ExampleApiClient,
get_user: { response: { id: 1 } }, # Returns an arbitrary response.
post_users: { id: 1 }, # You can ommit `response` keyword.
patch_user: ->(params) { { id: params[:id] } }, # Returns calculated result as response.
delete_user: { raise: MyApiClient::ClientError } # Raises an arbitrary error.
)
response = api_client.get_user(id: 123)
response.id # => 1
- Initialize sawyer agent before logger initialization (#60)
- Fixes: The URL included in the logger is incomplete (#53)
- Fix parsing error if given text/html response (#61)
- Improvement test coverage (#55)
- Fix unsupported data for the Bugsnag breadcrumbs (#50)
- Support bugsnag breadcrumb (#41)
- Use CircleCI Orbs (#43)
- Improvement for endpoint (#35)
- Add requirements for
$ bin/console
(#31)
- Update RuboCop v0.70.0 -> v0.71.0 (#34)
- Provide test helper for RSpec (#28)
- Support Bugsnag metadata (#22)
- Support activesupport before v5.2.0 (#17)
- Fix wrong variable name (#13)
- Fix wrong method name (#10)
- Fix typo (#6)
- The first release 🎉