Class: DownloadSolutions::Api::Reddit::GetInitialResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/download_solutions/api/reddit/get_initial_response.rb

Class Method Summary collapse

Class Method Details

.call(params:) ⇒ Faraday::Response

Equivalent to the initial page load of a Reddit thread, which loads some comments, but (if the thread has many comments) not all of them.

Parameters:

Returns:

  • (Faraday::Response)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/download_solutions/api/reddit/get_initial_response.rb', line 10

def self.call(params:)
  initial_response = nil

  loop do
    initial_response = params.connection.get(params.megathread_path)

    if initial_response.body.empty?
      puts PASTEL.bright_black("Throttled by Reddit. Sleeping for 60 seconds...")
      sleep 60
    else
      puts "Fetching comments for #{params.year}##{params.day.to_s.rjust(2, "0")}..."
      break
    end
  end

  initial_response
end