lib/lolcommits/plugin/protonet.rb in lolcommits-protonet-0.0.2 vs lib/lolcommits/plugin/protonet.rb in lolcommits-protonet-0.0.3
- old
+ new
@@ -8,23 +8,14 @@
##
# Initialize plugin with runner, config and set all configurable options.
#
def initialize(runner: nil, config: nil)
super
- options.concat(plugin_options)
+ options.concat([:api_endpoint, :api_token])
end
##
- # Returns the name of the plugin to identify the plugin to lolcommits.
- #
- # @return [String] the plugin name
- #
- def self.name
- 'protonet'
- end
-
- ##
# Returns position(s) of when this plugin should run during the capture
# process. Posting to a Protonet box happens when a new capture is ready.
#
# @return [Array] the position(s) (:capture_ready)
#
@@ -48,38 +39,26 @@
puts "\n"
super
end
##
- # Returns true if the plugin has been configured.
- #
- # @return [Boolean] true/false indicating if plugin is configured. An API
- # token and endpoint are required.
- #
- def configured?
- !!(configuration['enabled'] &&
- configuration['api_token'] &&
- configuration['api_endpoint'])
- end
-
- ##
# Post-capture hook, runs after lolcommits captures a snapshot. Posts the
# lolcommit image with a message to the Protonet box. API Documentation
# can be found on the Protonet box under Help/"Protonet REST API"
#
# @return [RestClient::Response] response object from POST request
# @return [Nil] if any error occurs
#
def run_capture_ready
- debug "Posting image (and message) to #{configuration['api_endpoint']}"
+ debug "Posting image (and message) to #{configuration[:api_endpoint]}"
RestClient.post(
- configuration['api_endpoint'],
+ configuration[:api_endpoint],
{
files: [File.new(runner.main_image)],
message: message
},
- 'X-Protonet-Token' => configuration['api_token']
+ 'X-Protonet-Token' => configuration[:api_token]
)
rescue => e
log_error(e, "ERROR: RestClient POST FAILED #{e.class} - #{e.message}")
nil
end
@@ -122,19 +101,9 @@
'(freedom fries!)', '[vote RON PAUL]', '- these are not my glasses -', 'typical pansy',
'- ze goggles zey do nothing! -', 'almost working', 'legen- wait for it -', '-dairy!',
' - Tavonius would be proud of this - ', 'Meg FAILMAN!', '- very brofessional of you -',
'heartbleeding', 'juciy', 'supercalifragilisticexpialidocious', 'failing', 'loving'
].sample
- end
-
- ##
- # Returns all configuration options available for this plugin. An API
- # endpoint and token.
- #
- # @return [Array] the option names
- #
- def plugin_options
- %w(api_endpoint api_token)
end
end
end
end