Class: HipchatNotification

Inherits:
Object
  • Object
show all
Defined in:
app/models/hipchat_notification.rb

Defined Under Namespace

Classes: Message

Instance Method Summary collapse

Constructor Details

#initialize(deploy) ⇒ HipchatNotification

Returns a new instance of HipchatNotification.



3
4
5
6
# File 'app/models/hipchat_notification.rb', line 3

def initialize(deploy)
  @deploy = deploy
  @stage = deploy.stage
end

Instance Method Details

#deliverObject



8
9
10
11
12
13
14
15
# File 'app/models/hipchat_notification.rb', line 8

def deliver
  return if @stage.hipchat_rooms.empty?

  @stage.hipchat_rooms.each do |room|
    try_delivery(@deploy, room)
  end

end

#try_delivery(deploy, room) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/hipchat_notification.rb', line 17

def try_delivery(deploy, room)
  if !room.accept_notify?(deploy)
    Rails.logger.debug("No need to notify #{room.name}")
    return
  end

  Rails.logger.debug("Begin to notify #{room.name}")
  message = Message.new(deploy, room.multi_message?)
  begin
    hipchat(room.token)[room.name].send message.from, message.to_s, **message.style
  rescue HipChat::UnknownRoom => e
    Rails.logger.error("Room did not existed")
  rescue HipChat::Unauthorized => e
    Rails.logger.error("Invalid token to post to room")
  rescue HipChat::UnknownResponseCode => e
    Rails.logger.error("Could not deliver hipchat message: #{e.message} to room #{room.name}")
  end
end