Class: Lifter::Webhook
- Inherits:
-
Object
- Object
- Lifter::Webhook
- Defined in:
- lib/lifter/webhook.rb
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
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
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/lifter/webhook.rb', line 5 def headers @headers end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
5 6 7 |
# File 'lib/lifter/webhook.rb', line 5 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/lifter/webhook.rb', line 5 def params @params end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
5 6 7 |
# File 'lib/lifter/webhook.rb', line 5 def url @url end |
Instance Method Details
#deliver ⇒ Object
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 |