Class: AppleEpf::Downloader
- Inherits:
-
Object
- Object
- AppleEpf::Downloader
- Includes:
- Logging
- Defined in:
- lib/apple_epf/downloader.rb
Constant Summary collapse
- ITUNES_FLAT_FEED_URL =
'https://feeds.itunes.apple.com/feeds/epf/v3/full'.freeze
Instance Attribute Summary collapse
-
#apple_filename_full ⇒ Object
readonly
Returns the value of attribute apple_filename_full.
- #dirpath ⇒ Object
-
#download_to ⇒ Object
readonly
Returns the value of attribute download_to.
-
#filedate ⇒ Object
Returns the value of attribute filedate.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#force_url ⇒ Object
Returns the value of attribute force_url.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #download ⇒ Object
- #downloaded_file_base_name ⇒ Object
- #get_filename_by_date_and_type ⇒ Object
-
#initialize(type, filename, filedate, force_url = nil) ⇒ Downloader
constructor
A new instance of Downloader.
- #prepare ⇒ Object
Methods included from Logging
Constructor Details
#initialize(type, filename, filedate, force_url = nil) ⇒ Downloader
Returns a new instance of Downloader.
15 16 17 18 19 20 |
# File 'lib/apple_epf/downloader.rb', line 15 def initialize(type, filename, filedate, force_url = nil) @type = type @filename = filename #itunes, popularity, match, pricing @filedate = filedate @force_url = force_url end |
Instance Attribute Details
#apple_filename_full ⇒ Object (readonly)
Returns the value of attribute apple_filename_full.
13 14 15 |
# File 'lib/apple_epf/downloader.rb', line 13 def apple_filename_full @apple_filename_full end |
#dirpath ⇒ Object
40 41 42 |
# File 'lib/apple_epf/downloader.rb', line 40 def dirpath File.join((@dirpath || AppleEpf.extract_dir), @type) end |
#download_to ⇒ Object (readonly)
Returns the value of attribute download_to.
13 14 15 |
# File 'lib/apple_epf/downloader.rb', line 13 def download_to @download_to end |
#filedate ⇒ Object
Returns the value of attribute filedate.
11 12 13 |
# File 'lib/apple_epf/downloader.rb', line 11 def filedate @filedate end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/apple_epf/downloader.rb', line 11 def filename @filename end |
#force_url ⇒ Object
Returns the value of attribute force_url.
11 12 13 |
# File 'lib/apple_epf/downloader.rb', line 11 def force_url @force_url end |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/apple_epf/downloader.rb', line 11 def type @type end |
Instance Method Details
#download ⇒ Object
33 34 35 36 37 38 |
# File 'lib/apple_epf/downloader.rb', line 33 def download prepare @download_processor = AppleEpf.download_processor.new(@apple_filename_full, @download_to) @download_processor.download_and_check @download_to end |
#downloaded_file_base_name ⇒ Object
79 80 81 |
# File 'lib/apple_epf/downloader.rb', line 79 def downloaded_file_base_name File.basename(@download_to, '.tbz') #popularity20130109 end |
#get_filename_by_date_and_type ⇒ Object
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 77 |
# File 'lib/apple_epf/downloader.rb', line 45 def get_filename_by_date_and_type #today = DateTime.now path = "" case @type when "full" path = "#{main_dir_date}/#{@filename}#{main_dir_date}.tbz" when "incremental" date_of_file = date_to_epf_format(@filedate) path = "#{main_dir_date}/incremental/#{date_of_file}/#{@filename}#{date_of_file}.tbz" when "file" #TODO: FIX THIS # date = date_to_epf_format( @filedate, check_if_in_previous_week, check_if_in_thursday ) # path = "#{file}#{date}.tbz" end # Return false if no url was suggested or file does not exist raise AppleEpf::DownloaderError.new("Unable to find out what file do you want to download") if path.empty? unless file_exists?(path) if @type == 'incremental' #force prev week. Apple sometimes put files for Sunday to prev week, not current. path = "#{main_dir_date(true)}/incremental/#{date_of_file}/#{@filename}#{date_of_file}.tbz" raise AppleEpf::FileNotExist.new("File does not exist #{path}") unless file_exists?(path) else raise AppleEpf::FileNotExist.new("File does not exist #{path}") end end @apple_filename_full_path = path @apple_filename_full_path end |
#prepare ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/apple_epf/downloader.rb', line 22 def prepare _prepare_folders if @force_url @apple_filename_full = @force_url else get_filename_by_date_and_type @apple_filename_full = apple_filename_full_url(@apple_filename_full_path) end @download_to = File.join(dirpath, File.basename(@apple_filename_full)) end |