From 7d57eda0a7d46b62012cb835394174b3c2099580 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sat, 11 Apr 2020 23:25:58 +1200 Subject: [PATCH] Allow closing underlying connection. (#67) Fixes #66. --- lib/sawyer/agent.rb | 5 +++++ sawyer.gemspec | 2 +- test/agent_test.rb | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/sawyer/agent.rb b/lib/sawyer/agent.rb index 7555fac..da5f847 100644 --- a/lib/sawyer/agent.rb +++ b/lib/sawyer/agent.rb @@ -48,6 +48,11 @@ def initialize(endpoint, options = nil) yield @conn if block_given? end + # Public: Close the underlying connection. + def close + @conn.close + end + # Public: Retains a reference to the root relations of the API. # # Returns a Sawyer::Relation::Map. diff --git a/sawyer.gemspec b/sawyer.gemspec index 1423dd0..d4e8e97 100644 --- a/sawyer.gemspec +++ b/sawyer.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/lostisland/sawyer' spec.licenses = ['MIT'] - spec.add_dependency 'faraday', ['> 0.8', '< 2.0'] + spec.add_dependency 'faraday', "~> 1.0" spec.add_dependency 'addressable', ['>= 2.3.5'] spec.files = %w(Gemfile LICENSE.md README.md Rakefile) diff --git a/test/agent_test.rb b/test/agent_test.rb index 0c22a7e..376589e 100644 --- a/test/agent_test.rb +++ b/test/agent_test.rb @@ -22,6 +22,10 @@ def setup end end + def test_close + @agent.close + end + def test_accesses_root_relations @stubs.get '/a/' do |env| assert_equal 'foo.com', env[:url].host