Class: OStatus::Link
- Inherits:
-
Atom::Link
- Object
- Atom::Link
- OStatus::Link
- Includes:
- Atom::Xml::Parseable
- Defined in:
- lib/ostatus/link.rb
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#fetch(options = {}) ⇒ Object
This will fetch the URL referenced by the link.
- #href ⇒ Object
-
#initialize(o) ⇒ Link
constructor
Create a link.
- #inspect ⇒ Object
- #length=(v) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(o) ⇒ Link
Create a link.
o-
An XML::Reader containing a link element or a Hash of attributes.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ostatus/link.rb', line 11 def initialize(o) case o when XML::Reader if current_node_is?(o, 'link') self.text = o.read_string parse(o, :once => true) else raise ArgumentError, "Link created with node other than atom:link: #{o.name}" end when Hash [:href, :rel, :type, :length, :hreflang, :title].each do |attr| self.send("#{attr}=", o[attr]) end else raise ArgumentError, "Don't know how to handle #{o}" end end |
Instance Method Details
#==(o) ⇒ Object
42 43 44 |
# File 'lib/ostatus/link.rb', line 42 def ==(o) o.respond_to?(:href) && o.href == self.href end |
#fetch(options = {}) ⇒ Object
This will fetch the URL referenced by the link.
If the URL contains a valid feed, a Feed will be returned, otherwise, the body of the response will be returned.
TODO: Handle redirects.
53 54 55 56 57 58 59 |
# File 'lib/ostatus/link.rb', line 53 def fetch( = {}) begin Atom::Feed.load_feed(URI.parse(self.href), ) rescue ArgumentError Net::HTTP.get_response(URI.parse(self.href)).body end end |
#href ⇒ Object
34 35 36 |
# File 'lib/ostatus/link.rb', line 34 def href @href || self.text end |
#inspect ⇒ Object
61 62 63 |
# File 'lib/ostatus/link.rb', line 61 def inspect "<OStatus::Link href:'#{href}' type:'#{type}'>" end |
#length=(v) ⇒ Object
30 31 32 |
# File 'lib/ostatus/link.rb', line 30 def length=(v) @length = v.to_i end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/ostatus/link.rb', line 38 def to_s self.href end |