Class: Slappy::Messenger
- Inherits:
-
Object
- Object
- Slappy::Messenger
- Defined in:
- lib/slappy/messenger.rb
Defined Under Namespace
Classes: MissingChannelException
Constant Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Messenger
constructor
A new instance of Messenger.
- #message ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Messenger
Returns a new instance of Messenger.
7 8 9 10 11 12 13 |
# File 'lib/slappy/messenger.rb', line 7 def initialize( = {}) opt = .dup @destination = {} @destination = opt[:channel] opt.delete :channel @options = opt end |
Instance Method Details
#message ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/slappy/messenger.rb', line 15 def = 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 [:channel] = id response = Slack.chat_postMessage fail SlackAPI::SlackError.new, response['error'] unless response['ok'] end |