module Slackr::IncomingWebhook
Attributes
connection[RW]
Public Instance Methods
say(connection, text="", options={})
click to toggle source
{
:formatter => [BasicFormatter, LinkFormatter, AttachmentFormatter]
}
# File lib/slackr/webhooks/incoming.rb, line 15 def say(connection, text="", options={}) @connection = connection #formatter = options[:formatter] || BasicFormatter #text = format_text(formatter, text) #TODO: fix law of demeter violations request = Net::HTTP::Post.new(service_url) request.body = encode_message(text, options) response = connection.http_request(request) if response.code != "200" raise Slackr::ServiceError, "Slack.com - #{response.code} - #{response.body}" end end
Private Instance Methods
encode_message(text, options)
click to toggle source
# File lib/slackr/webhooks/incoming.rb, line 34 def encode_message(text, options) #TODO: extract OptionValidator #TODO: add guard against invalid options #TODO: add guard against nil text connection.options.merge(options).merge({"text" => text}).to_json.to_s end
service_url()
click to toggle source
# File lib/slackr/webhooks/incoming.rb, line 30 def service_url "#{connection.base_url}/services/hooks/incoming-webhook?token=#{connection.token}" end