-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Yammer plugin #160
Yammer plugin #160
Changes from 15 commits
969b9a9
e1f98a9
5814aab
65ed2cc
73c7d75
04c31c5
ba40bc2
e685cb9
b14cb77
afa10ab
190ee53
f92c3a2
939fd64
5d4362c
7856ffd
7ff6426
4847926
92cd20f
698e965
f181e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require 'yammer' | ||
require 'rest_client' | ||
|
||
# https://developer.yammer.com/oauth2-quickstart/ | ||
YAMMER_CLIENT_ID = 'bgORyeKtnjZJSMwp8oln9g' | ||
YAMMER_CLIENT_SECRET = 'oer2WdGzh74a5QBbW3INUxblHK3yg9KvCZmiBa2r0' | ||
YAMMER_ACCESS_TOKEN_URL = "https://www.yammer.com/oauth2/access_token.json" | ||
|
||
module Lolcommits | ||
|
||
class LolYammer < Plugin | ||
|
||
def self.name | ||
'yammer' | ||
end | ||
|
||
def is_configured? | ||
!configuration['access_token'].nil? | ||
end | ||
|
||
def get_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 = STDIN.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}" | ||
# no need for 'return', last line is always the return value | ||
{'access_token' => result["access_token"]["token"]} | ||
end | ||
|
||
def configure_options! | ||
options = super | ||
if options['enabled'] == true | ||
if auth_config = get_access_token | ||
options.merge!(auth_config) | ||
else | ||
return | ||
end | ||
end | ||
options | ||
end | ||
|
||
def run | ||
return unless valid_configuration? | ||
|
||
commit_msg = self.runner.message | ||
post = "#{commit_msg} #lolcommits" | ||
puts "Yammer post: #{post}" unless self.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 = 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. retries could be assigned from a class level constant here e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, moved it to a constant. We can also do |
||
begin | ||
lolimage = File.new(self.runner.main_image) | ||
response = client.create_message(post, :attachment1 => lolimage) | ||
debug response.body.inspect | ||
if response | ||
puts "\t--> Status posted!" unless self.runner.capture_stealth | ||
end | ||
rescue => 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 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |s| | |
|
||
# plugin dependencies | ||
s.add_runtime_dependency('twitter', '~> 4.8.1') #twitter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can just say #yammer (in the comment below) |
||
s.add_runtime_dependency('yam', '~> 2.0.1') #yammer official gem | ||
s.add_runtime_dependency('oauth') #twitter | ||
s.add_runtime_dependency('rest-client') #uploldz | ||
s.add_runtime_dependency('httmultiparty') #dot_com | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these two constants (CLIENT_ID and CLIENT_SECRET) also be asked for (and stored) in the configuration? OR are these CLIENT constants merely to identify the lolcommits yammer plugin client to yammer itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthutchinson
CLIENT_ID and CLIENT_SECRET is for the registered app in Yammer Application directory, so it's merely to identify the lolcommits yammer plugin client to yammer itself.
I'll lookup transferring ownership procedure of the app, if anyone wants to take it :)
Right now, I don't there's much to configure on it, unless someone wants it published in Yammer Application directory (maybe add proper description, screenshots, etc).