class Flock::Notifier::Connection

Public Class Methods

new(incoming_webhook_url) click to toggle source
# File lib/flock/notifier/connection.rb, line 10
def initialize(incoming_webhook_url)
  uri       = URI.parse(incoming_webhook_url)
  header    = { 'Content-Type': 'application/json' }

  @http         = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = true

  @request = Net::HTTP::Post.new(uri.request_uri, header)
end

Public Instance Methods

post(message) click to toggle source
# File lib/flock/notifier/connection.rb, line 20
def post(message)
  payload       = { "text": message }
  @request.body = payload.to_json

  # Send the request
  @http.request(@request)
end