module Slackpost
docs
Constants
- VERSION
Public Class Methods
config()
click to toggle source
# File lib/slackpost.rb, line 13 def config @config ||= Configuration.new end
configure() { |config| ... }
click to toggle source
# File lib/slackpost.rb, line 17 def configure yield(config) end
send_attachment(msg, channel, attachments)
click to toggle source
# File lib/slackpost.rb, line 28 def send_attachment(msg, channel, attachments) body = { channel: channel, link_names: 1, text: msg, attachments: [attachments].flatten } send_slack(body) end
send_message(msg, channel)
click to toggle source
# File lib/slackpost.rb, line 21 def send_message(msg, channel) body = { channel: channel, link_names: 1, text: msg } send_slack(body) end
Private Class Methods
send_slack(body)
click to toggle source
# File lib/slackpost.rb, line 38 def send_slack(body) uri = URI.parse("https://hooks.slack.com/services/#{config.slack_token}") response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| request = Net::HTTP::Post.new(uri) request['Content-Type'] = 'application/json' request.body = body.to_json http.request(request) end raise SlackpostError if response.code != '200' response end