Commit 84dc2be
Changed files (3)
lib
net
hippie
test
net
lib/net/hippie/client.rb
@@ -60,6 +60,7 @@ module Net
attr_reader :mapper
def http_for(uri)
+ uri = normalize_uri(uri)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30
http.use_ssl = uri.is_a?(URI::HTTPS)
@@ -80,6 +81,10 @@ module Net
x.body = mapper.map_from(body) unless body.empty?
end
end
+
+ def normalize_uri(uri)
+ uri.is_a?(URI) ? uri : URI.parse(uri)
+ end
end
end
end
lib/net/hippie/version.rb
@@ -1,5 +1,5 @@
module Net
module Hippie
- VERSION = "0.1.2"
+ VERSION = "0.1.3"
end
end
test/net/client_test.rb
@@ -17,6 +17,14 @@ class Net::Hippie::ClientTest < Minitest::Test
end
end
+ def test_get_with_string_uri
+ VCR.use_cassette("get_breaches") do
+ response = subject.get('https://haveibeenpwned.com/api/breaches')
+ refute_nil response
+ assert_equal(283, JSON.parse(response.body).count)
+ end
+ end
+
def test_get_with_block_syntax
VCR.use_cassette("get_breaches") do
uri = URI.parse('https://haveibeenpwned.com/api/breaches')