class Lolcommits::Plugin::Dotcom

Constants

BASE_URL

Public Class Methods

new(runner: nil, name: nil, config: nil) click to toggle source

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

Calls superclass method
# File lib/lolcommits/plugin/dotcom.rb, line 15
def initialize(runner: nil, name: nil, config: nil)
  super
  options.concat(plugin_options)
end

Public Instance Methods

run_capture_ready() click to toggle source

Post-capture hook, runs after lolcommits captures a snapshot. Uploads the lolcommit to the dot-com server with the following multi-part POST body params (JSON encoded):

`t` - timestamp, seconds since epoch `token` - hex digest of `api_secret` from plugin config and timestamp `key` - `api_key` from plugin config `git_commit` - a hash with these params:

`sha` - the commit sha
`repo_external_id` - the `repo_id` from plugin config
`image` - the lolcommit image file (processed)

@return [HTTParty::Response] response object from POST request @return [Nil] if any error occurs

# File lib/lolcommits/plugin/dotcom.rb, line 50
def run_capture_ready
  debug "Posting capture to #{BASE_URL}"
  t = Time.now.to_i.to_s

  RestClient.post(
    "#{BASE_URL}/git_commits.json",
    {
      git_commit: {
        sha: runner.sha,
        repo_external_id: configuration[:repo_id],
        image: File.open(runner.lolcommit_path),
      },
      key: configuration[:api_key],
      t: t,
      token: Digest::SHA1.hexdigest(configuration[:api_secret] + t)
    }
  )
rescue => e
  log_error(e, "ERROR: HTTParty POST FAILED #{e.class} - #{e.message}")
  return nil
end
valid_configuration?() click to toggle source

Returns true/false indicating if the plugin has been correctly configured. All options must be set with 32 character alphanumeric keys.

@return [Boolean] true/false indicating if plugin is correctly configured

# File lib/lolcommits/plugin/dotcom.rb, line 27
def valid_configuration?
  plugin_options.all? do |option|
    configuration[option] =~ /^([a-z]|[0-9]){32}$/
  end
end

Private Instance Methods

plugin_options() click to toggle source

Returns all configuration options available for this plugin.

@return [Array] the option names

# File lib/lolcommits/plugin/dotcom.rb, line 80
def plugin_options
  [:api_key, :api_secret, :repo_id]
end