Class: Archdown::Download

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(library_root, search_terms) ⇒ Download

Returns a new instance of Download.



11
12
13
14
15
# File 'lib/archdown/download.rb', line 11

def initialize(library_root, search_terms)
  @library = Library.new(library_root)
  @search_terms = search_terms
  @client = Archivist::Client::Base.new
end

Instance Attribute Details

#library_rootObject (readonly)

Returns the value of attribute library_root.



9
10
11
# File 'lib/archdown/download.rb', line 9

def library_root
  @library_root
end

#search_termsObject (readonly)

Returns the value of attribute search_terms.



9
10
11
# File 'lib/archdown/download.rb', line 9

def search_terms
  @search_terms
end

Instance Method Details

#go!(&each_book) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/archdown/download.rb', line 17

def go!(&each_book)
  page = 1
  loop do
    books = ::Retriable.retriable :on => Faraday::Error::TimeoutError do
      terms = @search_terms.merge(:page => page)
      begin
        @client.search(terms)
      rescue e
        $stderr.puts "Search Terms: #{JSON.pretty_generate(terms)}"
        raise
      end
    end
  
    break if books.empty?
  
    books.each do |book|
      Librarian.new(@library, book).store_book(&each_book)
    end
    page += 1
  end
end