docbrown/app/services/feeds/validate_url.rb
Daniel Uber 6869917904
validate will send forem feeds importer user agent, just like import (#16925)
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.
2022-03-21 16:43:24 -05:00

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