Class: DistributionWrappers::HipChatWrapper

Inherits:
Base
  • Object
show all
Defined in:
lib/distribution_wrappers/hipchat/hipchat.rb

Instance Attribute Summary

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from DistributionWrappers::Base

Instance Method Details

#get_contactsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/distribution_wrappers/hipchat/hipchat.rb', line 16

def get_contacts
  client = get_access(@auth[:key])
  rooms = client.rooms

  users = client.users
  
  return nil if (rooms.nil? || rooms.length == 0) && (users.nil? || users.length == 0)
  
  csv_sting = ""
  
  # Loop through the channels just grabbing the names of them (that's all we need for the user)
  rooms.each_with_index do |room, index|          
    csv_sting += CSV.generate_line [room.name, room.name, '{"url": null}', 'channel', @params[:channel_id]]

    if index % 100 == 0
      @params[:temp_file].write(csv_sting)
      csv_sting = ""
    end
  end
  
  @params[:temp_file].write(csv_sting)
  
  csv_sting = ""
  
  users.each_with_index do |user, index| 
    icon_url = user.photo_url ? user.photo_url : "null"
    csv_sting += CSV.generate_line [user.name, user.user_id, "{\"url\": \"#{icon_url}\"}", 'user', @params[:channel_id]]

    if index % 100 == 0
      @params[:temp_file].write(csv_sting)
      csv_sting = ""
    end
  end
  
  @params[:temp_file].write(csv_sting)
  
  return true
end

#send_message(recipient) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/distribution_wrappers/hipchat/hipchat.rb', line 4

def send_message(recipient)
  super
  client = get_access(@auth[:key])
  
  case recipient['contact_type']
  when 'channel'
    client[recipient['identifier']].send('backstitch', @message, :color => "purple", :message_format => "html")
  when 'user'
    client.user(recipient['identifier']).send(@message, :color => "purple", :message_format => "html")
  end
end