Class: Lifter::Webhook

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#headersObject

Returns the value of attribute headers.



31
32
33
# File 'lib/lifter/webhook.rb', line 31

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



31
32
33
# File 'lib/lifter/webhook.rb', line 31

def method
  @method
end

#paramsObject

Returns the value of attribute params.



31
32
33
# File 'lib/lifter/webhook.rb', line 31

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



31
32
33
# File 'lib/lifter/webhook.rb', line 31

def url
  @url
end

Instance Method Details

#deliverObject



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