Class: Dev::Slack
- Defined in:
- lib/firespring_dev_commands/slack.rb,
lib/firespring_dev_commands/slack/global.rb
Overview
The main slack class for posting/uploading messages
Defined Under Namespace
Classes: Global
Instance Attribute Summary collapse
-
#client ⇒ Object
The attribute which contains the underlying slack web client object.
Instance Method Summary collapse
-
#initialize ⇒ Slack
constructor
Create a new slack web client and make sure it has valid credentials.
-
#post(channel:, text:) ⇒ Object
Post the text to the given channel.
-
#upload_text(channel:, text:, title: 'Text File', filename: 'file.txt') ⇒ Object
Upload the text to the give channel as a text file.
Constructor Details
#initialize ⇒ Slack
Create a new slack web client and make sure it has valid credentials
10 11 12 13 |
# File 'lib/firespring_dev_commands/slack.rb', line 10 def initialize @client = ::Slack::Web::Client.new @client.auth_test end |
Instance Attribute Details
#client ⇒ Object
The attribute which contains the underlying slack web client object
7 8 9 |
# File 'lib/firespring_dev_commands/slack.rb', line 7 def client @client end |
Instance Method Details
#post(channel:, text:) ⇒ Object
Post the text to the given channel
16 17 18 |
# File 'lib/firespring_dev_commands/slack.rb', line 16 def post(channel:, text:) client.chat_postMessage(channel:, text:) end |
#upload_text(channel:, text:, title: 'Text File', filename: 'file.txt') ⇒ Object
Upload the text to the give channel as a text file
21 22 23 24 25 26 |
# File 'lib/firespring_dev_commands/slack.rb', line 21 def upload_text(channel:, text:, title: 'Text File', filename: 'file.txt') raise 'text should be a string' unless text.is_a?(String) file = Faraday::UploadIO.new(StringIO.new(text), 'text/plain') client.files_upload(channels: channel, title:, file:, filename:, filetype: 'text') end |