Class: NotificationServices::GtalkService

Inherits:
NotificationService
  • Object
show all
Defined in:
app/models/notification_services/gtalk_service.rb

Constant Summary collapse

Label =
"gtalk"

Instance Method Summary collapse

Instance Method Details

#check_paramsObject


30
31
32
33
34
35
36
# File 'app/models/notification_services/gtalk_service.rb', line 30

def check_params
  if Fields.detect { |f| self[f[0]].blank? && self[f[2]].blank? } 
    errors.add :base, 
    """You must specify your Username, Password, service, service_url 
       and either rooms or users to send to or both"""
  end
end

#create_notification(problem) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/notification_services/gtalk_service.rb', line 42

def create_notification(problem)
  # build the xmpp client
  client = Jabber::Client.new(Jabber::JID.new(subdomain))
  client.connect(service)
  client.auth(api_token)

  #has to look like this to be formatted properly in the client
  message =  """#{problem.app.name.to_s}
#{Errbit::Config.protocol}://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}
#{notification_description problem}"""

  # post the issue to the xmpp room(s)
  send_to_users(client, message) unless user_id.blank?
  send_to_muc(client, message) unless room_id.blank?
ensure
  client.close unless client.nil?
end

#urlObject


38
39
40
# File 'app/models/notification_services/gtalk_service.rb', line 38

def url
  service_url || "http://www.google.com/talk/"
end