Class: Lifter::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/lifter/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Webhook

Returns a new instance of Webhook.



7
8
9
10
11
12
# File 'lib/lifter/webhook.rb', line 7

def initialize(endpoint)
  @url = endpoint.url
  @method = endpoint.method
  @headers = {}
  @params = {}
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/lifter/webhook.rb', line 5

def headers
  @headers
end

#methodObject (readonly)

Returns the value of attribute method.



5
6
7
# File 'lib/lifter/webhook.rb', line 5

def method
  @method
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/lifter/webhook.rb', line 5

def params
  @params
end

#urlObject (readonly)

Returns the value of attribute url.



5
6
7
# File 'lib/lifter/webhook.rb', line 5

def url
  @url
end

Instance Method Details

#deliverObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lifter/webhook.rb', line 26

def deliver
  http_stub = HTTP.headers(@headers)

  case @method.to_sym
  when :get
    http_stub.get(@url, params: @params)
  when :post
    http_stub.post(@url, form: @params)
  when :put
    http_stub.put(@url, form: @params)
  else
    raise StandardError.new('unsupported http method in webhook')
  end
end

#on_failure(&block) ⇒ Object



22
23
24
# File 'lib/lifter/webhook.rb', line 22

def on_failure(&block)
  @on_failure = block
end