Class: Plaid::Webhook
- Inherits:
-
Object
- Object
- Plaid::Webhook
- Defined in:
- lib/plaid/webhook.rb
Overview
Public: Representation of a webhook.
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Public: The String access token for authenticated user.
-
#code ⇒ Object
readonly
Public: The Integer code denoting the type of webhook this is.
-
#message ⇒ Object
readonly
Public: The String human readable explanation of this webhook request.
-
#total_transactions ⇒ Object
readonly
Public: The Integer number of transactions available in Plaid.
Instance Method Summary collapse
-
#error ⇒ Object
Public: Get a Plaid::Error instance if this is an Error Response Webhook.
-
#error_response? ⇒ Boolean
Public: Detect if the webhook is Error Response Webhook.
-
#historical_transaction? ⇒ Boolean
Public: Detect if the webhook is Historical Transaction Webhook.
-
#income? ⇒ Boolean
Public: Detect if the webhook is Income.
-
#initial_transaction? ⇒ Boolean
Public: Detect if the webhook is Initial Transaction Webhook.
-
#initialize(fields) ⇒ Webhook
constructor
Public: Initialize a Webhook instance.
-
#inspect ⇒ Object
(also: #to_s)
Public: Get a String representation of the transaction.
-
#normal_transaction? ⇒ Boolean
Public: Detect if the webhook is Normal Transaction Webhook.
-
#removed_transaction? ⇒ Boolean
Public: Detect if the webhook is Removed Transaction Webhook.
-
#removed_transactions_ids ⇒ Object
Public: Get transaction IDs that were removed.
-
#risk? ⇒ Boolean
Public: Detect if the webhook is Risk.
-
#type ⇒ Object
Public: Share the type of Webhook this is from its code.
-
#user_webhook_updated? ⇒ Boolean
Public: Detect if the webhook is User’s Webhook Updated.
Constructor Details
#initialize(fields) ⇒ Webhook
Public: Initialize a Webhook instance.
fields - The Hash with fields.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/plaid/webhook.rb', line 21 def initialize(fields) @message = fields['message'] @access_token = fields['access_token'] @total_transactions = fields['total_transactions'] @code = fields['code'] # present only for Removed Transaction Webhook @removed_transactions = fields['removed_transactions'] # present only for Error Response Webhook @resolve = fields['resolve'] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Public: The String access token for authenticated user.
9 10 11 |
# File 'lib/plaid/webhook.rb', line 9 def access_token @access_token end |
#code ⇒ Object (readonly)
Public: The Integer code denoting the type of webhook this is. E.g. 0
16 17 18 |
# File 'lib/plaid/webhook.rb', line 16 def code @code end |
#message ⇒ Object (readonly)
Public: The String human readable explanation of this webhook request. E.g. “Initial transaction pull finished”.
6 7 8 |
# File 'lib/plaid/webhook.rb', line 6 def @message end |
#total_transactions ⇒ Object (readonly)
Public: The Integer number of transactions available in Plaid. E.g. 124
13 14 15 |
# File 'lib/plaid/webhook.rb', line 13 def total_transactions @total_transactions end |
Instance Method Details
#error ⇒ Object
Public: Get a Plaid::Error instance if this is an Error Response Webhook
Returns Plaid::Error or nil
114 115 116 117 118 |
# File 'lib/plaid/webhook.rb', line 114 def error if error_response? Plaid::PlaidError.new @code, @message, @resolve end end |
#error_response? ⇒ Boolean
Public: Detect if the webhook is Error Response Webhook. Triggered when an error has occurred. Includes the relevant Plaid error code with details on both the error type and steps for error resolution.
Returns true if it is.
100 101 102 |
# File 'lib/plaid/webhook.rb', line 100 def error_response? Webhook::CODEX[code].nil? end |
#historical_transaction? ⇒ Boolean
Public: Detect if the webhook is Historical Transaction Webhook. Occurs once the historical transaction pull has completed, shortly after the initial transaction pull.
Returns true if it is.
52 53 54 |
# File 'lib/plaid/webhook.rb', line 52 def historical_transaction? code == Webhook::HISTORICAL_TRANSACTION end |
#income? ⇒ Boolean
Public: Detect if the webhook is Income. Occurs when Income data is ready.
Returns true if it is.
84 85 86 |
# File 'lib/plaid/webhook.rb', line 84 def income? code == Webhook::INCOME end |
#initial_transaction? ⇒ Boolean
Public: Detect if the webhook is Initial Transaction Webhook. Occurs once the initial transaction pull has finished.
Returns true if it is.
43 44 45 |
# File 'lib/plaid/webhook.rb', line 43 def initial_transaction? code == Webhook::INITIAL_TRANSACTION end |
#inspect ⇒ Object Also known as: to_s
Public: Get a String representation of the transaction.
Returns a String.
123 124 125 126 |
# File 'lib/plaid/webhook.rb', line 123 def inspect "#<Plaid::Webhook type=#{type.inspect} code=#{code.inspect}, access_token=#{access_token.inspect}, " \ "total_transactions=#{total_transactions.inspect}, message=#{.inspect}>" end |
#normal_transaction? ⇒ Boolean
Public: Detect if the webhook is Normal Transaction Webhook. Occurs at set intervals throughout the day as data is updated from the financial institutions.
Returns true if it is.
61 62 63 |
# File 'lib/plaid/webhook.rb', line 61 def normal_transaction? code == Webhook::NORMAL_TRANSACTION end |
#removed_transaction? ⇒ Boolean
Public: Detect if the webhook is Removed Transaction Webhook. Occurs when transactions have been removed from our system.
Returns true if it is.
69 70 71 |
# File 'lib/plaid/webhook.rb', line 69 def removed_transaction? code == Webhook::REMOVED_TRANSACTION end |
#removed_transactions_ids ⇒ Object
Public: Get transaction IDs that were removed.
Returns Array or nil
107 108 109 |
# File 'lib/plaid/webhook.rb', line 107 def removed_transactions_ids @removed_transactions end |
#risk? ⇒ Boolean
Public: Detect if the webhook is Risk. Occurs when Risk data is ready.
Returns true if it is.
91 92 93 |
# File 'lib/plaid/webhook.rb', line 91 def risk? code == Webhook::RISK end |
#type ⇒ Object
Public: Share the type of Webhook this is from its code
Returns String webhook type
35 36 37 |
# File 'lib/plaid/webhook.rb', line 35 def type Webhook::CODEX[code] || 'ERROR_RESPONSE' end |
#user_webhook_updated? ⇒ Boolean
Public: Detect if the webhook is User’s Webhook Updated. Occurs when an user’s webhook is updated via a PATCH request without credentials.
Returns true if it is.
77 78 79 |
# File 'lib/plaid/webhook.rb', line 77 def user_webhook_updated? code == Webhook::USER_WEBHOOK_UPDATED end |