Class: FYT::S3Storage

Inherits:
Base
  • Object
show all
Includes:
StorageHelper
Defined in:
lib/fyt/s3_storage.rb

Overview

Manages file downloads and storage

Instance Method Summary collapse

Methods inherited from Base

#logger

Constructor Details

#initialize(tmp_path, format_options, output_format, proxy_manager) ⇒ S3Storage

Returns a new instance of S3Storage.



10
11
12
13
14
15
16
# File 'lib/fyt/s3_storage.rb', line 10

def initialize(tmp_path, format_options, output_format, proxy_manager)
  @tmp_path = tmp_path || ''
  @format_options = format_options
  @output_format = output_format
  @proxy_manager = proxy_manager
  @known_files = []
end

Instance Method Details

#add(item) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fyt/s3_storage.rb', line 18

def add(item)
  url = item.link.href

  filename_for(item).tap do |filename|
    unless files_on_s3.include? filename
      download_file!(url, filename)
      upload_to_s3(filename)
      delete_file_from_disk(filename)
    end

    @known_files << filename
  end
end

#add_feed(feedname, feed) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fyt/s3_storage.rb', line 32

def add_feed(feedname, feed)
  logger.debug feed.to_s
  logger.debug @known_files

  feed_filename = "#{feedname}.feed.rss20.xml"

  tmp_path_for(feed_filename).tap do |path|
    File.write(path, feed)
    upload_to_s3(feed_filename)
    delete_file_from_disk(feed_filename)
    @known_files << feed_filename
  end
end

#cleanup!Object



46
47
48
49
50
51
52
53
# File 'lib/fyt/s3_storage.rb', line 46

def cleanup!
  logger.debug 'Files to delete:'
  logger.debug files_to_delete

  files_to_delete.each do |filename|
    delete_from_s3 filename
  end
end

#mtime(filename) ⇒ Object



55
56
57
# File 'lib/fyt/s3_storage.rb', line 55

def mtime(filename)
  bucket.object(filename).last_modified
end

#size(filename) ⇒ Object



59
60
61
# File 'lib/fyt/s3_storage.rb', line 59

def size(filename)
  bucket.object(filename).content_length
end