Method: Webhookdb::Replicator::TransistorEpisodeV1#_fetch_backfill_page

Defined in:
lib/webhookdb/replicator/transistor_episode_v1.rb

#_fetch_backfill_page(pagination_token, last_backfilled:) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/webhookdb/replicator/transistor_episode_v1.rb', line 167

def _fetch_backfill_page(pagination_token, last_backfilled:)
  url = "https://api.transistor.fm/v1/episodes"
  pagination_token = 1 if pagination_token.blank?
  response = Webhookdb::Http.get(
    url,
    headers: {"x-api-key" => self.service_integration.backfill_key},
    body: {pagination: {page: pagination_token, per: 500}},
    logger: self.logger,
    timeout: Webhookdb::Transistor.http_timeout,
  )
  data = response.parsed_response
  episodes = data["data"]
  current_page = data["meta"]["currentPage"]
  total_pages = data["meta"]["totalPages"]
  next_page = (current_page.to_i + 1 if current_page < total_pages)

  if last_backfilled.present?
    earliest_data_created = episodes.empty? ? Time.at(0) : episodes[-1].dig("attributes", "created_at")
    paged_to_already_seen_records = earliest_data_created < last_backfilled

    return episodes, nil if paged_to_already_seen_records
  end

  return episodes, next_page
end