From 75f1b1faf9f086d3495ff35ca3a6aab125ee36f9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 17 Feb 2016 16:58:02 +0100 Subject: [PATCH] Add handling for SSL errors, bump version to 0.1.1 --- README.md | 2 +- goldfinger.gemspec | 2 +- lib/goldfinger.rb | 10 +++++++--- lib/goldfinger/client.rb | 8 +++++--- lib/goldfinger/result.rb | 3 +-- spec/goldfinger/client_spec.rb | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 425ba38..5de3134 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Goldfinger, a Webfinger client for Ruby [gem]: https://rubygems.org/gems/goldfinger -A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::Error::NotFound` on failure to fetch the Webfinger or XRD data. +A Webfinger client for Ruby. Supports `application/xrd+xml` and `application/jrd+json` responses. Raises `Goldfinger::NotFoundError` on failure to fetch the Webfinger or XRD data, or `Goldfinger::SSLError` if something is wrong with the HTTPS connection it uses. ## Installation diff --git a/goldfinger.gemspec b/goldfinger.gemspec index c734e17..73031e5 100644 --- a/goldfinger.gemspec +++ b/goldfinger.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'goldfinger' - s.version = '0.1.0' + s.version = '0.1.1' s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 2.0.0' s.date = '2016-02-17' diff --git a/lib/goldfinger.rb b/lib/goldfinger.rb index 069f9d7..0b7a77c 100644 --- a/lib/goldfinger.rb +++ b/lib/goldfinger.rb @@ -4,9 +4,13 @@ require 'goldfinger/utils' require 'goldfinger/client' module Goldfinger - module Error - class NotFound < StandardError - end + class Error < StandardError + end + + class NotFoundError < Error + end + + class SSLError < Error end def self.finger(uri) diff --git a/lib/goldfinger/client.rb b/lib/goldfinger/client.rb index 66a2563..15eb521 100644 --- a/lib/goldfinger/client.rb +++ b/lib/goldfinger/client.rb @@ -19,14 +19,16 @@ module Goldfinger ssl = false retry else - raise Goldfinger::Error::NotFound + raise Goldfinger::NotFoundError end end headers, body = perform_get(url_from_template(template)) Goldfinger::Result.new(headers, body) rescue HTTP::Error - raise Goldfinger::Error::NotFound + raise Goldfinger::NotFoundError + rescue OpenSSL::SSL::SSLError + raise Goldfinger::SSLError end private @@ -39,7 +41,7 @@ module Goldfinger xml = Nokogiri::XML(template) links = xml.xpath('//xmlns:Link[@rel="lrdd"]', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0') - raise Goldfinger::Error::NotFound if links.empty? + raise Goldfinger::NotFoundError if links.empty? url = Addressable::Template.new(links.first.attribute('template').value) url.expand({ uri: @uri }).to_s diff --git a/lib/goldfinger/result.rb b/lib/goldfinger/result.rb index b3b3ba4..1c03811 100644 --- a/lib/goldfinger/result.rb +++ b/lib/goldfinger/result.rb @@ -20,8 +20,7 @@ module Goldfinger def parse case @mime_type - when 'application/jrd+json' - when 'application/json' + when 'application/jrd+json', 'application/json' parse_json when 'application/xrd+xml' parse_xml diff --git a/spec/goldfinger/client_spec.rb b/spec/goldfinger/client_spec.rb index ade36d5..69dd92a 100644 --- a/spec/goldfinger/client_spec.rb +++ b/spec/goldfinger/client_spec.rb @@ -40,7 +40,7 @@ describe Goldfinger::Client do subject { Goldfinger::Client.new('acct:gargron@quitter.no') } it 'raises an error' do - expect {subject.finger }.to raise_error(Goldfinger::Error::NotFound) + expect {subject.finger }.to raise_error(Goldfinger::NotFoundError) end end end