Sha256: b9ad6d8d0f9aa88abc8ccaf2d10729c074dd352148a67c03af3e9e6b05dbb1d8

Contents?: true

Size: 801 Bytes

Versions: 2

Compression:

Stored size: 801 Bytes

Contents

require 'forwardable'
require 'feedzirra'

module FeedCache
  class Fetcher
    extend Forwardable

    attr_reader :url, :options

    def_delegators :@fz_feed, :title, :last_modified, :entries

    def cache
      FeedCache.cache
    end

    def initialize(url, options = {})
      raise "cache must be set with FeedCache.cache=" unless cache
      @url = url
      @options = { :expires_in => FeedCache.default_expires_in }.merge options
    end

    def fetch
      @fz_feed = cache.fetch(cache_key, options) do
        Feedzirra::Feed.fetch_and_parse(url)
      end
    end

    def valid_feed?
      # Feedzirra returns fixnums in error conditions, so we
      # need to type check.
      @fz_feed && ! @fz_feed.is_a?(Fixnum)
    end

    private

    def cache_key
      url
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
feed_cache-0.1.0 lib/feed_cache/fetcher.rb
feed_cache-0.0.1 lib/feed_cache/fetcher.rb