Class: Webhookdb::Replicator::SponsyPublicationV1
- Inherits:
-
Base
- Object
- Base
- Webhookdb::Replicator::SponsyPublicationV1
show all
- Includes:
- Appydays::Loggable, SponsyV1Mixin
- Defined in:
- lib/webhookdb/replicator/sponsy_publication_v1.rb
Defined Under Namespace
Classes: Backfiller
Constant Summary
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
Constants inherited
from Base
Base::MAX_INDEX_NAME_LENGTH
Instance Attribute Summary
Attributes inherited from Base
#service_integration
Class Method Summary
collapse
Instance Method Summary
collapse
#_parallel_backfill, #_publication_backfillers, #_remote_key_column, #_resource_and_event, #_timestamp_column_name, #_ts_columns, #_update_where_expr, #_verify_backfill_err_msg, #_webhook_response, #api_url, #auth_headers, #fetch_sponsy_page, #find_api_key, #on_dependency_webhook_upsert, #root_integration
Methods inherited from Base
#_any_subscriptions_to_notify?, #_backfill_state_change_fields, #_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, #_remote_key_column, #_resource_and_event, #_resource_to_data, #_store_enrichment_body?, #_timestamp_column_name, #_to_json, #_update_where_expr, #_upsert_update_expr, #_upsert_webhook, #_verify_backfill_err_msg, #_webhook_response, #_webhook_state_change_fields, #admin_dataset, #backfill, #backfill_not_supported_message, #calculate_and_backfill_state_machine, #calculate_dependency_state_machine_step, #calculate_preferred_create_state_machine, #calculate_webhook_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_backfill_error, #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
Class Method Details
.descriptor ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 9
def self.descriptor
return Webhookdb::Replicator::Descriptor.new(
name: "sponsy_publication_v1",
ctor: self,
feature_roles: [],
resource_name_singular: "Sponsy Publication",
supports_backfill: true,
api_docs_url: "https://api.getsponsy.com/docs",
)
end
|
Instance Method Details
#_backfillers ⇒ Object
70
71
72
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 70
def _backfillers
return [Backfiller.new(self)]
end
|
#_denormalized_columns ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 20
def _denormalized_columns
col = Webhookdb::Replicator::Column
return [
col.new(:name, TEXT),
col.new(:slug, TEXT),
col.new(:type, TEXT),
col.new(:deleted_at, TIMESTAMP, optional: true),
col.new(
:days,
INTEGER_ARRAY,
converter: col.converter_map_lookup(
array: true,
map: col::DAYS_OF_WEEK.rotate.each_with_index.to_h { |dow, idx| [dow, idx] },
),
),
col.new(
:days_normalized,
INTEGER_ARRAY,
data_key: "days",
converter: col.converter_map_lookup(
array: true,
map: col::DAYS_OF_WEEK.each_with_index.to_a.concat((0..6).zip((0..6).to_a.rotate)).to_h,
),
backfill_statement: Sequel.lit(<<~SQL),
CREATE OR REPLACE FUNCTION pg_temp.sponsy_publication_v1_normalize_days(integer[])
RETURNS integer[] AS 'SELECT ARRAY(SELECT ((n + 1) % 7) FROM unnest($1) AS n)' LANGUAGE sql IMMUTABLE
SQL
backfill_expr: Sequel.lit("pg_temp.sponsy_publication_v1_normalize_days(days)"),
),
col.new(
:day_names,
TEXT_ARRAY,
data_key: "days",
converter: col.converter_map_lookup(
array: true,
map: col::DAYS_OF_WEEK.rotate.each_with_index.to_h { |dow, idx| [idx, dow] },
),
backfill_statement: Sequel.lit(<<~SQL),
CREATE OR REPLACE FUNCTION pg_temp.sponsy_publication_v1_day_names(integer[])
RETURNS text[] AS 'SELECT ARRAY(SELECT (CASE WHEN n = 0 THEN ''MONDAY'' WHEN n = 1 THEN ''TUESDAY'' WHEN n = 2 THEN ''WEDNESDAY'' WHEN n = 3 THEN ''THURSDAY'' WHEN n = 4 THEN ''FRIDAY'' WHEN n = 5 THEN ''SATURDAY'' WHEN n = 6 THEN ''SUNDAY'' END) FROM unnest($1) AS n)' LANGUAGE sql IMMUTABLE
SQL
backfill_expr: Sequel.lit("pg_temp.sponsy_publication_v1_day_names(days)"),
),
].concat(self._ts_columns)
end
|
#_fetch_backfill_page(pagination_token, last_backfilled:) ⇒ Object
74
75
76
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 74
def _fetch_backfill_page(, last_backfilled:)
return self.fetch_sponsy_page("/v1/publications", , last_backfilled)
end
|
#_verify_backfill_401_err_msg ⇒ Object
105
106
107
108
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 105
def _verify_backfill_401_err_msg
return "It looks like that API Key is invalid. Head back to https://getsponsy.com/settings/workspace, " \
"copy the API key, and try again:"
end
|
#calculate_backfill_state_machine ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/webhookdb/replicator/sponsy_publication_v1.rb', line 78
def calculate_backfill_state_machine
step = Webhookdb::Replicator::StateMachineStep.new
unless self.service_integration.backfill_secret.present?
step.needs_input = true
step.output = %(Great! Let's work on your Sponsy Publications integration.
Head over to your Sponsy dashboard and copy your API key:
https://getsponsy.com/settings/workspace
)
return step.secret_prompt("API key").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 Key").backfill_secret(self.service_integration)
end
step.output = %(We are going to start replicating your Sponsy Publications
and will keep them updated. You can can also add more Sponsy integrations.
Run `webhookdb services list` to see what's available.
#{self._query_help_output}
)
return step.completed
end
|