Class: Lifter::Webhook
- Inherits:
-
Object
- Object
- Lifter::Webhook
- Defined in:
- lib/lifter/webhook.rb
Defined Under Namespace
Modules: ParamNester
Constant Summary collapse
- RETRY_CODES =
[500, 502, 503, 504]
- RETRY_LIMIT =
3
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #deliver ⇒ Object
-
#initialize(endpoint) ⇒ Webhook
constructor
A new instance of Webhook.
- #on_failure(&block) ⇒ Object
- #on_success(&block) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ Webhook
Returns a new instance of Webhook.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lifter/webhook.rb', line 33 def initialize(endpoint) @url = endpoint.url @method = endpoint.method @headers = {} @params = {} @retry_count = 0 @retry_limit = RETRY_LIMIT @on_success = nil @on_failure = nil end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
31 32 33 |
# File 'lib/lifter/webhook.rb', line 31 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
31 32 33 |
# File 'lib/lifter/webhook.rb', line 31 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
31 32 33 |
# File 'lib/lifter/webhook.rb', line 31 def params @params end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
31 32 33 |
# File 'lib/lifter/webhook.rb', line 31 def url @url end |
Instance Method Details
#deliver ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/lifter/webhook.rb', line 62 def deliver begin start_delivery rescue Errors::WebhookFailed => e @on_failure.call if !@on_failure.nil? end @on_success.call if !@on_success.nil? end |
#on_failure(&block) ⇒ Object
58 59 60 |
# File 'lib/lifter/webhook.rb', line 58 def on_failure(&block) @on_failure = block end |
#on_success(&block) ⇒ Object
54 55 56 |
# File 'lib/lifter/webhook.rb', line 54 def on_success(&block) @on_success = block end |