lib/atom/feed.rb in atom-tools-0.9.0 vs lib/atom/feed.rb in atom-tools-0.9.1
- old
+ new
@@ -70,10 +70,12 @@
# parses XML fetched from +base+ into an Atom::Feed
def self.parse xml, base = ""
if xml.respond_to? :to_atom_entry
xml.to_atom_feed(base)
+ elsif xml.respond_to? :read
+ self.parse(xml.read)
else
REXML::Document.new(xml.to_s).to_atom_feed(base)
end
end
@@ -153,10 +155,12 @@
feed
end
# fetches this feed's URL, parses the result and #merge!s
# changes, new entries, &c.
+ #
+ # (note that this is different from Atom::Entry#updated!
def update!
raise(RuntimeError, "can't fetch without a uri.") unless @uri
headers = {}
headers["If-None-Match"] = @etag if @etag
@@ -170,25 +174,26 @@
elsif res.code == "410"
raise Atom::FeedGone, "410 Gone (#{@uri})"
elsif res.code != "200"
raise Atom::HTTPException, "Unexpected HTTP response code: #{res.code}"
end
-
- unless res.content_type.match(/^application\/atom\+xml/)
- raise Atom::HTTPException, "Unexpected HTTP response Content-Type: #{res.content_type} (wanted application/atom+xml)"
+
+ media_type = res.content_type.split(";").first
+ unless ["application/atom+xml", "application/xml", "text/xml"].member? media_type
+ raise Atom::HTTPException, "An atom:feed shouldn't have Content-Type: #{res.content_type}"
end
@etag = res["Etag"] if res["Etag"]
@last_modified = res["Last-Modified"] if res["Last-Modified"]
xml = res.body
coll = REXML::Document.new(xml)
- update_time = Time.parse(REXML::XPath.first(coll, "/atom:feed/atom:updated", { "atom" => Atom::NS } ).text)
+ update_el = REXML::XPath.first(coll, "/atom:feed/atom:updated", { "atom" => Atom::NS } )
- # the feed hasn't been updated, don't bother
- if self.updated and self.updated >= update_time
+ # the feed hasn't been updated, don't do anything.
+ if update_el and self.updated and self.updated >= Time.parse(update_el.text)
return self
end
coll = Atom::Feed.parse(coll, self.base.to_s)
merge! coll