Sha256: eba602a89618aa703e5212775dbf8beb926bc5cfd185656e787ea8c4e0afa2d3

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

require 'uri'

require 'rack'

require 'murlsh'

module Murlsh

  # Serve Atom feed.
  class AtomServer

    def initialize(config); @config = config; end

    # Respond to a GET request for Atom feed.
    def get(req)
      conditions = Murlsh::SearchConditions.new(req['q']).conditions
      page = 1
      per_page = config.fetch('num_posts_feed', 25)

      result_set = Murlsh::UrlResultSet.new(conditions, page, per_page)
      urls = result_set.results

      feed_url = URI.join(config.fetch('root_url'), config.fetch('feed_file'))
      body = Murlsh::AtomBody.new(config, req, feed_url, urls)

      resp = Rack::Response.new(body, 200,
        'Cache-Control' => 'must-revalidate, max-age=0',
        'Content-Type' => 'application/atom+xml')
      if u = body.updated
        resp['Last-Modified'] = u.httpdate
      end
      resp
    end

    attr_reader :config
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
murlsh-1.6.1 lib/murlsh/atom_server.rb
murlsh-1.6.0 lib/murlsh/atom_server.rb
murlsh-1.5.0 lib/murlsh/atom_server.rb