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
|
[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
|
||||||
|
|
||||||
|
|
|
@ -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'
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue