class Stenographer::Outputs::SlackOutput
Constants
- BASE_URI
Public Instance Methods
channels()
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 8 def channels result = get_request(endpoint: 'channels.list', params: { token: token, exclude_archived: true, exclude_members: true }) channels_data = result[:channels] channels_data.map { |channel| [channel[:name], channel[:id]] } end
send()
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 14 def send raise StandardError, 'you must pass a Change to send' if @change.blank? post_json_request(endpoint: 'chat.postMessage', params: { channel: configuration[:channel], text: "Deployed updates to *#{@change.environments.upcase}*:", attachments: [generate_attachment] }) end
Private Instance Methods
configuration()
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 26 def configuration JSON.parse(@output.configuration, symbolize_names: true) end
generate_attachment()
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 30 def generate_attachment note = @change.message @change.tracker_ids.split(',').each do |id| note += "\n<https://www.pivotaltracker.com/story/show/#{id}|##{id}>" end { 'fallback': note, 'text': note } end
get_request(endpoint: '', params: {})
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 48 def get_request(endpoint: '', params: {}) response = HTTP.get("#{BASE_URI}/#{endpoint}", params: params) JSON.parse(response.body, symbolize_names: true) end
post_json_request(endpoint: '', params: {})
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 53 def post_json_request(endpoint: '', params: {}) response = HTTP .auth("Bearer #{token}") .headers(accept: 'application/json') .post("#{BASE_URI}/#{endpoint}", json: params) JSON.parse(response.body, symbolize_names: true) end
token()
click to toggle source
# File lib/stenographer/outputs/slack_output.rb, line 43 def token credentials = @output.authentication.credentials_hash credentials[:token] end