Class: Webhookdb::Replicator::PlivoSmsInboundV1
- Inherits:
-
Base
- Object
- Base
- Webhookdb::Replicator::PlivoSmsInboundV1
show all
- Includes:
- Appydays::Loggable
- Defined in:
- lib/webhookdb/replicator/plivo_sms_inbound_v1.rb
Constant Summary
collapse
- INTEGER_KEYS =
["TotalAmount", "TotalRate", "Units"].freeze
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, #_store_enrichment_body?, #_to_json, #_upsert_update_expr, #_upsert_webhook, #_verify_backfill_err_msg, #_webhook_state_change_fields, #admin_dataset, #backfill, #backfill_not_supported_message, #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
Class Method Details
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 9
def self.descriptor
return Webhookdb::Replicator::Descriptor.new(
name: "plivo_sms_inbound_v1",
ctor: ->(sint) { Webhookdb::Replicator::PlivoSmsInboundV1.new(sint) },
feature_roles: ["beta"],
resource_name_singular: "Plivo Inbound SMS Message",
supports_webhooks: true,
api_docs_url: "https://www.plivo.com/docs/sms/api/message#the-message-object",
)
end
|
Instance Method Details
#_denormalized_columns ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 24
def _denormalized_columns
return [
Webhookdb::Replicator::Column.new(:row_inserted_at, TIMESTAMP, defaulter: :now, optional: true, index: true),
Webhookdb::Replicator::Column.new(:from_number, TEXT, data_key: "From", index: true),
Webhookdb::Replicator::Column.new(:to_number, TEXT, data_key: "To", index: true),
]
end
|
#_remote_key_column ⇒ Object
20
21
22
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 20
def _remote_key_column
return Webhookdb::Replicator::Column.new(:plivo_message_uuid, TEXT, data_key: "MessageUUID")
end
|
#_resource_and_event(request) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 45
def _resource_and_event(request)
body = request.body
raise Webhookdb::InvalidPrecondition, "body should be form-encoded string" unless body.is_a?(String)
resource = URI.decode_www_form(body).to_h
return resource, nil
end
|
#_resource_to_data(resource) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 54
def _resource_to_data(resource, *)
super
h = resource.dup
INTEGER_KEYS.each do |k|
h[k] = h[k].to_i if h.key?(k)
end
return h
end
|
#_timestamp_column_name ⇒ Object
32
33
34
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 32
def _timestamp_column_name
return :row_inserted_at
end
|
#_update_where_expr ⇒ Object
36
37
38
39
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 36
def _update_where_expr
return Sequel[false]
end
|
#_webhook_response(request) ⇒ Object
41
42
43
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 41
def _webhook_response(request)
return Webhookdb::Plivo.webhook_response(request, self.service_integration.backfill_secret)
end
|
#calculate_webhook_state_machine ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/webhookdb/replicator/plivo_sms_inbound_v1.rb', line 63
def calculate_webhook_state_machine
step = Webhookdb::Replicator::StateMachineStep.new
if self.service_integration.backfill_key.blank?
step.output = %(You are about to set up an endpoint to receive #{self.resource_name_plural}.
You'll need to give us your Auth ID and Auth Token so we can validate webhooks.
Once that is set up, we'll help you set up your WebhookDB endpoint in Plivo.)
return step.secret_prompt("Auth ID").backfill_key(self.service_integration)
end
if self.service_integration.backfill_secret.blank?
return step.secret_prompt("Auth Token").backfill_secret(self.service_integration)
end
begin
Webhookdb::Plivo.request(
:get,
"/",
auth_id: self.service_integration.backfill_key,
auth_token: self.service_integration.backfill_secret,
timeout: Webhookdb::Plivo.http_timeout,
)
rescue Webhookdb::Http::Error => e
self.service_integration.update(backfill_key: "", backfill_secret: "")
step.output = %(Those credentials didn't work (Plivo returned an HTTP #{e.status} error).
Let's start over with your Auth ID (it probably begins with an MA or SA).)
return step.secret_prompt("Auth ID").backfill_key(self.service_integration)
end
step.output = %(Perfect, those credentials check out.
You can use this endpoint in your Plivo Application to receive webhooks:
#{self._webhook_endpoint}
This can be done through the UI, or the API by creating or updating an Application under your Account.
As messages comes in, they'll be upserted into your table.
#{self._query_help_output}
You can also use `webhookdb httpsync` to set up notifications to your own server
when rows are modified.)
return step.completed
end
|