Class: SlackbotNotifier

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(room = 'general') ⇒ SlackbotNotifier

Returns a new instance of SlackbotNotifier.



4
5
6
# File 'lib/slackbot_notifier.rb', line 4

def initialize(room = 'general')
  @room = SlackbotNotifier.production ? room : SlackbotNotifier.development_room
end

Class Attribute Details

.slackbot_urlObject

Returns the value of attribute slackbot_url.



28
29
30
# File 'lib/slackbot_notifier.rb', line 28

def slackbot_url
  @slackbot_url
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



2
3
4
# File 'lib/slackbot_notifier.rb', line 2

def message
  @message
end

#roomObject (readonly)

Returns the value of attribute room.



2
3
4
# File 'lib/slackbot_notifier.rb', line 2

def room
  @room
end

Instance Method Details

#httpObject



17
18
19
# File 'lib/slackbot_notifier.rb', line 17

def http
  @http ||= Net::HTTP.new(uri.host, uri.port).tap { |h| h.use_ssl = uri.scheme == 'https' }
end

#notify(message) ⇒ Object



8
9
10
11
# File 'lib/slackbot_notifier.rb', line 8

def notify(message)
  @message = message
  http.request request
end

#requestObject



21
22
23
24
25
26
# File 'lib/slackbot_notifier.rb', line 21

def request
  @request ||= Net::HTTP::Post.new(uri.request_uri).tap do |r|
    r.body = message
    r.content_type = 'text/xml'
  end
end

#uriObject



13
14
15
# File 'lib/slackbot_notifier.rb', line 13

def uri
  @uri ||= URI "#{SlackbotNotifier.slackbot_url}&channel=%23#{room}"
end