Class: Webhooks::Outgoing::DeliveryAttempt
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Webhooks::Outgoing::DeliveryAttempt
- Defined in:
- app/models/webhooks/outgoing/delivery_attempt.rb
Instance Method Summary collapse
- #attempt ⇒ Object
- #failed? ⇒ Boolean
- #label_string ⇒ Object
- #still_attempting? ⇒ Boolean
- #successful? ⇒ Boolean
Instance Method Details
#attempt ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/webhooks/outgoing/delivery_attempt.rb', line 24 def attempt uri = URI.parse(delivery.endpoint_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == "https" request = Net::HTTP::Post.new(uri.path) request.add_field("Content-Type", "application/json") request.body = delivery.event.payload.to_json begin response = http.request(request) self. = response. self.response_code = response.code self.response_body = response.body rescue Exception => exception self.response_code = 0 self. = exception. end save successful? end |
#failed? ⇒ Boolean
20 21 22 |
# File 'app/models/webhooks/outgoing/delivery_attempt.rb', line 20 def failed? !(successful? || still_attempting?) end |
#label_string ⇒ Object
46 47 48 |
# File 'app/models/webhooks/outgoing/delivery_attempt.rb', line 46 def label_string "#{attempt_number.ordinalize} Attempt" end |
#still_attempting? ⇒ Boolean
12 13 14 |
# File 'app/models/webhooks/outgoing/delivery_attempt.rb', line 12 def still_attempting? .nil? && response_code.nil? end |
#successful? ⇒ Boolean
16 17 18 |
# File 'app/models/webhooks/outgoing/delivery_attempt.rb', line 16 def successful? [200, 201, 202, 203, 204, 205, 206, 207, 226].include?(response_code) end |