class DistributionWrappers::HipChatWrapper

Public Instance Methods

get_contacts() click to toggle source
# 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) click to toggle source
Calls superclass method DistributionWrappers::Base#send_message
# 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

Private Instance Methods

get_access(key) click to toggle source
# File lib/distribution_wrappers/hipchat/hipchat.rb, line 75
def get_access(key)
  client = HipChat::Client.new(key, :api_version => 'v2')
  client
end
prepare(identifier=nil) click to toggle source
# File lib/distribution_wrappers/hipchat/hipchat.rb, line 57
def prepare(identifier=nil)
  base_url = ""
  if ENV['ENVIRONMENT'] == "development"
    base_url = "http://localhost:3000"
  else
    base_url = "https://studio.backstit.ch"
  end
  
  params = "contact_id=#{@version_contact.id}&version_id=#{@version_contact.studio_post_version_id}&organization_id=#{@params[:organization_id]}"
  
  body_text = "<a href='#{base_url}/posts/#{@params[:post].id}?#{params}'><strong>#{@params[:post].title}</strong></a>"
  body_text += "<br><br>#{TextHelper.clean_text(@params[:post].draft_content)[0..280]}..."
  body_text += "<br><br><a href='#{base_url}/posts/#{@params[:post].id}?#{params}'><img src='#{@params[:post].screenshot_url}'/></a>"
  body_text += "<br><a href='#{base_url}/posts/#{@params[:post].id}?#{params}'><strong>Read More...</strong></a>"
  
  return body_text
end