lib/lolcommits/plugin/yammer.rb in lolcommits-yammer-0.0.4 vs lib/lolcommits/plugin/yammer.rb in lolcommits-yammer-0.0.5

- old
+ new

@@ -14,36 +14,27 @@ OAUTH_CLIENT_SECRET = 'gHVw5Ekyy2mWOWsBzrZPs5EPnR6s04RibApcbuy10'.freeze OAUTH_REDIRECT_PORT = 5429 OAUTH_REDIRECT_URL = "http://localhost:#{OAUTH_REDIRECT_PORT}".freeze ## - # Returns the name of the plugin. - # - # @return [String] the plugin name - # - def self.name - 'yammer' - end - - ## # Returns position(s) of when this plugin should run during the capture # process. Posting to Yammer happens when a new capture is ready. # # @return [Array] the position(s) (:capture_ready) # def self.runner_order [:capture_ready] end ## - # Returns true if the plugin has been configured. - # - # @return [Boolean] true/false indicating if plugin has been configured. + # Returns true if the plugin has been configured correctly. # The access_token must be set. # - def configured? - !configuration['access_token'].nil? + # @return [Boolean] true/false + # + def valid_configuration? + !configuration[:access_token].nil? end ## # Prompts the user to configure the plugin. # @@ -54,17 +45,17 @@ # # @return [Hash] the configured plugin options # def configure_options! options = super - if options['enabled'] + if options[:enabled] oauth_access_token = fetch_access_token if oauth_access_token - options.merge!('access_token' => oauth_access_token) + options.merge!(access_token: oauth_access_token) else puts "Aborting.. Plugin disabled since Yammer Oauth was denied" - options['enabled'] = false + options[:enabled] = false end end options end @@ -78,10 +69,10 @@ 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.main_image) }, - { 'Authorization' => "Bearer #{configuration["access_token"]}" } + { 'Authorization' => "Bearer #{configuration[:access_token]}" } ) if response.code != 201 debug response.body.inspect raise "Invalid response code (#{response.code})"