diff options
author | Starfall <us@starfall.systems> | 2022-05-04 12:00:22 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-05-04 12:00:22 -0500 |
commit | e9b2e11520056d0ec822ac0862923d00c6a1289c (patch) | |
tree | 53b22a4fecda9846fc6c77cf4067c071a6287df0 /app/lib/webfinger.rb | |
parent | 9ec0ecda66745c892961a917b18354f42dfc1f19 (diff) | |
parent | 58ac5ae643dc57ffd20017c54e7be523deaef156 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'app/lib/webfinger.rb')
-rw-r--r-- | app/lib/webfinger.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/lib/webfinger.rb b/app/lib/webfinger.rb index 1ffb5b4bf..a681e0815 100644 --- a/app/lib/webfinger.rb +++ b/app/lib/webfinger.rb @@ -6,8 +6,13 @@ class Webfinger class RedirectError < StandardError; end class Response - def initialize(body) + attr_reader :uri + + def initialize(uri, body) + @uri = uri @json = Oj.load(body, mode: :strict) + + validate_response! end def subject @@ -23,6 +28,10 @@ class Webfinger def links @links ||= @json['links'].index_by { |link| link['rel'] } end + + def validate_response! + raise Webfinger::Error, "Missing subject in response for #{@uri}" if subject.blank? + end end def initialize(uri) @@ -34,7 +43,7 @@ class Webfinger end def perform - Response.new(body_from_webfinger) + Response.new(@uri, body_from_webfinger) rescue Oj::ParseError raise Webfinger::Error, "Invalid JSON in response for #{@uri}" rescue Addressable::URI::InvalidURIError |