feed_discover 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/feed_discover.rb +19 -17
  2. metadata +1 -10
data/lib/feed_discover.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/ruby
2
+ #--
2
3
  #Copyright (C) 2007 Ben Coffey (me@inelegant.org) <http://inelegant.org/>
3
4
  #
4
5
  #This program is free software; you can redistribute it and/or
@@ -15,25 +16,26 @@
15
16
  #along with this program; if not, write to the Free Software
16
17
  #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18
  #
18
- # FeedDiscover performs feed autodiscovery on the given URL.
19
+ #++
20
+ #FeedDiscover performs feed autodiscovery on the given URL.
19
21
  #
20
- # Feed autodiscovery is a process of using standardised heruitsics
21
- # to determine the Atom/RSS feed(s) associated with a given X?HTML
22
- # document. The process is being standardised for Atom feeds via the
23
- # IETF: http://tools.ietf.org/html/draft-ietf-atompub-autodiscovery
24
- # We use the same approach for RSS feeds.
22
+ #Feed autodiscovery is a process of using standardised heruitsics
23
+ #to determine the Atom/RSS feed(s) associated with a given X?HTML
24
+ #document. The process is being standardised for Atom feeds via the
25
+ #IETF: http://tools.ietf.org/html/draft-ietf-atompub-autodiscovery
26
+ #We use the same approach for RSS feeds.
25
27
  #
26
- # When feeds cannot be discovered using the above method, we use a
27
- # broader, thus less accurate, method of looking for hyperlinks whose
28
- # URLs end with an extension typical of feeds. This feature is experimental.
28
+ #When feeds cannot be discovered using the above method, we use a
29
+ #broader, thus less accurate, method of looking for hyperlinks whose
30
+ #URLs end with an extension typical of feeds. This feature is experimental.
29
31
  #
30
- # Author:: Ben Coffey (mailto:me@inelegant.org)
31
- # Copyright:: Copyright (c) 2007 Ben Coffey
32
- # License:: GPL
32
+ #Author:: Ben Coffey (mailto:me@inelegant.org)
33
+ #Copyright:: Copyright (c) 2007 Ben Coffey
34
+ #License:: GPL
33
35
 
34
36
  require 'rubygems'
35
37
  require 'uri'
36
- require 'simple_http'
38
+ require 'open-uri'
37
39
 
38
40
  class Array #:nodoc: all
39
41
  def to_h(default=nil)
@@ -111,14 +113,14 @@ class FeedDiscover
111
113
  VALID_EXT = /\.(?:rss|xml|rdf)$/
112
114
 
113
115
  def autodiscover
114
- res = SimpleHttp.new @url
115
- #TODO: How to handle exceptions?
116
- @body = res.get || return
116
+ res = open(@url)
117
+ @body = res.read || return
118
+ @url = res.base_uri
117
119
  #If the URL that we were called with is already a feed (IOW,
118
120
  #its MIME type matches one of the keys of VALID_MIME_TYPE),
119
121
  #just return it. Autodiscovery is only specified for X?HTML
120
122
  #documents.
121
- if VALID_MIME_TYPE[res.response_headers['content-type']]
123
+ if VALID_MIME_TYPE[res.content_type.match(/(^[^; ]+)/)[0]]
122
124
  @feeds << @url.to_s
123
125
  return
124
126
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: feed_discover
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.2.0
7
7
  date: 2007-05-18 00:00:00 +01:00
8
8
  summary: A library for performing feed autodiscovery on X?HTML pages
9
9
  require_paths:
@@ -52,15 +52,6 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: 1.0.4
54
54
  version:
55
- - !ruby/object:Gem::Dependency
56
- name: simplehttp
57
- version_requirement:
58
- version_requirements: !ruby/object:Gem::Version::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.1.1
63
- version:
64
55
  - !ruby/object:Gem::Dependency
65
56
  name: htmlentities
66
57
  version_requirement: