Permalink
Browse files

port yammer hook

  • Loading branch information...
1 parent 08092a8 commit 4ddbbb22b8efd32df61d9daa503e69cd331e8e1e @technoweenie technoweenie committed Jun 9, 2011
Showing with 65 additions and 25 deletions.
  1. +31 −22 services/yammer.rb
  2. +0 −3 test/friend_feed_test.rb
  3. +34 −0 test/yammer_test.rb
View
@@ -1,29 +1,38 @@
-service :yammer do |data, payload|
- statuses = [ ]
- repository = payload['repository']['name']
+class Service::Yammer < Service
+ self.hook_name = :yammer
- if data['digest'] == '1'
- commit = payload['commits'][-1]
- tiny_url = shorten_url(payload['repository']['url'] + '/commits/' + payload['ref_name'])
- statuses << "@#{commit['author']['name']} pushed #{payload['commits'].length}. #{tiny_url} \##{repository}"
- else
- payload['commits'].each do |commit|
- tiny_url = shorten_url(commit['url'])
- statuses << "#{commit['message']} (committer: @#{commit['author']['name']}) #{tiny_url} \##{repository}"
- end
- end
+ def receive_push
+ statuses = [ ]
+ repository = payload['repository']['name']
+ if data['digest'] == '1'
+ commit = payload['commits'][-1]
+ tiny_url = shorten_url(payload['repository']['url'] + '/commits/' + payload['ref_name'])
+ statuses << "@#{commit['author']['name']} pushed #{payload['commits'].length}. #{tiny_url} \##{repository}"
+ else
+ payload['commits'].each do |commit|
+ tiny_url = shorten_url(commit['url'])
+ statuses << "#{commit['message']} (committer: @#{commit['author']['name']}) #{tiny_url} \##{repository}"
+ end
+ end
- yammer = Yammer::Client.new(:consumer =>
- {:key => data['consumer_key'],
- :secret => data['consumer_secret']},
- :access =>
- {:token => data['access_token'],
- :secret => data['access_secret']})
+ statuses.each do |status|
+ params = { :body => status }
+ params['group_id'] = data['group_id'] unless data['group_id'].to_s.empty?
+ send_message params
+ end
+ end
- statuses.each do |status|
- params = { :body => status }
- params['group_id'] = data['group_id'] unless data['group_id'].to_s.empty?
+ def send_message(params)
yammer.message(:post, params)
end
+
+ def yammer
+ @yammer ||= Yammer::Client.new(:consumer =>
+ {:key => data['consumer_key'],
+ :secret => data['consumer_secret']},
+ :access =>
+ {:token => data['access_token'],
+ :secret => data['access_secret']})
+ end
end
View
@@ -21,6 +21,3 @@ def service(*args)
end
end
-
-
-
View
@@ -0,0 +1,34 @@
+require File.expand_path('../helper', __FILE__)
+
+class YammerTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ svc = service({'group_id' => 'g'}, payload)
+
+ def svc.messages
+ @messages ||= []
+ end
+
+ def svc.send_message(params)
+ messages << params
+ end
+
+ def svc.shorten_url(*args)
+ 'short'
+ end
+
+ svc.receive_push
+
+ assert_equal 3, svc.messages.size
+ assert_equal %w(g g g), svc.messages.map { |m| m['group_id'] }
+ end
+
+ def service(*args)
+ super Service::Yammer, *args
+ end
+end
+
+

0 comments on commit 4ddbbb2

Please sign in to comment.