Class: Webhookdb::Replicator::EmailOctopusEventV1::EventBackfiller

Inherits:
Backfiller
  • Object
show all
Includes:
Backfiller::Bulk
Defined in:
lib/webhookdb/replicator/email_octopus_event_v1.rb

Overview

Because “Event” is an abstraction we’ve created and does not actually exist in the Email Octopus API, it might seem strange that we are able to “backfill” the resources at all. However, the API has a number of endpoints that they call “campaign reports,” which return lists of contacts that have engaged with a campaign in the specified way (e.g. bounced, opened, etc.) In this way, we can retrieve timestamped records of “events” that have already occurred. The only available campaign report endpoint that we don’t hit is “sent”, which notes the time at which each campaign was sent to each contact. This information doesn’t come in through webhooks at all and the timestamps closely match the “sent_at” field in the campaign row, so we have opted not to track it through backfill.

Instance Method Summary collapse

Methods included from Backfiller::Bulk

#conditional_upsert?, #dry_run?, #flush_pending_inserts, #handle_item, #pending_inserts, #remote_key_column_name

Methods inherited from Backfiller

#_fetch_backfill_page_with_retry, #backfill, do_retry_wait, #handle_item, #max_backfill_retry_attempts, #wait_for_retry_attempt

Constructor Details

#initialize(event_svc:, campaign_id:, api_key:, event_type:) ⇒ EventBackfiller

Returns a new instance of EventBackfiller.



211
212
213
214
215
216
217
# File 'lib/webhookdb/replicator/email_octopus_event_v1.rb', line 211

def initialize(event_svc:, campaign_id:, api_key:, event_type:)
  @event_svc = event_svc
  @campaign_id = campaign_id
  @api_key = api_key
  @event_type = event_type
  super()
end

Instance Method Details

#fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/webhookdb/replicator/email_octopus_event_v1.rb', line 227

def fetch_backfill_page(pagination_token, **_kwargs)
  limit = Webhookdb::EmailOctopus.page_size
  base_url = "https://emailoctopus.com"
  # rubocop:disable Layout/LineLength
  endpoint_path = pagination_token || "/api/1.6/campaigns/#{@campaign_id}/reports/#{@event_type}?api_key=#{@api_key}&limit=#{limit}"
  # rubocop:enable Layout/LineLength
  response = Webhookdb::Http.get(
    base_url + endpoint_path,
    logger: @event_svc.logger,
    timeout: Webhookdb::EmailOctopus.http_timeout,
  )
  data = response.parsed_response
  # if no data is returned from endpoint, the "paging" and "data" values are both empty arrays
  next_page_link = data.fetch("paging").empty? ? nil : data.dig("paging", "next")
  return data["data"], next_page_link
end

#prepare_body(body) ⇒ Object



222
223
224
225
# File 'lib/webhookdb/replicator/email_octopus_event_v1.rb', line 222

def prepare_body(body)
  body["campaign_id"] = @campaign_id
  body["event_type"] = "contact.#{@event_type}"
end

#upsert_page_sizeObject



220
# File 'lib/webhookdb/replicator/email_octopus_event_v1.rb', line 220

def upsert_page_size = 500

#upserting_replicatorObject



219
# File 'lib/webhookdb/replicator/email_octopus_event_v1.rb', line 219

def upserting_replicator = @event_svc