Class: Lolcommits::Plugin::Yammer

Inherits:
Base
  • Object
show all
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

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.

developer.yammer.com/docs/oauth-2#server-side-flow

Returns:

  • (Hash)

    the configured plugin options



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lolcommits/plugin/yammer.rb', line 40

def configure_options!
  options = super
  if options[:enabled]
    oauth_access_token = fetch_access_token
    if oauth_access_token
      options.merge!(access_token: oauth_access_token)
    else
      puts "Aborting.. Plugin disabled since Yammer Oauth was denied"
      options[:enabled] = false
    end
  end
  options
end

#run_capture_readyBoolean

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.

Returns:

  • (Boolean)

    true/false indicating posting was successful



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: yammer_message, 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.message}"
  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.

Returns:

  • (Boolean)

    true/false



26
27
28
# File 'lib/lolcommits/plugin/yammer.rb', line 26

def valid_configuration?
  !configuration[:access_token].nil?
end