Class: OStatus::Feed
- Inherits:
-
Object
- Object
- OStatus::Feed
- Defined in:
- lib/ostatus/feed.rb
Overview
This class represents an OStatus Feed object.
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.
-
#entries ⇒ Object
This method gives you an array of OStatus::Entry instances for each entry listed in the feed.
-
#hubs ⇒ Object
Returns an array of URLs for each hub link tag.
-
#icon ⇒ Object
Returns the icon.
- #id ⇒ Object
-
#initialize(str, url, access_token, options) ⇒ Feed
constructor
A new instance of Feed.
-
#link(attribute) ⇒ Object
Returns an array of Nokogiri::XML::Element instances for all link tags that have a rel equal to that given by attribute.
-
#logo ⇒ Object
Returns the logo.
-
#salmon ⇒ Object
Returns the salmon URL from the link tag.
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(str, url, access_token, options) ⇒ Feed
Returns a new instance of Feed.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ostatus/feed.rb', line 12 def initialize(str, url, access_token, ) @str = str @url = url @access_token = access_token @options = if == nil @xml = Nokogiri::XML::Document.parse(self.atom) end 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.
31 32 33 |
# File 'lib/ostatus/feed.rb', line 31 def Feed.from_data(url, ) Feed.new(nil, url, 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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/ostatus/feed.rb', line 90 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 # build the atom file from internal information feed = TinyAtom::Feed.new( self.id, self.title, @url, :author_name => self..name, :author_email => self..email, :author_uri => self..uri, :hubs => self.hubs ) @options[:entries].each do |entry| entry_url = entry.url entry_url = @url if entry_url == nil feed.add_entry( entry.id, entry.title, entry.updated, entry_url, :published => entry.published, :content => entry.content, :author_name => self..name, :author_email => self..email, :author_uri => self..uri ) end feed.make(:indent => 2) end end |
#author ⇒ Object
Returns an OStatus::Author that will parse the author information within the Feed.
166 167 168 169 170 171 |
# File 'lib/ostatus/feed.rb', line 166 def return @options[:author] unless @options == nil = @xml.at_css('author') OStatus::Author.new() end |
#entries ⇒ Object
This method gives you an array of OStatus::Entry instances for each entry listed in the feed.
175 176 177 178 179 180 181 182 183 |
# File 'lib/ostatus/feed.rb', line 175 def entries return @options[:entries] unless @options == nil entries_xml = @xml.css('entry') entries_xml.map do |entry| OStatus::Entry.new(entry) end end |
#hubs ⇒ Object
Returns an array of URLs for each hub link tag.
58 59 60 61 62 63 64 65 66 |
# File 'lib/ostatus/feed.rb', line 58 def hubs if link(:hub) link(:hub).map do |link| link[:href] end else [] end end |
#icon ⇒ Object
Returns the icon
81 82 83 84 85 |
# File 'lib/ostatus/feed.rb', line 81 def icon return @options[:icon] unless @options == nil pick_first_node(@xml.xpath('/xmlns:feed/xmlns:icon')) end |
#id ⇒ Object
148 149 150 151 152 |
# File 'lib/ostatus/feed.rb', line 148 def id return @options[:id] unless @options == nil pick_first_node(@xml.xpath('/xmlns:feed/xmlns:id')) end |
#link(attribute) ⇒ Object
Returns an array of Nokogiri::XML::Element instances for all link tags that have a rel equal to that given by attribute. This can be used generally as a Hash where the keys are intern strings that give an attribute.
For example:
link(:hub).first[:href] -- Gets the first link tag with rel="hub" and
returns the contents of the href attribute.
47 48 49 50 51 52 53 54 55 |
# File 'lib/ostatus/feed.rb', line 47 def link(attribute) return @options[:links][attribute] unless @options == nil or @options[:links] == nil return nil if @options != nil # get all links with rel attribute being equal to attribute @xml.xpath('/xmlns:feed/xmlns:link').select do |link| link[:rel] == attribute.to_s end end |
#logo ⇒ Object
Returns the logo
74 75 76 77 78 |
# File 'lib/ostatus/feed.rb', line 74 def logo return @options[:logo] unless @options == nil pick_first_node(@xml.xpath('/xmlns:feed/xmlns:logo')) end |
#salmon ⇒ Object
Returns the salmon URL from the link tag.
69 70 71 |
# File 'lib/ostatus/feed.rb', line 69 def salmon link(:salmon).first[:href] end |
#title ⇒ Object
154 155 156 157 158 |
# File 'lib/ostatus/feed.rb', line 154 def title return @options[:title] unless @options == nil pick_first_node(@xml.xpath('/xmlns:feed/xmlns:title')) end |
#url ⇒ Object
160 161 162 |
# File 'lib/ostatus/feed.rb', line 160 def url return @url end |