forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converts_subscriber_to_feed_data.rb
39 lines (35 loc) · 1.09 KB
/
converts_subscriber_to_feed_data.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require_relative "queries_web_finger"
FeedData = Struct.new(:url, :finger_data)
class ConvertsSubscriberToFeedData
def self.get_feed_data(subscriber_url)
feed_data = FeedData.new
case subscriber_url
when /^feed:\/\//
# SAFARI!!!!1 /me shakes his first at the sky
feed_data.url = "http" + subscriber_url[4..-1]
when /@/
begin
finger_data = QueriesWebFinger.query(subscriber_url)
rescue StandardError
#
# TODO Bubble up a better description of what went wrong.
#
# We could see any one of the following here:
#
# Redfinger::ResourceNotFound
# Nokogiri::SyntaxError (Bad XML parsed by Redfinger)
# SocketError (DNS resolution or connect failure)
# ??? more ???
#
raise RstatUs::InvalidSubscribeTo
end
feed_data.url = finger_data.url
feed_data.finger_data = finger_data
when /^https?:\/\//
feed_data.url = subscriber_url
else
raise RstatUs::InvalidSubscribeTo
end
feed_data
end
end