forked from github/github-services
/
yammer.rb
57 lines (51 loc) · 1.55 KB
/
yammer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
54
55
56
class Service::Yammer < Service
string :group_id, :consumer_key, :consumer_secret,
:access_token, :access_secret
boolean :digest
white_list :group_id
def receive_push
statuses = [ ]
repository = payload['repository']['name']
if data['digest'] == '1'
commit = payload['commits'][-1]
tiny_url = shorten_url("#{payload['repository']['url']}/commits/#{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
statuses.each do |status|
params = { :body => status }
params['group_id'] = data['group_id'] unless data['group_id'].to_s.empty?
begin
send_message params
rescue
if $!.to_s =~ /authentication failed/i
raise_config_error "Invalid username or password"
else
raise
end
end
end
end
def send_message(params)
yammer.message(:post, params)
rescue RuntimeError => boom
if boom.to_s =~ /Bad Request/i
raise_config_error boom.to_s
else
raise
end
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