From 1e94653ec59dc9927a8f948594118ce82d548db9 Mon Sep 17 00:00:00 2001 From: Dewey Garwood Date: Sun, 13 Aug 2023 09:10:02 -0600 Subject: [PATCH] Upgrade faraday to 2.x (#33) * move development dependencies to gemspec * upgrade faraday to >= 2.0.1 this removes faraday_middleware (due to faraday 2.0 changes), adds faraday-multipart and updates related class references. additionally, faraday's minimum version is now set at 2.0.1 per https://github.com/lostisland/faraday/blob/main/UPGRADING.md to avoid missing net_http issues --- CHANGELOG.md | 1 + Gemfile | 12 ------------ lib/open-weather-ruby-client.rb | 3 ++- lib/open_weather/connection.rb | 13 ++++++------- lib/open_weather/raise_error.rb | 2 +- open-weather-ruby-client.gemspec | 14 ++++++++++++-- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8adae85..e08a2e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### 0.3.1 (Next) * Your contribution here. +* [#33](https://github.com/dblock/open-weather-ruby-client/pull/33): Update faraday to 2.x - [@dgarwood](https://github.com/dgarwood). ### 0.3.0 (2023/03/25) diff --git a/Gemfile b/Gemfile index 0a417e0..f7200f1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,15 +3,3 @@ source 'http://rubygems.org' gemspec - -group :development, :test do - gem 'danger-changelog', '~> 0.4.2' - gem 'danger-toc', '~> 0.1.3' - gem 'dotenv' - gem 'pry' - gem 'rake' - gem 'rspec' - gem 'rubocop', '~> 1.48.1' - gem 'vcr' - gem 'webmock' -end diff --git a/lib/open-weather-ruby-client.rb b/lib/open-weather-ruby-client.rb index a2cab32..41807fe 100644 --- a/lib/open-weather-ruby-client.rb +++ b/lib/open-weather-ruby-client.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require 'faraday' -require 'faraday_middleware' +require 'faraday/multipart' + require 'json' require 'logger' require 'hashie' diff --git a/lib/open_weather/connection.rb b/lib/open_weather/connection.rb index cdfaa80..74965bc 100644 --- a/lib/open_weather/connection.rb +++ b/lib/open_weather/connection.rb @@ -26,13 +26,12 @@ def connection request_options[:open_timeout] = open_timeout if open_timeout options[:request] = request_options if request_options.any? - ::Faraday::Connection.new(endpoint, options) do |connection| - connection.use ::Faraday::Request::Multipart - connection.use ::Faraday::Request::UrlEncoded - connection.use ::OpenWeather::Response::RaiseError - connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/ - connection.response :logger, logger if logger - connection.adapter ::Faraday.default_adapter + Faraday.new(endpoint, options) do |f| + f.request :multipart + f.request :url_encoded + f.use ::OpenWeather::Response::RaiseError + f.response :json, content_type: /\bjson$/ + f.response :logger, logger if logger end end end diff --git a/lib/open_weather/raise_error.rb b/lib/open_weather/raise_error.rb index 14aa0e7..6677953 100644 --- a/lib/open_weather/raise_error.rb +++ b/lib/open_weather/raise_error.rb @@ -2,7 +2,7 @@ module OpenWeather module Response - class RaiseError < ::Faraday::Response::Middleware + class RaiseError < ::Faraday::Response::RaiseError def on_complete(env) case env[:status] when 404 diff --git a/open-weather-ruby-client.gemspec b/open-weather-ruby-client.gemspec index d12db4c..35cfc19 100644 --- a/open-weather-ruby-client.gemspec +++ b/open-weather-ruby-client.gemspec @@ -17,7 +17,17 @@ Gem::Specification.new do |s| s.licenses = ['MIT'] s.summary = 'OpenWeather API Ruby client.' s.add_dependency 'activesupport' - s.add_dependency 'faraday', '>= 1.0.0' - s.add_dependency 'faraday_middleware' + s.add_dependency 'faraday', '>= 2.0.1' + s.add_dependency 'faraday-multipart' s.add_dependency 'hashie' + + s.add_development_dependency 'danger-changelog', '~> 0.4.2' + s.add_development_dependency 'danger-toc', '~> 0.1.3' + s.add_development_dependency 'dotenv' + s.add_development_dependency 'pry' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' + s.add_development_dependency 'rubocop', '~> 1.48.1' + s.add_development_dependency 'vcr' + s.add_development_dependency 'webmock' end