Class: Lolcommits::Plugin::Protonet

Inherits:
Base
  • Object
show all
Defined in:
lib/lolcommits/plugin/protonet.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner: nil, config: nil) ⇒ Protonet

Initialize plugin with runner, config and set all configurable options.



11
12
13
14
# File 'lib/lolcommits/plugin/protonet.rb', line 11

def initialize(runner: nil, config: nil)
  super
  options.concat(plugin_options)
end

Class Method Details

.nameString

Returns the name of the plugin to identify the plugin to lolcommits.

Returns:

  • (String)

    the plugin name



21
22
23
# File 'lib/lolcommits/plugin/protonet.rb', line 21

def self.name
  'protonet'
end

.runner_orderArray

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.

Returns:

  • (Array)

    the position(s) (:capture_ready)



31
32
33
# File 'lib/lolcommits/plugin/protonet.rb', line 31

def self.runner_order
  [:capture_ready]
end

Instance Method Details

#configure_options!Hash

Prompts the user to configure plugin options.

Returns:

  • (Hash)

    a hash of configured plugin options



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

def configure_options!
  puts "-----------------------------------------------------------------"
  puts "              Lolcommits Protonet Plugin Config"
  puts "-----------------------------------------------------------------"
  puts "\n"
  puts "We'll need an API endpoint & token. Find API info on your box at "
  puts "Help/Protonet Rest API. Visit https://protonet.com for more info."
  puts "-----------------------------------------------------------------"
  puts "\n"
  super
end

#configured?Boolean

Returns true if the plugin has been configured.

token and endpoint are required.

Returns:

  • (Boolean)

    true/false indicating if plugin is configured. An API



58
59
60
61
62
# File 'lib/lolcommits/plugin/protonet.rb', line 58

def configured?
  !!(configuration['enabled'] &&
     configuration['api_token'] &&
     configuration['api_endpoint'])
end

#run_capture_readyRestClient::Response, Nil

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”

Returns:

  • (RestClient::Response)

    response object from POST request

  • (Nil)

    if any error occurs



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lolcommits/plugin/protonet.rb', line 72

def run_capture_ready
  debug "Posting image (and message) to #{configuration['api_endpoint']}"
  RestClient.post(
    configuration['api_endpoint'],
    {
      files: [File.new(runner.main_image)],
      message: message
    },
    'X-Protonet-Token' => configuration['api_token']
  )
rescue => e
  log_error(e, "ERROR: RestClient POST FAILED #{e.class} - #{e.message}")
  nil
end