Class: Janky::ChatService::Slack
- Inherits:
-
Object
- Object
- Janky::ChatService::Slack
- Defined in:
- lib/janky/chat_service/slack.rb
Instance Method Summary collapse
-
#initialize(settings) ⇒ Slack
constructor
A new instance of Slack.
- #rooms ⇒ Object
- #speak(message, room_id, options = {}) ⇒ Object
Constructor Details
#initialize(settings) ⇒ Slack
Returns a new instance of Slack.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/janky/chat_service/slack.rb', line 6 def initialize(settings) team = settings["JANKY_CHAT_SLACK_TEAM"] if team.nil? || team.empty? raise Error, "JANKY_CHAT_SLACK_TEAM setting is required" end token = settings["JANKY_CHAT_SLACK_TOKEN"] if token.nil? || token.empty? raise Error, "JANKY_CHAT_SLACK_TOKEN setting is required" end username = settings["JANKY_CHAT_SLACK_USERNAME"] || 'CI' icon_url = settings["JANKY_CHAT_SLACK_ICON_URL"] @client = ::Slack::Client.new(team: team, token: token, username: username, icon_url: icon_url) end |
Instance Method Details
#rooms ⇒ Object
35 36 37 38 39 |
# File 'lib/janky/chat_service/slack.rb', line 35 def rooms @rooms ||= @client.channels.map do |channel| Room.new(channel['id'], channel['name']) end end |
#speak(message, room_id, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/janky/chat_service/slack.rb', line 25 def speak(, room_id, = {}) room_name = ChatService.room_name(room_id) || room_id if [:build].present? @client.(nil, room_name, {attachments: (, [:build])}) else @client.(, room_name, ) end end |