class Tarumi::Bot
Attributes
channel[R]
hook_name[R]
icon_emoji[R]
icon_url[R]
username[R]
Public Class Methods
new(team, token, options = {})
click to toggle source
# File lib/tarumi/bot.rb, line 16 def initialize(team, token, options = {}) self.class.base_uri("https://#{team}.slack.com") self.class.default_params(token: token) #we sent this token on each request @username = options[:username] || "webhookbot" @channel = options[:channel] || "#general" @hook_name = options[:hook_name] || "incoming-webhook" @icon_url = options[:icon_url] || "https://slack.com/img/icons/app-57.png" @icon_emoji = options[:icon_emoji] raise ArgumentError, 'You need to specify a team' if team.blank? raise ArgumentError, 'You need to specify the token, to get one go to https://yourteamname.slack.com/services/new' if token.blank? end
Public Instance Methods
ping(text, options = {})
click to toggle source
# File lib/tarumi/bot.rb, line 30 def ping(text, options = {}) payload = { text: text, channel: @channel, username: @username }.merge(icon).merge(options) body = { body: "payload=#{payload.to_json}"} response = self.class.post("/services/hooks/#{@hook_name}", body) raise ArgumentError, 'You need to specify a text' if text.blank? "#{response.body} - #{response.code}" end
Private Instance Methods
icon()
click to toggle source
# File lib/tarumi/bot.rb, line 48 def icon @icon_emoji ? { icon_emoji: @icon_emoji } : { icon_url: @icon_url } end