Class: Lolcommits::Plugin::Yammer
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Yammer
- Defined in:
- lib/lolcommits/plugin/yammer.rb
Constant Summary collapse
- MESSAGES_API_URL =
"https://www.yammer.com/api/v1/messages".freeze
- ACCESS_TOKEN_URL =
'https://www.yammer.com/oauth2/access_token.json'.freeze
- OAUTH_CLIENT_ID =
'abbxXRgeSagk9GtiWW9rFw'.freeze
- OAUTH_CLIENT_SECRET =
'gHVw5Ekyy2mWOWsBzrZPs5EPnR6s04RibApcbuy10'.freeze
- OAUTH_REDIRECT_PORT =
5429
- OAUTH_REDIRECT_URL =
"http://localhost:#{OAUTH_REDIRECT_PORT}".freeze
Instance Method Summary collapse
-
#configure_options! ⇒ Hash
Prompts the user to configure the plugin.
-
#run_capture_ready ⇒ Boolean
Post-capture hook, runs after lolcommits captures a snapshot.
-
#valid_configuration? ⇒ Boolean
Returns true if the plugin has been configured correctly.
Instance Method Details
#configure_options! ⇒ Hash
Prompts the user to configure the plugin.
If the enabled option is set we attempt to fetch an Oauth token via Yammers’ Oauth 2 Server Side flow.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lolcommits/plugin/yammer.rb', line 40 def = super if [:enabled] oauth_access_token = fetch_access_token if oauth_access_token .merge!(access_token: oauth_access_token) else puts "Aborting.. Plugin disabled since Yammer Oauth was denied" [:enabled] = false end end end |
#run_capture_ready ⇒ Boolean
Post-capture hook, runs after lolcommits captures a snapshot. Posts the lolcommit file to Yammer with a commit message postfixed by a #lolcommits topic/hashtag.
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/yammer.rb', line 61 def run_capture_ready print "Posting to Yammer ... " response = RestClient.post( "https://www.yammer.com/api/v1/messages", { body: , attachment1: File.new(runner.lolcommit_path) }, { 'Authorization' => "Bearer #{configuration[:access_token]}" } ) if response.code != 201 debug response.body.inspect raise "Invalid response code (#{response.code})" end print "done!\n" true rescue StandardError => e print "failed :(\n" puts "Yammer error: #{e.}" puts "Try a lolcommits capture with `--debug` and check for errors: `lolcommits -c --debug`" false end |
#valid_configuration? ⇒ Boolean
Returns true if the plugin has been configured correctly. The access_token must be set.
26 27 28 |
# File 'lib/lolcommits/plugin/yammer.rb', line 26 def valid_configuration? !configuration[:access_token].nil? end |