Class: Pulse::Downloader::Client

Inherits:
Object
  • Object
show all
Includes:
FileChecker, FileDownloader, WebPageParser
Defined in:
lib/pulse/downloader/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileDownloader

#compute_hash_of, #download, #fetch_save_paths

Methods included from FileChecker

#file_path_in_file_list?

Methods included from WebPageParser

#fetch_file_paths

Constructor Details

#initialize(url:, file_type:, scrape_images: false, save_data: false, save_path: '', read_from_save_path: false, verify_ssl: true, drop_exitsing_files_in_path: false, save_and_dont_return: true, report_time: false, progress_bar: false) ⇒ Client

TODO: Validation TODO: Retry TODO: DNS TODO: Multiple filetypes TODO: lib/pulse/downloader/file_downloader.rb:13: warning: URI.escape is obsolete



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pulse/downloader/client.rb', line 32

def initialize(url:,
  file_type:,
  scrape_images: false,
  save_data: false,
  save_path: '',
  read_from_save_path: false,
  verify_ssl: true,
  drop_exitsing_files_in_path: false,
  save_and_dont_return: true,
  report_time: false,
  progress_bar: false)

  @url = url
  @file_type = file_type
  @scrape_images = scrape_images
  @save_data = save_data
  @save_path = save_path
  @read_from_save_path = read_from_save_path
  @verify_ssl = verify_ssl
  @drop_exitsing_files_in_path = drop_exitsing_files_in_path
  @save_and_dont_return = save_and_dont_return
  @report_time = report_time
  @progress_bar = progress_bar

  @base_url = get_base_url
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def base_url
  @base_url
end

#drop_exitsing_files_in_pathObject (readonly)

Returns the value of attribute drop_exitsing_files_in_path.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def drop_exitsing_files_in_path
  @drop_exitsing_files_in_path
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def end_time
  @end_time
end

#file_typeObject (readonly)

Returns the value of attribute file_type.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def file_type
  @file_type
end

#progress_barObject (readonly)

Returns the value of attribute progress_bar.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def progress_bar
  @progress_bar
end

#read_from_save_pathObject (readonly)

Returns the value of attribute read_from_save_path.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def read_from_save_path
  @read_from_save_path
end

#report_timeObject (readonly)

Returns the value of attribute report_time.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def report_time
  @report_time
end

#save_and_dont_returnObject (readonly)

Returns the value of attribute save_and_dont_return.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def save_and_dont_return
  @save_and_dont_return
end

#save_dataObject (readonly)

Returns the value of attribute save_data.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def save_data
  @save_data
end

#save_pathObject (readonly)

Returns the value of attribute save_path.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def save_path
  @save_path
end

#scrape_imagesObject (readonly)

Returns the value of attribute scrape_images.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def scrape_images
  @scrape_images
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def start_time
  @start_time
end

#urlObject (readonly)

Returns the value of attribute url.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def url
  @url
end

#verify_sslObject (readonly)

Returns the value of attribute verify_ssl.



9
10
11
# File 'lib/pulse/downloader/client.rb', line 9

def verify_ssl
  @verify_ssl
end

Instance Method Details

#callObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/pulse/downloader/client.rb', line 63

def call
  return false unless valid?

  if @progress_bar
    @progress_bar = ::ProgressBar.new(fetch_file_paths.size)
  end

  fetch_file_paths.map do |file_path|
    download(file_path, @progress_bar)
    @progress_bar.increment!
  end
end

#call!Object



59
60
61
# File 'lib/pulse/downloader/client.rb', line 59

def call!
  call
end

#valid?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/pulse/downloader/client.rb', line 76

def valid?
  true # TODO
end