Class: PactBroker::Domain::WebhookRequest
- Inherits:
-
Object
- Object
- PactBroker::Domain::WebhookRequest
- Defined in:
- lib/pact_broker/domain/webhook_request.rb
Constant Summary
Constants included from Logging
Logging::LOG_DIR, Logging::LOG_FILE_NAME
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
(also: #http_method)
Returns the value of attribute method.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #description ⇒ Object
- #display_password ⇒ Object
- #execute ⇒ Object
-
#initialize(attributes = {}) ⇒ WebhookRequest
constructor
A new instance of WebhookRequest.
Methods included from Messages
#message, #potential_duplicate_pacticipant_message, #validation_message
Methods included from Logging
Constructor Details
#initialize(attributes = {}) ⇒ WebhookRequest
Returns a new instance of WebhookRequest.
31 32 33 34 35 36 37 38 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 31 def initialize attributes = {} @method = attributes[:method] @url = attributes[:url] @username = attributes[:username] @password = attributes[:password] @headers = attributes[:headers] || {} @body = attributes[:body] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def headers @headers end |
#method ⇒ Object Also known as: http_method
Returns the value of attribute method.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def method @method end |
#password ⇒ Object
Returns the value of attribute password.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def password @password end |
#url ⇒ Object
Returns the value of attribute url.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def username @username end |
Instance Method Details
#description ⇒ Object
40 41 42 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 40 def description "#{method.upcase} #{URI(url).host}" end |
#display_password ⇒ Object
44 45 46 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 44 def display_password password.nil? ? nil : "**********" end |
#execute ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 48 def execute begin req = http_request headers.each_pair do | name, value | req[name] = value end req.basic_auth(username, password) if username req.body = body logger.info "Making webhook request #{to_s}" response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request req end logger.info "Received response status=#{response.code} body=#{response.body}" WebhookExecutionResult.new(response) rescue StandardError => e logger.error "Error executing webhook #{e.class.name} - #{e.}" logger.error e.backtrace.join("\n") WebhookExecutionResult.new(nil, e) end end |