Skip to content

Commit

Permalink
Merge pull request #131 from mkmn/compatible_faraday_v2
Browse files Browse the repository at this point in the history
Compatible Faraday v2
  • Loading branch information
raszi authored Jan 8, 2023
2 parents 11a8d62 + fe2dc4f commit 7c1b5b1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
strategy:
matrix:
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2']
gemfile: [faraday_1, faraday_2]

env:
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
Exclude:
- 'bin/**/*'
- 'vendor/**/*'
Expand Down
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ PATH
remote: .
specs:
mrkt (1.2.1)
faraday (>= 1, < 3)
faraday_middleware (~> 1.0)
faraday (>= 1.10, < 3)
faraday-multipart

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -40,8 +40,6 @@ GEM
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.0)
faraday (~> 1.0)
gem-release (2.2.2)
hashdiff (1.0.1)
method_source (1.0.0)
Expand Down
11 changes: 11 additions & 0 deletions gemfiles/faraday_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# require v1.10 or higher.
# Because gem needs JSON middleware.
#
# see: https://github.com/lostisland/faraday/releases/tag/v1.10.0
gem 'faraday', '~> 1.10'

eval_gemfile File.expand_path('../Gemfile', __dir__)
7 changes: 7 additions & 0 deletions gemfiles/faraday_2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'faraday', '~> 2'

eval_gemfile File.expand_path('../Gemfile', __dir__)
2 changes: 1 addition & 1 deletion lib/mrkt/concerns/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def init_connection
conn.request :url_encoded

conn.response :logger, @logger, (@log_options || {}) if @debug
conn.response :mkto, content_type: /\bjson$/
conn.response :mkto, content_type: /\bjson$/, parser_options: { symbolize_names: true }

conn.options.timeout = @options[:read_timeout] if @options.key?(:read_timeout)
conn.options.open_timeout = @options[:open_timeout] if @options.key?(:open_timeout)
Expand Down
1 change: 1 addition & 0 deletions lib/mrkt/faraday.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'faraday'
require 'faraday/multipart'

require 'mrkt/faraday/params_encoder'
require 'mrkt/faraday_middleware'
8 changes: 3 additions & 5 deletions lib/mrkt/faraday_middleware/response.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require 'faraday_middleware'
require 'faraday/response/json'

module Mrkt
module FaradayMiddleware
class Response < ::FaradayMiddleware::ParseJson
define_parser do |body|
JSON.parse(body, symbolize_names: true) unless body.strip.empty?
end
class Response < ::Faraday::Response::Json
private

def process_response(env)
super
Expand Down
6 changes: 3 additions & 3 deletions mrkt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ Gem::Specification.new do |spec|

spec.metadata['rubygems_mfa_required'] = 'true'

spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = '>= 2.6'

spec.add_dependency 'faraday', '>= 1', '< 3'
spec.add_dependency 'faraday_middleware', '~> 1.0'
spec.add_dependency 'faraday', '>= 1.10', '< 3'
spec.add_dependency 'faraday-multipart'

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'gem-release', '~> 2.1'
Expand Down

0 comments on commit 7c1b5b1

Please sign in to comment.