follow on to #15942 which enabled downloading existing DEV feeds, this allows setting a feed url to DEV. It's possible this user agent should be brought inline with the tags choice of community name and url, but in the short term I'm making this consistent with the existing feed importer.
28 lines
515 B
Ruby
28 lines
515 B
Ruby
module Feeds
|
|
class ValidateUrl
|
|
def self.call(feed_url)
|
|
new(feed_url).call
|
|
end
|
|
|
|
def initialize(feed_url)
|
|
@feed_url = feed_url
|
|
end
|
|
|
|
def call
|
|
return false if feed_url.blank?
|
|
|
|
xml = HTTParty.get(feed_url,
|
|
timeout: 10,
|
|
headers: { "User-Agent" => "Forem Feeds Importer" }).body
|
|
Feedjira.parse(xml)
|
|
|
|
true
|
|
rescue Feedjira::NoParserAvailable
|
|
false
|
|
end
|
|
|
|
private
|
|
|
|
attr_reader :feed_url
|
|
end
|
|
end
|