Module: Webhookdb::Replicator::IncreaseV1Mixin
- Included in:
- IncreaseACHTransferV1, IncreaseAccountNumberV1, IncreaseAccountTransferV1, IncreaseAccountV1, IncreaseCheckTransferV1, IncreaseLimitV1, IncreaseTransactionV1, IncreaseWireTransferV1
- Defined in:
- lib/webhookdb/replicator/increase_v1_mixin.rb
Instance Method Summary collapse
- #_fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object
- #_find_resource_and_event(body, desired_object_name) ⇒ Object
- #_mixin_backfill_url ⇒ Object
- #_timestamp_column_name ⇒ Object
- #_verify_backfill_401_err_msg ⇒ Object
- #_verify_backfill_err_msg ⇒ Object
- #_webhook_response(request) ⇒ Object
- #calculate_backfill_state_machine ⇒ Object
- #calculate_webhook_state_machine ⇒ Object
- #process_state_change(field, value) ⇒ Object
Instance Method Details
#_fetch_backfill_page(pagination_token, **_kwargs) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 107 def _fetch_backfill_page(pagination_token, **_kwargs) query = {} (query[:cursor] = pagination_token) if pagination_token.present? response = Webhookdb::Http.get( self._mixin_backfill_url, query, headers: {"Authorization" => ("Bearer " + self.service_integration.backfill_key)}, logger: self.logger, timeout: Webhookdb::Increase.http_timeout, ) data = response.parsed_response next_page_param = data.dig("response_metadata", "next_cursor") return data["data"], next_page_param end |
#_find_resource_and_event(body, desired_object_name) ⇒ Object
18 19 20 21 22 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 18 def _find_resource_and_event(body, desired_object_name) return nil unless Webhookdb::Increase.contains_desired_object(body, desired_object_name) return body.fetch("data"), body if body.key?("event") && body.key?("event_id") return body, nil end |
#_mixin_backfill_url ⇒ Object
6 7 8 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 6 def _mixin_backfill_url raise NotImplementedError end |
#_timestamp_column_name ⇒ Object
14 15 16 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 14 def return :updated_at end |
#_verify_backfill_401_err_msg ⇒ Object
99 100 101 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 99 def _verify_backfill_401_err_msg return "It looks like that API Key is invalid. Please reenter the API Key you just created:" end |
#_verify_backfill_err_msg ⇒ Object
103 104 105 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 103 def _verify_backfill_err_msg return "An error occurred. Please reenter the API Key you just created:" end |
#_webhook_response(request) ⇒ Object
10 11 12 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 10 def _webhook_response(request) return Webhookdb::Increase.webhook_response(request, self.service_integration.webhook_secret) end |
#calculate_backfill_state_machine ⇒ Object
59 60 61 62 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 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 59 def calculate_backfill_state_machine step = Webhookdb::Replicator::StateMachineStep.new unless self.service_integration.backfill_key.present? step.output = %(In order to backfill #{self.resource_name_plural}, we need an API key. From your Increase admin dashboard, go to Settings -> Development -> API Keys. We'll need the Production key--copy that value to your clipboard. ) return step.secret_prompt("API Key").backfill_key(self.service_integration) end unless self.service_integration.api_url.present? step.output = %(Great. Now we want to make sure we're sending API requests to the right place. For Increase, the API url is different when you are in Sandbox mode and when you are in Production mode. For Sandbox mode, the API root url is: https://sandbox.increase.com For Production mode, which is our default, it is: https://api.increase.com Leave blank to use the default or paste the answer into this prompt. ) return step.prompting("API url").api_url(self.service_integration) end unless (result = self.verify_backfill_credentials).verified self.service_integration.replicator.clear_backfill_information step.output = result. return step.secret_prompt("API Key").backfill_key(self.service_integration) end step.needs_input = false step.output = %(Great! We are going to start backfilling your #{self.resource_name_plural}. #{self._query_help_output} ) step.complete = true return step end |
#calculate_webhook_state_machine ⇒ Object
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 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 30 def calculate_webhook_state_machine step = Webhookdb::Replicator::StateMachineStep.new # if the service integration doesn't exist, create it with some standard values unless self.service_integration.webhook_secret.present? step.output = %(You are about to start replicating #{self.resource_name_plural} info into WebhookDB. We've made an endpoint available for #{self.resource_name_singular} webhooks: #{self._webhook_endpoint} From your Increase admin dashboard, go to Applications -> Create Webhook. In the "Webhook endpoint URL" field you can enter the URL above. For the shared secret, you'll have to generate a strong password (you can use '#{Webhookdb::Id.rand_enc(16)}') and then enter it into the textbox. Copy that shared secret value. ) return step.secret_prompt("secret").webhook_secret(self.service_integration) end step.output = %(Great! WebhookDB is now listening for #{self.resource_name_singular} webhooks. #{self._query_help_output} In order to backfill existing #{self.resource_name_plural}, run this from a shell: #{self._backfill_command} ) return step.completed end |
#process_state_change(field, value) ⇒ Object
24 25 26 27 28 |
# File 'lib/webhookdb/replicator/increase_v1_mixin.rb', line 24 def process_state_change(field, value) # special handling for having a default value for api url value = "https://api.increase.com" if field == "api_url" && value == "" return super(field, value) end |