Add handling for SSL errors, bump version to 0.1.1

This commit is contained in:
Eugen Rochko 2016-02-17 16:58:02 +01:00
parent 8b0d7af683
commit 75f1b1faf9
6 changed files with 16 additions and 11 deletions

View File

@ -5,7 +5,7 @@ Goldfinger, a Webfinger client for Ruby
[gem]: https://rubygems.org/gems/goldfinger [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 ## Installation

View File

@ -1,6 +1,6 @@
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = 'goldfinger' s.name = 'goldfinger'
s.version = '0.1.0' s.version = '0.1.1'
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.required_ruby_version = '>= 2.0.0' s.required_ruby_version = '>= 2.0.0'
s.date = '2016-02-17' s.date = '2016-02-17'

View File

@ -4,9 +4,13 @@ require 'goldfinger/utils'
require 'goldfinger/client' require 'goldfinger/client'
module Goldfinger module Goldfinger
module Error class Error < StandardError
class NotFound < StandardError end
end
class NotFoundError < Error
end
class SSLError < Error
end end
def self.finger(uri) def self.finger(uri)

View File

@ -19,14 +19,16 @@ module Goldfinger
ssl = false ssl = false
retry retry
else else
raise Goldfinger::Error::NotFound raise Goldfinger::NotFoundError
end end
end end
headers, body = perform_get(url_from_template(template)) headers, body = perform_get(url_from_template(template))
Goldfinger::Result.new(headers, body) Goldfinger::Result.new(headers, body)
rescue HTTP::Error rescue HTTP::Error
raise Goldfinger::Error::NotFound raise Goldfinger::NotFoundError
rescue OpenSSL::SSL::SSLError
raise Goldfinger::SSLError
end end
private private
@ -39,7 +41,7 @@ module Goldfinger
xml = Nokogiri::XML(template) xml = Nokogiri::XML(template)
links = xml.xpath('//xmlns:Link[@rel="lrdd"]', xmlns: 'http://docs.oasis-open.org/ns/xri/xrd-1.0') 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 = Addressable::Template.new(links.first.attribute('template').value)
url.expand({ uri: @uri }).to_s url.expand({ uri: @uri }).to_s

View File

@ -20,8 +20,7 @@ module Goldfinger
def parse def parse
case @mime_type case @mime_type
when 'application/jrd+json' when 'application/jrd+json', 'application/json'
when 'application/json'
parse_json parse_json
when 'application/xrd+xml' when 'application/xrd+xml'
parse_xml parse_xml

View File

@ -40,7 +40,7 @@ describe Goldfinger::Client do
subject { Goldfinger::Client.new('acct:gargron@quitter.no') } subject { Goldfinger::Client.new('acct:gargron@quitter.no') }
it 'raises an error' do 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 end
end end