Class: Slackbot

Inherits:
Object
  • Object
show all
Defined in:
lib/slackbot.rb

Constant Summary collapse

REMOTE_ENDPOINT =
"https://%s.slack.com"
REMOTE_PATH =
"/services/hooks/slackbot?token=%s&channel=%s"

Instance Method Summary collapse

Constructor Details

#initialize(subdomain, token) ⇒ Slackbot

Returns a new instance of Slackbot.



10
11
12
13
# File 'lib/slackbot.rb', line 10

def initialize(subdomain, token)
  @endpoint = URI(REMOTE_ENDPOINT % URI.encode(subdomain))
  @token = token
end

Instance Method Details

#send(channel, message) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/slackbot.rb', line 15

def send(channel, message)
  http = Net::HTTP.new(@endpoint.host, @endpoint.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(path(channel))
  request.body = message

  http.request(request)
end