Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Faraday 2.x #7

Merged
merged 1 commit into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [0.2.4] - 2022-03-29

- Add support for Faraday 2.x

## [0.2.3] - 2021-11-12

- Handle "uncountable" responses (i.e. those without a Total-Count or Total-Pages header)
Expand Down
36 changes: 19 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
PATH
remote: .
specs:
zaikio-client-helpers (0.2.3)
faraday
zaikio-client-helpers (0.2.4)
faraday (>= 1, < 3)
multi_json
spyke
spyke (~> 6)

GEM
remote: https://rubygems.org/
specs:
activemodel (6.1.4.1)
activesupport (= 6.1.4.1)
activesupport (6.1.4.1)
activemodel (7.0.2.3)
activesupport (= 7.0.2.3)
activesupport (7.0.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.9)
concurrent-ruby (1.1.10)
crack (0.4.5)
rexml
faraday (1.8.0)
faraday (1.10.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.1)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
multipart-post (>= 1.2, < 3)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.0.3)
multipart-post (>= 1.2, < 3)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
hashdiff (1.0.1)
i18n (1.8.11)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.4)
minitest (5.15.0)
multi_json (1.15.0)
multipart-post (2.1.1)
pry (0.13.1)
Expand All @@ -62,7 +65,7 @@ GEM
rake (13.0.3)
rexml (3.2.5)
ruby2_keywords (0.0.5)
spyke (6.0.0)
spyke (6.1.3)
Copy link
Contributor Author

@nickcampbell18 nickcampbell18 Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately spyke is holding us back on 1.x - see balvig/spyke#133 - but this will work when that is eventually updated.

activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
addressable (>= 2.5.2)
Expand All @@ -75,7 +78,6 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
zeitwerk (2.5.1)

PLATFORMS
x86_64-darwin-19
Expand All @@ -91,4 +93,4 @@ DEPENDENCIES
zaikio-client-helpers!

BUNDLED WITH
2.2.30
2.3.6
8 changes: 7 additions & 1 deletion lib/zaikio/client/helpers/json_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
require "multi_json"

module Zaikio::Client::Helpers
class JSONParser < Faraday::Response::Middleware
superclass = if Gem.loaded_specs["faraday"].version >= Gem::Version.new("2.0")
Faraday::Middleware
else
Faraday::Response::Middleware
end

JSONParser = Class.new(superclass) do
def on_complete(env)
case env.status
when 404 then raise Spyke::ResourceNotFound.new(nil, url: env.url)
Expand Down
8 changes: 7 additions & 1 deletion lib/zaikio/client/helpers/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ module Pagination

METADATA_KEY = :pagination

superclass = if Gem.loaded_specs["faraday"].version >= Gem::Version.new("2.0")
Faraday::Middleware
else
Faraday::Response::Middleware
end

# Faraday Middleware for extracting any pagination headers into the a top-level
# :metadata hash, or the env hash for non-JSON responses.
#
Expand All @@ -22,7 +28,7 @@ module Pagination
# response = conn.get("/")
# response.env[METADATA_KEY]
# #=> {total_count: 4, total_pages: 1, current_page: 1}
class FaradayMiddleware < Faraday::Response::Middleware
FaradayMiddleware = Class.new(superclass) do
def on_complete(env)
@env = env

Expand Down
2 changes: 1 addition & 1 deletion lib/zaikio/client/helpers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Zaikio
module Client
module Helpers
VERSION = "0.2.3"
VERSION = "0.2.4"
end
end
end
4 changes: 2 additions & 2 deletions zaikio-client-helpers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Gem::Specification.new do |spec|
"CHANGELOG.md"]
spec.require_paths = ["lib"]

spec.add_dependency "faraday"
spec.add_dependency "faraday", ">= 1", "< 3"
spec.add_dependency "multi_json"
spec.add_dependency "spyke"
spec.add_dependency "spyke", "~> 6"

spec.add_development_dependency "vcr"
spec.add_development_dependency "webmock"
Expand Down