-
Notifications
You must be signed in to change notification settings - Fork 241
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
Merged
Merged
Yammer plugin #160
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
969b9a9
Yammer initial integration
mrclmrvn e1f98a9
Added configuration setter from the plugin
mrclmrvn 5814aab
remove yammer install in init block
mrclmrvn 65ed2cc
honor stealth flag
mrclmrvn 73c7d75
set plugin name
mrclmrvn 04c31c5
add is_configured? method just like other plugins do
mrclmrvn ba40bc2
simplify abort run
mrclmrvn e685cb9
use configure_options!
mrclmrvn b14cb77
remove post install message
mrclmrvn afa10ab
rewrite get_access_token
mrclmrvn 190ee53
Merge remote-tracking branch 'upstream/master'
mrclmrvn f92c3a2
bump yammer dependency
mrclmrvn 939fd64
revert caching yammer client
mrclmrvn 5d4362c
create attachment first
mrclmrvn 7856ffd
Use attachment1 as opts for image stream
mrclmrvn 7ff6426
simpler comment
mrclmrvn 4847926
move retries in constant - assign its value to local var instead of m…
mrclmrvn 92cd20f
Merge remote-tracking branch 'upstream/master'
mrclmrvn 698e965
comply to RuboCop offenses
mrclmrvn f181e90
miss encoding requirement
mrclmrvn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- encoding : utf-8 -*- | ||
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' | ||
YAMMER_RETRY_COUNT = 2 | ||
|
||
module Lolcommits | ||
class LolYammer < Plugin | ||
def self.name | ||
'yammer' | ||
end | ||
|
||
def configured? | ||
!configuration['access_token'].nil? | ||
end | ||
|
||
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 = 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 | ||
auth_config = configure_access_token | ||
if auth_config | ||
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 = YAMMER_RETRY_COUNT | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,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 | ||
s.add_runtime_dependency('oauth') #twitter | ||
s.add_runtime_dependency('rest-client') #uploldz | ||
s.add_runtime_dependency('httmultiparty') #dot_com | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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).