Class: InstagramCrawler::File

Inherits:
File
  • Object
show all
Defined in:
lib/instagram_crawler/file.rb

Class Method Summary collapse

Class Method Details

.download(url, dir_name, file_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/instagram_crawler/file.rb', line 10

def download(url, dir_name, file_name)
  return unless Config.download
  binary_data, mime_type = get_binary_data(url)

  extname =
    case mime_type
    when "video/mp4" then ".mp4"
    when "image/jpeg" then ".jpeg"
    end

  dir_path  = "#{Config.base_path}/#{dir_name}"
  FileUtils.mkdir_p(dir_path) unless Dir.exist?(dir_path)

  file_path = "#{dir_path}/#{file_name}#{extname}"


  File.open(file_path, 'wb') do |f|
    f.write binary_data
  end
end

.mkdirObject



4
5
6
7
8
# File 'lib/instagram_crawler/file.rb', line 4

def mkdir
  return unless Config.download
  Logger.info "Create directory in #{Config.base_path}\n"
  FileUtils.mkdir_p(Config.base_path) unless Dir.exist?(Config.base_path)
end