mirror of https://github.com/mastodon/goldfinger
Add handling for SSL errors, bump version to 0.1.1
This commit is contained in:
parent
8b0d7af683
commit
75f1b1faf9
|
@ -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
|
||||
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue