Class: Envoy::Webhook
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#url ⇒ Object
Returns the value of attribute url.
Attributes inherited from Transport
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Webhook
constructor
A new instance of Webhook.
- #send_message(message) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Webhook
Returns a new instance of Webhook.
62 63 64 65 |
# File 'lib/envoy/transport.rb', line 62 def initialize( = {}) self.url = [:url] self.headers = [:headers] || {} end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
60 61 62 |
# File 'lib/envoy/transport.rb', line 60 def headers @headers end |
#url ⇒ Object
Returns the value of attribute url.
60 61 62 |
# File 'lib/envoy/transport.rb', line 60 def url @url end |
Instance Method Details
#send_message(message) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/envoy/transport.rb', line 67 def () url = URI.parse(@url) request = Net::HTTP::Post.new(url.path) request.body = . @headers.each do |k,v| request.add_field k,v end response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)} case response when Net::HTTPSuccess, Net::HTTPFound return true else return false end rescue URI::InvalidURIError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => error self.errors << SendError.new(error, Time.now) return false end |