Skip to content

Commit

Permalink
upgrade faraday to >= 2.0.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dgarwood committed Jun 30, 2023
1 parent b5292bb commit ec8f128
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
3 changes: 2 additions & 1 deletion lib/open-weather-ruby-client.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require 'faraday'
require 'faraday_middleware'
require 'faraday/multipart'

require 'json'
require 'logger'
require 'hashie'
Expand Down
13 changes: 6 additions & 7 deletions lib/open_weather/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions open-weather-ruby-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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'
Expand Down

0 comments on commit ec8f128

Please sign in to comment.