From ff813791d566bd9d68008100f80cb55677c75f9c Mon Sep 17 00:00:00 2001 From: dblock Date: Sat, 2 Jan 2021 14:58:28 -0500 Subject: [PATCH] Use digest_auth from faraday-digestauth. --- CHANGELOG.md | 6 ++++-- README.md | 15 +++++++++++---- hyperclient.gemspec | 2 -- lib/faraday/connection.rb | 17 ----------------- lib/hyperclient/entry_point.rb | 3 +-- test/faraday/connection_test.rb | 29 ----------------------------- 6 files changed, 16 insertions(+), 56 deletions(-) delete mode 100644 lib/faraday/connection.rb delete mode 100644 test/faraday/connection_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 859360f..f60fa10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,14 @@ ### 1.0.1 (Next) +* [#193](https://github.com/codegram/hyperclient/pull/193): Auto-paginate collections - [@dblock](https://github.com/dblock). +* [#163](https://github.com/codegram/hyperclient/pull/163): Test against Faraday 0.9, 0.17 and 1.0+ - [@dblock](https://github.com/dblock). +* [#199](https://github.com/codegram/hyperclient/pull/199): Use digest_auth from faraday-digestauth - [@dblock](https://github.com/dblock). * Your contribution here. ### 1.0.0 (2021/01/02) -* [#193](https://github.com/codegram/hyperclient/pull/193): Auto-paginate collections - [@dblock](https://github.com/dblock). -* [#163](https://github.com/codegram/hyperclient/pull/163): Test against Faraday 0.9, 0.17 and 1.0+ - [@dblock](https://github.com/dblock). +* NOTE: **⚠ This version has been yanked ⚠** - [@dblock](https://github.com/dblock). ### 0.9.3 (2020/05/14) diff --git a/README.md b/README.md index 87ce613..085e49d 100644 --- a/README.md +++ b/README.md @@ -85,12 +85,19 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client| end ``` -You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or Digest auth as well as many other Faraday extensions. +You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or [Digest auth](https://github.com/bhaberer/faraday-digestauth) as well as many other Faraday extensions. ```ruby -api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') -api.digest_auth('username', 'password') -api.headers.update('Accept-Encoding' => 'deflate, gzip') +require 'faraday/digestauth' + +api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client| + client.connection(default: false) do |conn| + conn.request :digest, 'username', 'password' + conn.request :json + conn.response :json, content_type: /\bjson$/ + conn.adapter :net_http + end +end ``` You can access the Faraday connection directly after it has been created and add middleware to it. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache). diff --git a/hyperclient.gemspec b/hyperclient.gemspec index c054380..c01318d 100644 --- a/hyperclient.gemspec +++ b/hyperclient.gemspec @@ -15,8 +15,6 @@ Gem::Specification.new do |gem| gem.add_dependency 'addressable' gem.add_dependency 'faraday', '>= 0.9.0' - gem.add_dependency 'faraday-digestauth', '>= 0.3.0' gem.add_dependency 'faraday_hal_middleware' gem.add_dependency 'faraday_middleware' - gem.add_dependency 'net-http-digest_auth' end diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb deleted file mode 100644 index 110354c..0000000 --- a/lib/faraday/connection.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'faraday' -require 'faraday/digestauth' - -module Faraday - # Reopen Faraday::Connection to add a helper to set the digest auth data. - class Connection - # Public: Adds the digest auth middleware at the top and sets the user and - # password. - # - # user - A String with the user. - # password - A String with the password. - # - def digest_auth(user, password) - builder.insert(0, Faraday::Request::DigestAuth, user, password) - end - end -end diff --git a/lib/hyperclient/entry_point.rb b/lib/hyperclient/entry_point.rb index 2dd992f..96cebc8 100644 --- a/lib/hyperclient/entry_point.rb +++ b/lib/hyperclient/entry_point.rb @@ -1,6 +1,5 @@ require 'faraday_middleware' require 'faraday_hal_middleware' -require_relative '../faraday/connection' module Hyperclient # Public: Exception that is raised when trying to modify an @@ -30,7 +29,7 @@ class EntryPoint < Link extend Forwardable # Public: Delegates common methods to be used with the Faraday connection. - def_delegators :connection, :basic_auth, :digest_auth, :token_auth, :params, :params= + def_delegators :connection, :params, :params= # Public: Initializes an EntryPoint. # diff --git a/test/faraday/connection_test.rb b/test/faraday/connection_test.rb deleted file mode 100644 index 55c4d99..0000000 --- a/test/faraday/connection_test.rb +++ /dev/null @@ -1,29 +0,0 @@ -require_relative '../test_helper' -require_relative '../../lib/faraday/connection' - -module Faraday - describe Connection do - describe 'digest_auth' do - let(:connection) do - Faraday.new('http://api.example.org/') do |builder| - builder.request :url_encoded - builder.adapter :net_http - end - end - - it 'inserts the DigestAuth middleware at the top' do - connection.digest_auth('user', 'password') - - _(connection.builder.handlers.first.klass).must_equal Faraday::Request::DigestAuth - end - - it 'passes the user and password to the middleware' do - connection.digest_auth('user', 'password') - - Faraday::Request::DigestAuth.expects(:new).with(anything, 'user', 'password').returns(stub_everything) - - connection.get('/') - end - end - end -end