class Alerty::Plugin::Slack::SlackClient::WebApi
Slack
client for Web API
Constants
- DEFAULT_ENDPOINT
Public Instance Methods
api()
click to toggle source
# File lib/alerty/plugin/slack/slack_client.rb, line 215 def api self end
channels_create(params = {}, opts = {})
click to toggle source
Creates a channel.
NOTE: Bot user can not create a channel. Token must be issued by Normal User Account @see api.slack.com/bot-users
@see api.slack.com/methods/channels.create @see github.com/slackhq/slack-api-docs/blob/master/methods/channels.create.md @see github.com/slackhq/slack-api-docs/blob/master/methods/channels.create.json
# File lib/alerty/plugin/slack/slack_client.rb, line 251 def channels_create(params = {}, opts = {}) log.info { "out_slack: channels_create #{filter_params(params)}" } post(channels_create_endpoint, params) end
channels_create_endpoint()
click to toggle source
# File lib/alerty/plugin/slack/slack_client.rb, line 227 def channels_create_endpoint @channels_create_endpoint ||= URI.join(endpoint, "channels.create") end
endpoint()
click to toggle source
# File lib/alerty/plugin/slack/slack_client.rb, line 219 def endpoint @endpoint ||= URI.parse(DEFAULT_ENDPOINT) end
post_message(params = {}, opts = {})
click to toggle source
Sends a message to a channel.
@see api.slack.com/methods/chat.postMessage @see github.com/slackhq/slack-api-docs/blob/master/methods/chat.postMessage.md @see github.com/slackhq/slack-api-docs/blob/master/methods/chat.postMessage.json
# File lib/alerty/plugin/slack/slack_client.rb, line 236 def post_message(params = {}, opts = {}) with_channels_create(params, opts) do log.info { "out_slack: post_message #{filter_params(params)}" } post(post_message_endpoint, params) end end
post_message_endpoint()
click to toggle source
# File lib/alerty/plugin/slack/slack_client.rb, line 223 def post_message_endpoint @post_message_endpoint ||= URI.join(endpoint, "chat.postMessage") end
Private Instance Methods
encode_body(params = {})
click to toggle source
# File lib/alerty/plugin/slack/slack_client.rb, line 258 def encode_body(params = {}) body = params.dup if params['attachments'] body['attachments'] = params['attachments'].to_json end URI.encode_www_form(body) end
response_check(res, params)
click to toggle source
Calls superclass method
Alerty::Plugin::Slack::SlackClient::Base#response_check
# File lib/alerty/plugin/slack/slack_client.rb, line 266 def response_check(res, params) super res_params = JSON.parse(res.body) return if res_params['ok'] case res_params['error'] when 'channel_not_found' raise ChannelNotFoundError.new(res, params) when 'name_taken' raise NameTakenError.new(res, params) else raise Error.new(res, params) end end