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

Upgrade to faraday 2 #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
source 'https://rubygems.org'

# rack 2.x requires ruby 2.2.x
if RUBY_VERSION < '2.2'
gem 'rack', '~> 1.6.0', group: :test
end
Copy link
Author

Choose a reason for hiding this comment

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

The minimum was already set to 2.6, this is pointless, removed.


gemspec
27 changes: 11 additions & 16 deletions cover_my_meds.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cover_my_meds/version'
require_relative 'lib/cover_my_meds/version'
Copy link
Author

Choose a reason for hiding this comment

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

Quit messing with $LOAD_PATH.


Gem::Specification.new do |spec|
spec.name = "cover_my_meds"
Expand All @@ -12,26 +10,23 @@ Gem::Specification.new do |spec|
spec.summary = %q{CoverMyMeds Public API}
spec.description = %q{The public version of CoverMyMeds API}
spec.homepage = "https://github.com/covermymeds/cover_my_meds"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Copy link
Author

Choose a reason for hiding this comment

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

There are no executables, and lib is already the default require path. No idea why the default name was even changed.


spec.add_development_dependency "bundler"
spec.add_development_dependency "rspec", ">= 3.2"
spec.add_development_dependency "rspec-junklet", ">= 2.0"
spec.add_development_dependency "webmock", "~> 2.0"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rspec-junklet"
spec.add_development_dependency "webmock"
Copy link
Author

Choose a reason for hiding this comment

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

I think we can forego versioning on dev dependencies unless we're really locked into a version.

spec.add_development_dependency "rake"
spec.add_development_dependency "pry"
spec.add_development_dependency "dotenv"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "railties"

spec.add_runtime_dependency "faraday", ">= 1.0", "< 2.0"
spec.add_runtime_dependency "faraday_middleware"
spec.add_runtime_dependency "typhoeus"
spec.add_runtime_dependency "mime-types"
spec.add_runtime_dependency "hashie", ">= 3.4.0"
spec.add_runtime_dependency "activesupport", ">= 4.2.2"
spec.add_runtime_dependency "faraday", "~> 2.9.0"
spec.add_runtime_dependency "faraday-follow_redirects", "~> 0.3.0"
spec.add_runtime_dependency "faraday-multipart", "~> 1.0.4"
spec.add_runtime_dependency "faraday-typhoeus", "~> 1.1.0"
Copy link
Author

Choose a reason for hiding this comment

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

The extra faraday-xxx dependencies here were required because of the updated faraday gem, i.e. multipart and redirect are no longer baked into it, but require separate gems.

spec.add_runtime_dependency "mime-types", "~> 3.5.2"
spec.add_runtime_dependency "hashie", "~> 5.0.0"
spec.add_runtime_dependency "activesupport", "~> 7.0.8"
end
18 changes: 9 additions & 9 deletions lib/cover_my_meds/api_request.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
require 'faraday'
require 'faraday_middleware'
require 'typhoeus'
require 'typhoeus/adapters/faraday'
require 'faraday/typhoeus'
require 'faraday/multipart'
require 'faraday/follow_redirects'
Copy link
Author

Choose a reason for hiding this comment

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

See above.

require 'json'
require 'hashie'
require 'active_support/core_ext/object/to_param'
require 'active_support/core_ext/object/to_query'
require 'cover_my_meds/error'
require 'mime-types'


module CoverMyMeds
module ApiRequest
DEFAULT_TIMEOUT = 60 #seconds, matches Net::Http's default which rest-client used
Expand All @@ -19,17 +18,18 @@ def request(http_method, host, path, params={}, auth_type = :basic, &block)
headers = params.delete(:headers) || {}
timeout = params.delete(:timeout) || DEFAULT_TIMEOUT

conn = Faraday.new host do |faraday|
conn = Faraday.new(host) do |faraday|
faraday.request :multipart
faraday.request :url_encoded
faraday.response :follow_redirects
faraday.adapter :typhoeus
end

case auth_type
when :basic
conn.request :basic_auth, @username, @password
when :bearer
conn.authorization :Bearer, "#{@username}+#{params.delete(:token_id)}"
when :basic
conn.set_basic_auth(@username, @password)
when :bearer
headers['Authorization'] = "Bearer #{@username}+#{params.delete(:token_id)}"
end

response = conn.send http_method do |request|
Expand Down
2 changes: 1 addition & 1 deletion lib/cover_my_meds/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CoverMyMeds
VERSION = "3.4.1"
VERSION = "3.5.0"
end