Sha256: ea6f5b056732e295e83090dcd5dd8d4a935a65c27750526936ae3dd8cfbd31b8
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
module Slappy class Messenger class MissingChannelException < StandardError; end CHANNEL_APIS = [SlackAPI::Channel, SlackAPI::Group, SlackAPI::Direct] def initialize(options) @destination = {} @destination = options[:channel] options.delete :channel @options = options end def message options = merge_params(@options) if @destination.is_a? SlackAPI::Base id = @destination.id else instance = nil CHANNEL_APIS.each do |klass| instance = klass.find(name: @destination) || klass.find(id: @destination) break unless instance.nil? end fail MissingChannelException.new, "channel / #{@destination} is not found" if instance.nil? id = instance.id end options[:channel] = id response = Slack.chat_postMessage options fail SlackAPI::SlackError.new, response['error'] unless response['ok'] end private def config Slappy.configuration end def merge_params(options) default = config.send_params default.merge options end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
slappy-0.6.0 | lib/slappy/messenger.rb |