Class: OStatus::Feed
- Inherits:
-
Atom::Feed
- Object
- Atom::Feed
- OStatus::Feed
- Includes:
- Atom::SimpleExtensions
- Defined in:
- lib/ostatus/feed.rb
Overview
This class represents an OStatus Feed object.
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.from_data(url, options) ⇒ Object
Creates a new Feed instance that contains the information given by the various instances of author and entries.
- .from_string(str) ⇒ Object
-
.from_url(url, access_token = nil) ⇒ Object
Creates a new Feed instance given by the atom feed located at ‘url’ and optionally using the OAuth::AccessToken given.
Instance Method Summary collapse
-
#atom ⇒ Object
This method will return a String containing the actual content of the atom feed.
-
#author ⇒ Object
Returns an OStatus::Author that will parse the author information within the Feed.
- #author=(author) ⇒ Object
-
#hubs ⇒ Object
Returns an array of URLs for each hub link tag.
- #hubs=(hubs) ⇒ Object
-
#initialize(str, url, access_token, options) ⇒ Feed
constructor
A new instance of Feed.
-
#link(attribute) ⇒ Object
Returns an array of Atom::Link instances for all link tags that have a rel equal to that given by attribute.
- #links=(given) ⇒ Object
-
#salmon ⇒ Object
Returns the salmon URL from the link tag.
Constructor Details
#initialize(str, url, access_token, options) ⇒ Feed
Returns a new instance of Feed.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ostatus/feed.rb', line 28 def initialize(str, url, access_token, ) @str = str @url = url @access_token = access_token @options = if str super(XML::Reader.string(str)) else super() end end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
26 27 28 |
# File 'lib/ostatus/feed.rb', line 26 def url @url end |
Class Method Details
.from_data(url, options) ⇒ Object
Creates a new Feed instance that contains the information given by the various instances of author and entries.
57 58 59 |
# File 'lib/ostatus/feed.rb', line 57 def Feed.from_data(url, ) Feed.new(nil, url, nil, ) end |
.from_string(str) ⇒ Object
61 62 63 |
# File 'lib/ostatus/feed.rb', line 61 def Feed.from_string(str) Feed.new(str, nil, nil, nil) end |
.from_url(url, access_token = nil) ⇒ Object
Creates a new Feed instance given by the atom feed located at ‘url’ and optionally using the OAuth::AccessToken given.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ostatus/feed.rb', line 43 def Feed.from_url(url, access_token = nil) if access_token.nil? # simply open the url str = open(url).read else # open the url through OAuth str = access_token.get(url).body end Feed.new(str, url, access_token, nil) end |
Instance Method Details
#atom ⇒ Object
This method will return a String containing the actual content of the atom feed. It will make a network request (through OAuth if an access token was given) to retrieve the document if necessary.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ostatus/feed.rb', line 98 def atom if @str != nil @str elsif @options == nil and @access_token == nil # simply open the url open(@url).read elsif @options == nil and @url != nil # open the url through OAuth @access_token.get(@url).body else self.links << Atom::Link.new(:rel => 'self', :href => @url) if @url self.links << Atom::Link.new(:rel => 'edit', :href => @url) if @url self.to_xml end end |
#author ⇒ Object
Returns an OStatus::Author that will parse the author information within the Feed.
116 117 118 |
# File 'lib/ostatus/feed.rb', line 116 def @options ? @options[:author] : self..first end |
#author=(author) ⇒ Object
120 121 122 |
# File 'lib/ostatus/feed.rb', line 120 def self..clear << end |
#hubs ⇒ Object
Returns an array of URLs for each hub link tag.
86 87 88 |
# File 'lib/ostatus/feed.rb', line 86 def hubs link(:hub).map { |link| link.href } end |
#hubs=(hubs) ⇒ Object
124 125 126 127 128 |
# File 'lib/ostatus/feed.rb', line 124 def hubs= hubs hubs.each do |hub| links << Atom::Link.new(:rel => 'hub', :href => hub) end end |
#link(attribute) ⇒ Object
Returns an array of Atom::Link instances for all link tags that have a rel equal to that given by attribute.
For example:
link(:hub).first.href -- Gets the first link tag with rel="hub" and
returns the contents of the href attribute.
72 73 74 |
# File 'lib/ostatus/feed.rb', line 72 def link(attribute) links.find_all { |l| l.rel == attribute.to_s } end |
#links=(given) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/ostatus/feed.rb', line 76 def links=(given) self.links.clear given.each do |rel,links| links.each do |l| self.links << Atom::Link.new(l.merge({:rel => rel})) end end end |
#salmon ⇒ Object
Returns the salmon URL from the link tag.
91 92 93 |
# File 'lib/ostatus/feed.rb', line 91 def salmon link(:salmon).first.href end |