Class: Lotus::Atom::Feed

Inherits:
Atom::Feed
  • Object
show all
Includes:
Atom::SimpleExtensions
Defined in:
lib/lotus/atom/feed.rb

Overview

This class represents an OStatus Feed object.

Constant Summary collapse

POCO_NAMESPACE =

The XML namespace the specifies this content.

'http://portablecontacts.net/spec/1.0'
ACTIVITY_NAMESPACE =

The XML namespace that identifies the conforming specification.

'http://activitystrea.ms/spec/1.0/'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_canonical(obj) ⇒ Object

Creates an Atom generator for the given Lotus::Feed.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/lotus/atom/feed.rb', line 45

def self.from_canonical(obj)
  hash = obj.to_hash
  hash[:entries].map! {|e|
    Lotus::Atom::Entry.from_canonical(e)
  }

  # Ensure that the generator is encoded.
  if hash[:generator]
    hash[:generator] = Lotus::Atom::Generator.from_canonical(hash[:generator])
  end

  hash[:links] ||= []

  if hash[:salmon_url]
    hash[:links] << ::Atom::Link.new(:rel => "salmon", :href => hash[:salmon_url])
  end
  hash.delete :salmon_url

  if hash[:url]
    hash[:links] << ::Atom::Link.new(:rel => "self", :href => hash[:url])
  end
  hash.delete :url

  hash[:hubs].each {|h|
    hash[:links] << ::Atom::Link.new(:rel => "hub", :href => h)
  }
  hash.delete :hubs

  hash[:authors].map! {|a|
    Lotus::Atom::Author.from_canonical(a)
  }

  hash[:contributors].map! {|a|
    Lotus::Atom::Author.from_canonical(a)
  }

  hash[:categories].map! {|c|
    Lotus::Atom::Category.from_canonical(c)
  }

  # title/subtitle content type
  node = XML::Node.new("title")
  node['type'] = hash[:title_type] if hash[:title_type]
  node << hash[:title]

  xml = XML::Reader.string(node.to_s)
  xml.read
  hash[:title] = ::Atom::Content.parse(xml)
  hash.delete :title_type

  if hash[:subtitle]
    node = XML::Node.new("subtitle")
    node['type'] = hash[:subtitle_type] if hash[:subtitle_type]
    node << hash[:subtitle]

    xml = XML::Reader.string(node.to_s)
    xml.read
    hash[:subtitle] = ::Atom::Content.parse(xml)
  else
    hash.delete :subtitle
  end
  hash.delete :subtitle_type

  self.new(hash)
end

Instance Method Details

#hubsObject

Returns an array of URLs for each hub link tag.



156
157
158
# File 'lib/lotus/atom/feed.rb', line 156

def hubs
  link('hub').map { |link| link.href }
end

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.


151
152
153
# File 'lib/lotus/atom/feed.rb', line 151

def link(attribute)
  links.find_all { |l| l.rel == attribute.to_s }
end

#to_canonicalObject



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
138
139
140
141
142
# File 'lib/lotus/atom/feed.rb', line 111

def to_canonical
  generator = nil
  generator = self.generator.to_canonical if self.generator

  salmon_url = nil
  if self.link('salmon').any?
    salmon_url = self.link('salmon').first.href
  end

  url = self.url

  categories = self.categories.map(&:to_canonical)

  Lotus::Feed.new(:title         => self.title.to_s,
                  :title_type    => self.title ? self.title.type : nil,
                  :subtitle      => self.subtitle.to_s,
                  :subtitle_type => self.subtitle ? self.subtitle.type : nil,
                  :id            => self.id,
                  :url           => url,
                  :categories    => categories,
                  :icon          => self.icon,
                  :logo          => self.,
                  :rights        => self.rights,
                  :published     => self.published,
                  :updated       => self.updated,
                  :entries       => self.entries.map(&:to_canonical),
                  :authors       => self.authors.map(&:to_canonical),
                  :contributors  => self.contributors.map(&:to_canonical),
                  :hubs          => self.hubs,
                  :salmon_url    => salmon_url,
                  :generator     => generator)
end

#urlObject

Returns a string of the url for this feed.



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/lotus/atom/feed.rb', line 161

def url
  if links.alternate
    links.alternate.href
  elsif links.self
    links.self.href
  else
    links.map.each do |l|
      l.href
    end.compact.first
  end
end