Class: StandupMD::Post::Adapters::Slack

Inherits:
StandupMD::Post::Adapter show all
Defined in:
lib/standup_md/post/adapters/slack.rb

Overview

Posts standup entries to Slack using the chat.postMessage Web API.

Constant Summary collapse

DEFAULT_ENDPOINT =

Slack chat.postMessage endpoint.

Returns:

  • (String)
"https://slack.com/api/chat.postMessage"
DEFAULT_TOKEN_ENV =

Environment variable used for the Slack token by default.

Returns:

  • (String)
"STANDUP_MD_SLACK_TOKEN"

Instance Attribute Summary

Attributes inherited from StandupMD::Post::Adapter

#options

Instance Method Summary collapse

Methods inherited from StandupMD::Post::Adapter

#initialize

Constructor Details

This class inherits a constructor from StandupMD::Post::Adapter

Instance Method Details

#post(message) ⇒ StandupMD::Post::Result

Sends a message to Slack.

Parameters:

Returns:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/standup_md/post/adapters/slack.rb', line 35

def post(message)
  channel = message.channel || options[:channel]
  token = ENV[token_env]
  return failure(message, channel, "No Slack channel configured") if blank?(channel)
  return failure(message, channel, "Missing Slack token in $#{token_env}") if blank?(token)

  response = perform_request(channel, message.text, token)
  parsed = parse_response(response.body)
  return success(message, channel, response, parsed) if response.is_a?(Net::HTTPSuccess) && parsed["ok"]

  failure(message, channel, error_message(response, parsed), parsed)
rescue => e
  failure(message, channel, e.message)
end