class SimpleSlack::Poster

Public Class Methods

new(slack, simple_slack) click to toggle source
# File lib/simple_slack/poster.rb, line 3
def initialize(slack, simple_slack)
  @slack = slack
  @simple_slack = simple_slack
end

Public Instance Methods

channel(to: , text: , name: "slacker", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 15
def channel(to: , text: , name: "slacker", **options)
  id = convert_channel_to_id(to.to_s)
  send_chat({ username: name, channel: id, text: text }.merge(options))
end
channels(to: , text: , name: "slacker", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 8
def channels(to: , text: , name: "slacker", **options)
  to.all? do |t|
    id = convert_channel_to_id(t.to_s)
    send_chat({ username: name, channel: id, text: text }.merge(options))
  end
end
chat(channel: nil, user: nil, text: , name: "slacker", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 24
def chat(channel: nil, user: nil, text: , name: "slacker", **options)
  if channel
    self.channel({ to: channel, text: text, name: name }.merge(options))
  elsif user
    "yet"
  end
end
im(to: , text: , name: "slacker", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 39
def im(to: , text: , name: "slacker", **options)
  id = convert_im_to_id(to.to_s)
  send_chat({ username: name, channel: id, text: text }.merge(options))
end
ims(to: , text: , name: "slacker", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 32
def ims(to: , text: , name: "slacker", **options)
  to.all? do |t|
    id = convert_im_to_id(t.to_s)
    send_chat({ username: name, channel: id, text: text }.merge(options))
  end
end
user(to: , text: , name: "slacker") click to toggle source
# File lib/simple_slack/poster.rb, line 20
def user(to: , text: , name: "slacker")
  "yet"
end

Private Instance Methods

convert_channel_to_id(key) click to toggle source
# File lib/simple_slack/poster.rb, line 51
def convert_channel_to_id(key)
  channel = @simple_slack.get.channel(key)
  if channel
    channel[:id]
  else
    raise "チャンネルが見つかりませんでした。"
  end
end
convert_im_to_id(key) click to toggle source
# File lib/simple_slack/poster.rb, line 60
def convert_im_to_id(key)
  im = @simple_slack.get.im(key)
  if im
    im[:id]
  else
    raise "IMが見つかりませんでした。"
  end
end
send_chat(username: , channel: , text: , icon_emoji: ":ghost:", **options) click to toggle source
# File lib/simple_slack/poster.rb, line 46
def send_chat(username: , channel: , text: , icon_emoji: ":ghost:", **options)
  result = @slack.chat_postMessage({ username: username, channel: channel, text: text, icon_emoji: icon_emoji }.merge(options))
  result["ok"]
end