Class: Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/feed.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Feed

Returns a new instance of Feed.



5
6
7
8
# File 'lib/feed.rb', line 5

def initialize(options)
  @options = options
  @dsl = DSL.new(@options)
end

Instance Method Details

#checkObject



10
11
12
13
# File 'lib/feed.rb', line 10

def check
  @results ? update_feeds : check_feeds
  check_downloads
end

#check_downloadsObject



69
70
71
72
73
74
# File 'lib/feed.rb', line 69

def check_downloads
  return if @options[:dry_run]
  @options[:logger].info "Checking Download Status" if @options[:verbose]
  t = Transmission::Client.new(@options[:transmission_server], @options[:transmission_port])
  @dsl.download_complete(t.torrents)
end

#check_feedsObject



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
# File 'lib/feed.rb', line 15

def check_feeds
  number_processed = 0
  feeds = @dsl.feeds
  feed_size = feeds.size
  
  begin
    @options[:logger].info "Fetching #{feed_size} feed#{feed_size == 1 ? "" : "s"}" if @options[:verbose]
    
    @results = Feedzirra::Feed.fetch_and_parse(feeds)
    
    @options[:logger].info "Processing #{feed_size} feed#{feed_size == 1 ? "" : "s"}" if @options[:verbose]
    
    @results.each do |url, rss|
      if rss.is_a?(Fixnum)
        @options[:logger].error "Couldn't download #{url}"
      else
        @dsl.perform_filter(rss.entries)
        number_processed += 1
      end
    end
  rescue => e
    @options[:logger].error "#{e}"
  end

  @options[:logger].info "Processed #{number_processed} out of #{feed_size} feed#{feed_size == 1 ? "" : "s"}" if @options[:verbose]
  return number_processed
end

#update_feedsObject



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
# File 'lib/feed.rb', line 43

def update_feeds
  number_processed = 0
  number_skipped = 0
  feeds = @results
  feed_size = feeds.size

  begin
    @options[:logger].info "Fetching #{feed_size} feed#{feed_size ? "" : "s"}" if @options[:verbose]
    
    results = Feedzirra::Feed.update(feeds.values)
    @options[:logger].info "Processing #{feed_size} feed#{feed_size ? "" : "s"}" if @options[:verbose]
    
    if results.updated?
      @dsl.perform_filter(results.new_entries)
    else
      number_skipped += 1
    end
    number_processed += 1
  rescue => e
    @options[:logger].error "#{e}"
  end

  @options[:logger].info "Processed #{number_processed} out of #{feed_size} feed#{feed_size ? "" : "s"} (#{number_skipped} skipped)" if @options[:verbose]
  return number_processed   
end