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.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
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
included, #log_error, #logger, #logger=
Constructor Details
#initialize(attributes = {}) ⇒ WebhookRequest
Returns a new instance of WebhookRequest.
31 32 33 34 35 36 37 38 39 |
# 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] @uuid = attributes[:uuid] 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 |
#uuid ⇒ Object
Returns the value of attribute uuid.
25 26 27 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 25 def uuid @uuid end |
Instance Method Details
#description ⇒ Object
41 42 43 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 41 def description "#{method.upcase} #{URI(url).host}" end |
#display_password ⇒ Object
45 46 47 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 45 def display_password password.nil? ? nil : "**********" end |
#execute ⇒ Object
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 77 78 79 80 81 82 83 84 |
# File 'lib/pact_broker/domain/webhook_request.rb', line 49 def execute begin req = http_request headers.each_pair do | name, value | req[name] = value end req.basic_auth(username, password) if username unless body.nil? if String === body req.body = body else req.body = body.to_json end end logger.info "Making webhook #{uuid} 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 for webhook #{uuid} status=#{response.code}" logger.debug "body=#{response.body}" WebhookExecutionResult.new(response) rescue StandardError => e logger.error "Error executing webhook #{uuid} #{e.class.name} - #{e.}" logger.error e.backtrace.join("\n") WebhookExecutionResult.new(nil, e) end end |