Class: Webhookdb::Replicator::PostmarkOutboundMessageEventV1

Inherits:
Base
  • Object
show all
Includes:
Appydays::Loggable
Defined in:
lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb

Constant Summary collapse

TIMESTAMP_KEYS =
["ReceivedAt", "DeliveredAt", "BouncedAt", "ChangedAt"].freeze
LOOKUP_TIMESTAMP =
Webhookdb::Replicator::Column::IsomorphicProc.new(
  ruby: lambda do |resource:, **|
    tskey = TIMESTAMP_KEYS.find { |k| resource[k] }
    raise KeyError, "Cannot find valid timestamp key in #{resource}" if tskey.nil?
    resource[tskey]
  end,
)
BUILD_EVENT_MD5 =
Webhookdb::Replicator::Column::IsomorphicProc.new(
  ruby: lambda do |resource:, **|
    md5 = Digest::MD5.new
    md5.update(resource.fetch("MessageID"))
    md5.update(resource.fetch("RecordType"))
    md5.update(LOOKUP_TIMESTAMP.ruby.call(resource:))
    md5.hexdigest
  end,
)

Constants inherited from Base

Base::MAX_INDEX_NAME_LENGTH

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 Attribute Summary

Attributes inherited from Base

#service_integration

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#_any_subscriptions_to_notify?, #_backfill_state_change_fields, #_backfillers, #_clear_backfill_information, #_clear_webook_information, #_coalesce_excluded_on_update, #_enqueue_backfill_jobs, #_extra_index_specs, #_fetch_enrichment, #_find_dependency_candidate, #_notify_dependents, #_parallel_backfill, #_prepare_for_insert, #_publish_rowupsert, #_resource_to_data, #_store_enrichment_body?, #_to_json, #_upsert_update_expr, #_upsert_webhook, #_verify_backfill_err_msg, #_webhook_state_change_fields, #admin_dataset, #backfill, #calculate_and_backfill_state_machine, #calculate_backfill_state_machine, #calculate_dependency_state_machine_step, #calculate_preferred_create_state_machine, chunked_row_update_bounds, #clear_backfill_information, #clear_webhook_information, #create_table, #create_table_modification, #data_column, #dbadapter_table, #denormalized_columns, #descriptor, #dispatch_request_to, #documentation_url, #enqueue_sync_targets, #enrichment_column, #ensure_all_columns, #ensure_all_columns_modification, #find_dependent, #find_dependent!, #indices, #initialize, #on_dependency_webhook_upsert, #preferred_create_state_machine_method, #preprocess_headers_for_logging, #primary_key_column, #process_state_change, #process_webhooks_synchronously?, #qualified_table_sequel_identifier, #readonly_dataset, #remote_key_column, #requires_sequence?, #resource_name_plural, #resource_name_singular, #schema_and_table_symbols, #storable_columns, #synchronous_processing_response_body, #timestamp_column, #upsert_has_deps?, #upsert_webhook, #upsert_webhook_body, #verify_backfill_credentials, #webhook_endpoint, #webhook_response

Constructor Details

This class inherits a constructor from Webhookdb::Replicator::Base

Class Method Details

.descriptorWebhookdb::Replicator::Descriptor



9
10
11
12
13
14
15
16
17
18
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 9

def self.descriptor
  return Webhookdb::Replicator::Descriptor.new(
    name: "postmark_outbound_message_event_v1",
    ctor: ->(sint) { Webhookdb::Replicator::PostmarkOutboundMessageEventV1.new(sint) },
    feature_roles: [],
    resource_name_singular: "Postmark Outbound Message Event",
    supports_webhooks: true,
    api_docs_url: "https://postmarkapp.com/developer/webhooks/webhooks-overview",
  )
end

Instance Method Details

#_denormalized_columnsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 44

def _denormalized_columns
  col = Webhookdb::Replicator::Column
  return [
    col.new(:message_id, TEXT, index: true, data_key: "MessageID"),
    col.new(:timestamp, TIMESTAMP, index: true, optional: true, defaulter: LOOKUP_TIMESTAMP),
    col.new(:record_type, TEXT, index: true, optional: true, data_key: "RecordType"),
    col.new(:tag, TEXT, index: true, optional: true, data_key: "Tag"),
    col.new(:recipient, TEXT, index: true, optional: true, data_key: "Recipient"),
    col.new(:changed_at, TIMESTAMP, index: true, optional: true, data_key: "ChangedAt"),
    col.new(:delivered_at, TIMESTAMP, index: true, optional: true, data_key: "DeliveredAt"),
    col.new(:received_at, TIMESTAMP, index: true, optional: true, data_key: "ReceivedAt"),
    col.new(:bounced_at, TIMESTAMP, index: true, optional: true, data_key: "BouncedAt"),
  ]
end

#_remote_key_columnObject



40
41
42
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 40

def _remote_key_column
  return Webhookdb::Replicator::Column.new(:event_id, UUID, optional: true, defaulter: BUILD_EVENT_MD5)
end

#_resource_and_event(request) ⇒ Object



63
64
65
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 63

def _resource_and_event(request)
  return request.body, nil
end

#_timestamp_column_nameObject



59
60
61
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 59

def _timestamp_column_name
  return :timestamp
end

#_update_where_exprObject



67
68
69
70
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 67

def _update_where_expr
  # Since the primary key is based on the timestamp, we never do updates
  return Sequel[false]
end

#_webhook_response(request) ⇒ Object



72
73
74
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 72

def _webhook_response(request)
  return Webhookdb::Postmark.webhook_response(request)
end

#backfill_not_supported_messageObject



100
101
102
103
104
105
106
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 100

def backfill_not_supported_message
  return %(We don't yet support backfilling Postmark Outbound Message Events.

File an issue at #{Webhookdb.oss_repo_url} or email [email protected] to let us know if this is something you want!

Run `webhookdb integration reset #{self.service_integration.opaque_id}` to go through webhook setup.)
end

#calculate_webhook_state_machineObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/webhookdb/replicator/postmark_outbound_message_event_v1.rb', line 76

def calculate_webhook_state_machine
  step = Webhookdb::Replicator::StateMachineStep.new
  if self.service_integration.webhook_secret.blank?
    step.output = %(You are about to set up webhooks for Postmark Outbound Message Events,
like deliveries, clicks, and opens.

1. In the Postmark UI, locate the server and stream (Transactional or Broadcast) you want to record.
2. Click on the 'Webhooks' tab.
3. Use this Webhook URL: #{self.webhook_endpoint}
4. Check the events you want to send.
5. Hit 'Send test' and verify it works. If it does not, double check your settings.
6. Hit 'Save Changes')
    step.set_prompt("Press Enter after Saved Changes succeeds:")
    step.transition_field(self.service_integration, "noop_create")
    self.service_integration.update(webhook_secret: "placeholder")
    return step
  end
  step.output = %(
All set! Events will be synced as they come in.

#{self._query_help_output})
  return step.completed
end