Skip to content

Commit

Permalink
remove Yammer plugin (now a gem)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthutchinson committed Nov 10, 2017
1 parent d99fef1 commit 1bcd288
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 88 deletions.
1 change: 0 additions & 1 deletion lib/lolcommits.rb
Expand Up @@ -29,7 +29,6 @@
require 'lolcommits/backends/mercurial_info'

require 'lolcommits/plugin/base'
require 'lolcommits/plugin/lol_yammer'
require 'lolcommits/plugin/lol_protonet'
require 'lolcommits/plugin/lol_flowdock'

Expand Down
84 changes: 0 additions & 84 deletions lib/lolcommits/plugin/lol_yammer.rb
@@ -1,84 +0,0 @@
require 'yammer'
require 'rest_client'

# https://developer.yammer.com/oauth2-quickstart/
YAMMER_CLIENT_ID = 'bgORyeKtnjZJSMwp8oln9g'.freeze
YAMMER_CLIENT_SECRET = 'oer2WdGzh74a5QBbW3INUxblHK3yg9KvCZmiBa2r0'.freeze
YAMMER_ACCESS_TOKEN_URL = 'https://www.yammer.com/oauth2/access_token.json'.freeze
YAMMER_RETRY_COUNT = 2

module Lolcommits
module Plugin
class LolYammer < Base
def self.name
'yammer'
end

def self.runner_order
:capture_ready
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 = 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
# ask user to configure tokens if enabling
if options['enabled']
auth_config = configure_access_token
return unless auth_config
options.merge!(auth_config)
end
options
end

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
end
end
end
3 changes: 0 additions & 3 deletions lolcommits.gemspec
Expand Up @@ -66,9 +66,6 @@ POSTINSTALL
# built-in lolcommits plugin
s.add_runtime_dependency('lolcommits-loltext', '~> 0.0.4')

# plugin gems
s.add_runtime_dependency('yam', '~> 2.5.0') # yammer

# development gems
s.add_development_dependency('rdoc')
s.add_development_dependency('pry')
Expand Down

0 comments on commit 1bcd288

Please sign in to comment.