Class: GitHooks::Notifier::JabberClient
- Inherits:
-
Object
- Object
- GitHooks::Notifier::JabberClient
- Includes:
- Jabber
- Defined in:
- lib/git_hooks/notifier/jabber_client.rb
Defined Under Namespace
Classes: Buddy
Class Method Summary collapse
Instance Method Summary collapse
- #backend ⇒ Object
- #buddies ⇒ Object
- #create_message(from_commits) ⇒ Object
- #create_recipients(recipients) ⇒ Object
- #deliver(commits, recipients) ⇒ Object
- #init_jabber_backend! ⇒ Object
-
#initialize(jabber_options) ⇒ JabberClient
constructor
A new instance of JabberClient.
- #request_authorization_of(recipient) ⇒ Object
- #roster ⇒ Object
- #send_message_to(message, recipients) ⇒ Object
Constructor Details
#initialize(jabber_options) ⇒ JabberClient
Returns a new instance of JabberClient.
25 26 27 28 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 25 def initialize() @jabber_options = init_jabber_backend! end |
Class Method Details
.deliver(options) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 44 def self.deliver() commits = .delete(:commits) recipients = .delete(:recipients) client_instance = new() client_instance.deliver(commits, recipients) end |
Instance Method Details
#backend ⇒ Object
65 66 67 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 65 def backend @backend end |
#buddies ⇒ Object
36 37 38 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 36 def buddies roster.items.map { |roster_item| Buddy.new(roster_item.last.jid, roster) } end |
#create_message(from_commits) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 69 def (from_commits) = "[#{GitHooks::Utils.hostname}] #{from_commits.size} commits have been pushed to '#{from_commits.repo_name}' on '#{from_commits.ref_name}':\n" from_commits.each do |commit| << "\t#{commit.id[0...5]}...: '#{commit.}' by #{commit..name}\n" end end |
#create_recipients(recipients) ⇒ Object
30 31 32 33 34 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 30 def create_recipients(recipients) [recipients].flatten.map do |recipient| recipient.is_a?(Buddy) ? recipient : Buddy.new(recipient, roster) end end |
#deliver(commits, recipients) ⇒ Object
52 53 54 55 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 52 def deliver(commits, recipients) (commits), recipients true end |
#init_jabber_backend! ⇒ Object
59 60 61 62 63 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 59 def init_jabber_backend! @backend = Client.new(JID.new(@jabber_options[:jid])) @backend.connect(@jabber_options[:server]) @backend.auth(@jabber_options[:password]) end |
#request_authorization_of(recipient) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 78 def (recipient) request = Jabber::Presence.new request.to = recipient.respond_to?(:jid) ? recipient.jid : recipient request.type = :subscribe backend.send request end |
#roster ⇒ Object
40 41 42 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 40 def roster @roster ||= Roster::Helper.new(backend) end |
#send_message_to(message, recipients) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/git_hooks/notifier/jabber_client.rb', line 85 def (, recipients) create_recipients(recipients).each do |recipient| subject = "Git commit notification" (recipient) unless recipient.subscribed? msg = Message::new(recipient.jid, ).set_type(:normal).set_id('1').set_subject(subject) GitHooks::Logger.debug "msg: #{msg}" backend.send msg end end |