Class: Lolcommits::Plugin::LolYammer
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::LolYammer
show all
- Defined in:
- lib/lolcommits/plugin/lol_yammer.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #options, #runner
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#configuration, #configured_and_enabled?, #debug, #enabled?, #execute_capture_ready, #execute_post_capture, #execute_pre_capture, #initialize, #log_error, #parse_user_input, #print, #puts, #run_post_capture, #run_pre_capture, #valid_configuration?
Class Method Details
.name ⇒ Object
13
14
15
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 13
def self.name
'yammer'
end
|
.runner_order ⇒ Object
17
18
19
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 17
def self.runner_order
:capture_ready
end
|
Instance Method Details
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 25
def configure_access_token
print "Open the URL below and copy the `code` param from query after redirected, enter it as `access_token`:\n"
print "https://www.yammer.com/dialog/oauth?client_id=#{YAMMER_CLIENT_ID}&response_type=code\n"
print 'Enter code param from the redirected URL, then press enter: '
code = gets.to_s.strip
url = YAMMER_ACCESS_TOKEN_URL
debug "access_token url: #{url}"
params = {
'client_id' => YAMMER_CLIENT_ID,
'client_secret' => YAMMER_CLIENT_SECRET,
'code' => code
}
debug "params : #{params.inspect}"
result = JSON.parse(RestClient.post(url, params))
debug "response : #{result.inspect}"
{ 'access_token' => result['access_token']['token'] }
end
|
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 45
def configure_options!
options = super
if options['enabled']
auth_config = configure_access_token
return unless auth_config
options.merge!(auth_config)
end
options
end
|
21
22
23
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 21
def configured?
!configuration['access_token'].nil?
end
|
#run_capture_ready ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/lolcommits/plugin/lol_yammer.rb', line 56
def run_capture_ready
commit_msg = runner.message
post = "#{commit_msg} #lolcommits"
puts "Yammer post: #{post}" unless runner.capture_stealth
Yammer.configure do |c|
c.client_id = YAMMER_CLIENT_ID
c.client_secret = YAMMER_CLIENT_SECRET
end
client = Yammer::Client.new(access_token: configuration['access_token'])
retries = YAMMER_RETRY_COUNT
begin
lolimage = File.new(runner.main_image)
response = client.create_message(post, attachment1: lolimage)
debug response.body.inspect
puts "\t--> Status posted!" if response
rescue StandardError => e
retries -= 1
retry if retries > 0
puts "Status not posted - #{e.message}"
puts 'Try running config again:'
puts "\tlolcommits --config --plugin yammer"
end
end
|