Created
February 4, 2019 02:45
-
-
Save gordysc/ff50bd8d8554feaaa05fc29f2b0ee8ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SlackWebhook | |
attr_accessor :webhook | |
def initialize(webhook) | |
@webhook = webhook | |
end | |
def send_message(text) | |
uri = URI(webhook) | |
connection.post do |req| | |
req.url uri.path | |
req.headers['Content-Type'] = 'application/json' | |
req.body = { text: text }.to_json | |
end | |
end | |
private | |
def connection | |
Faraday.new(url: "https://hooks.slack.com") do |faraday| | |
faraday.response :json, content_type: /\bjson$/, parser_options: { symbolize_names: true } | |
faraday.adapter Faraday.default_adapter | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment