Module: Webhookdb::Replicator::ConvertkitV1Mixin

Includes:
DBAdapter::ColumnTypes
Included in:
ConvertkitBroadcastV1, ConvertkitSubscriberV1, ConvertkitTagV1
Defined in:
lib/webhookdb/replicator/convertkit_v1_mixin.rb

Constant Summary collapse

CONV_FIND_CANCELED_AT =

Converter for use with the denormalized columns

Webhookdb::Replicator::Column::IsomorphicProc.new(
  ruby: lambda do |_, resource:, **_|
    # Subscribers do not store a cancelation time (nor an updated at time),
    # so we derive and store it based on their state.
    # When they become inactive state, we set canceled_at,
    # and clear it when they are not active.
    # See the upsert_update_expr for Convertkit Subscriber for the details.
    resource.fetch("state") == "active" ? nil : Time.now
  end,
  sql: nil,
)

Constants included from DBAdapter::ColumnTypes

DBAdapter::ColumnTypes::BIGINT, DBAdapter::ColumnTypes::BIGINT_ARRAY, DBAdapter::ColumnTypes::BOOLEAN, DBAdapter::ColumnTypes::COLUMN_TYPES, DBAdapter::ColumnTypes::DATE, DBAdapter::ColumnTypes::DECIMAL, DBAdapter::ColumnTypes::DOUBLE, DBAdapter::ColumnTypes::FLOAT, DBAdapter::ColumnTypes::INTEGER, DBAdapter::ColumnTypes::INTEGER_ARRAY, DBAdapter::ColumnTypes::OBJECT, DBAdapter::ColumnTypes::TEXT, DBAdapter::ColumnTypes::TEXT_ARRAY, DBAdapter::ColumnTypes::TIMESTAMP, DBAdapter::ColumnTypes::UUID

Instance Method Summary collapse

Instance Method Details

#_remote_key_columnObject



16
17
18
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 16

def _remote_key_column
  return Webhookdb::Replicator::Column.new(:convertkit_id, BIGINT, data_key: "id")
end

#_verify_backfill_401_err_msgObject



45
46
47
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 45

def _verify_backfill_401_err_msg
  return "It looks like that API Secret is invalid. Please reenter the API Secret:"
end

#_verify_backfill_err_msgObject



49
50
51
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 49

def _verify_backfill_err_msg
  return "An error occurred. Please reenter the API Secret:"
end

#_webhook_response(_request) ⇒ Object



11
12
13
14
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 11

def _webhook_response(_request)
  # Webhook Authentication isn't supported
  return Webhookdb::WebhookResponse.ok
end

#backfiller_server_error_backoffObject



9
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 9

def backfiller_server_error_backoff = 121.seconds

#backfiller_server_error_retriesObject

ConvertKit gets a decent number of 5xx responses. Wait for about 20 minutes before the job dies.



8
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 8

def backfiller_server_error_retries = 10

#calculate_backfill_state_machineObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/webhookdb/replicator/convertkit_v1_mixin.rb', line 20

def calculate_backfill_state_machine
  step = Webhookdb::Replicator::StateMachineStep.new
  if self.service_integration.backfill_secret.blank?
    step.output = %(Great! We've created your #{self.resource_name_plural} integration.

#{self.resource_name_singular} webhooks are not designed to mirror data, so to fill your database,
we need to use the API to make requests, which requires your API Secret.
#{Webhookdb::Convertkit::FIND_API_SECRET_HELP}
    )
    return step.secret_prompt("API Secret").backfill_secret(self.service_integration)
  end

  unless (result = self.verify_backfill_credentials).verified
    self.service_integration.replicator.clear_backfill_information
    step.output = result.message
    return step.secret_prompt("API Secret").backfill_secret(self.service_integration)
  end

  step.output = %(We'll start backfilling your #{self.resource_name_plural} now,
and they will show up in your database momentarily.
#{self._query_help_output}
  )
  return step.completed
end