Class: Murlsh::AtomBody

Inherits:
Object
  • Object
show all
Includes:
FeedBody
Defined in:
lib/murlsh/atom_body.rb

Overview

Atom feed builder.

Instance Attribute Summary

Attributes included from FeedBody

#config, #feed_url, #req, #updated, #urls

Instance Method Summary collapse

Methods included from FeedBody

#each, #feed_title, #initialize

Instance Method Details

#buildObject

Atom feed builder.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
# File 'lib/murlsh/atom_body.rb', line 14

def build
  if defined?(@body)
    @body
  else
    feed = TinyAtom::Feed.new(config.fetch('root_url'), feed_title,
      feed_url, :hubs => config.fetch('pubsubhubbub_hubs', []).
      map { |x| x['subscribe_url'] })

    urls.each do |mu|
      Murlsh::Plugin.hooks('url_display_pre') do |p|
        p.run mu, req, config
      end

      options = {
        :author_name => mu.name,
        :summary => mu.title_stripped
      }

      options[:enclosures] = []
      mu.enclosures.each do |e|
        new_e = {
          :enclosure_href => e.enclosure_url,
          :enclosure_title => e.title_stripped,
          :enclosure_type => e.content_type
        }

        new_e[:enclosure_length] = e.content_length  if e.content_length

        options[:enclosures] << new_e
      end

      if mu.thumbnail_url
        begin
          # Add root url to relative urls.
          tu = URI(mu.thumbnail_url)
          abs_url = if tu.is_a?(URI::HTTP)
            tu
          else
            URI.join config.fetch('root_url'), tu
          end
          options.merge! :media_thumbnail_url => abs_url
        rescue URI::InvalidURIError
        end
      end

      Murlsh::failproof do
        if mu.via
          options.merge!(
            :via_type => 'text/html',
            :via_href => mu.via,
            :via_title => URI(mu.via).extend(Murlsh::URIDomain).domain
            )
        end
      end

      feed.add_entry mu.id, mu.title_stripped, mu.time, mu.url, options
    end

    @updated = feed.updated
    @body = feed.make
  end

end