Class: Webhookdb::Replicator::EmailOctopusListV1
- Inherits:
-
Base
- Object
- Base
- Webhookdb::Replicator::EmailOctopusListV1
show all
- Includes:
- Appydays::Loggable
- Defined in:
- lib/webhookdb/replicator/email_octopus_list_v1.rb
Constant Summary
Constants inherited
from Base
Base::MAX_INDEX_NAME_LENGTH
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, #_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_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
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 9
def self.descriptor
return Webhookdb::Replicator::Descriptor.new(
name: "email_octopus_list_v1",
ctor: ->(sint) { Webhookdb::Replicator::EmailOctopusListV1.new(sint) },
feature_roles: [],
resource_name_singular: "Email Octopus List",
supports_backfill: true,
api_docs_url: "https://emailoctopus.com/api-documentation",
)
end
|
Instance Method Details
#_denormalized_columns ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 24
def _denormalized_columns
return [
Webhookdb::Replicator::Column.new(:name, TEXT),
Webhookdb::Replicator::Column.new(:created_at, TIMESTAMP, index: true, converter: :time),
Webhookdb::Replicator::Column.new(:pending, INTEGER, data_key: ["counts", "pending"]),
Webhookdb::Replicator::Column.new(:subscribed, INTEGER, data_key: ["counts", "subscribed"]),
Webhookdb::Replicator::Column.new(:unsubscribed, INTEGER, data_key: ["counts", "unsubscribed"]),
Webhookdb::Replicator::Column.new(:row_updated_at, TIMESTAMP, defaulter: :now, optional: true),
]
end
|
#_fetch_backfill_page(pagination_token) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 79
def _fetch_backfill_page(, **)
api_key = self.backfill_key!
limit = Webhookdb::EmailOctopus.page_size
base_url = "https://emailoctopus.com"
endpoint_path = || "/api/1.6/lists?api_key=#{api_key}&limit=#{limit}"
response = Webhookdb::Http.get(
base_url + endpoint_path,
logger: self.logger,
timeout: Webhookdb::EmailOctopus.http_timeout,
)
data = response.parsed_response
next_page_link = data.dig("paging", "next")
return data["data"], next_page_link
end
|
#_remote_key_column ⇒ Object
20
21
22
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 20
def _remote_key_column
return Webhookdb::Replicator::Column.new(:email_octopus_id, TEXT, data_key: "id")
end
|
#_resource_and_event(request) ⇒ Object
35
36
37
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 35
def _resource_and_event(request)
return request.body, nil
end
|
#_timestamp_column_name ⇒ Object
43
44
45
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 43
def _timestamp_column_name
return :row_updated_at
end
|
#_update_where_expr ⇒ Object
39
40
41
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 39
def _update_where_expr
return self.qualified_table_sequel_identifier[:data] !~ Sequel[:excluded][:data]
end
|
#_verify_backfill_err_msg ⇒ Object
75
76
77
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 75
def _verify_backfill_err_msg
return "It looks like that API key is invalid. Please reenter your API Key:"
end
|
#_webhook_response(_request) ⇒ Object
47
48
49
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 47
def _webhook_response(_request)
return Webhookdb::WebhookResponse.ok
end
|
#backfill_key! ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 94
def backfill_key!
bk = self.service_integration.backfill_key
return bk if bk.present?
raise Webhookdb::Replicator::CredentialsMissing,
"This integration requires that the #{self.descriptor.name} integration has a valid API Key"
end
|
#calculate_backfill_state_machine ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/webhookdb/replicator/email_octopus_list_v1.rb', line 51
def calculate_backfill_state_machine
step = Webhookdb::Replicator::StateMachineStep.new
unless self.service_integration.backfill_key.present?
step.output = %(In order to replicate #{self.resource_name_plural} into WebhookDB, we need an API Key.
From your Email Octopus dashboard, go to Account Settings -> Integrations & API.
Then, click through to the API menu, under the "Developer tools" header and create a key.
Copy the key.
)
return step.secret_prompt("API Key").backfill_key(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_key(self.service_integration)
end
step.output = %(Great! We are going to start replicating your #{self.resource_name_plural}.
#{self._query_help_output}
)
return step.completed
end
|