Class: DownloadSolutions::Api::Reddit::GetSerialComments
- Inherits:
-
Object
- Object
- DownloadSolutions::Api::Reddit::GetSerialComments
- Defined in:
- lib/download_solutions/api/reddit/get_serial_comments.rb
Constant Summary collapse
- MAX_SLEEP_COUNT =
10
Class Method Summary collapse
-
.call(params:, parent_id: params.thread_id) ⇒ Array(Array<Hash>, Array<Hash>)
Equivalent to repeatedly pressing “View more comments” in a thread’s top level (or the “+” below a comment) until reaching the end.
Class Method Details
.call(params:, parent_id: params.thread_id) ⇒ Array(Array<Hash>, Array<Hash>)
Equivalent to repeatedly pressing “View more comments” in a thread’s top level (or the “+” below a comment) until reaching the end. “Serial” because this doesn’t fetch all replies; many (not all) replies are in “more children” nodes and not yet fetched.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/download_solutions/api/reddit/get_serial_comments.rb', line 23 def self.call(params:, parent_id: params.thread_id) comments = initial_comments_or_replies(params, parent_id) || (return [[], []]) loop do more_top_level_childrens, comments = comments.partition { it[:children] && it[:parent_id] == parent_id } break unless more_top_level_childrens.any? raise Reddit::MultipleMoreChildrensError if more_top_level_childrens.count > 1 # Loop again to fetch more if there are more top-level comments. comments += fetch_more_children(params, more_top_level_childrens.first, parent_id) end more_childrens, comments = comments.partition { it[:children] } [comments, more_childrens] end |