Class: Lolcommits::Plugin::Dotcom

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

Constant Summary collapse

BASE_URL =
'https://lolcommits.com'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(runner: nil, name: nil, config: nil) ⇒ Dotcom

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



15
16
17
18
# File 'lib/lolcommits/plugin/dotcom.rb', line 15

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

Instance Method Details

#run_capture_readyHTTParty::Response, Nil

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)

Returns:

  • (HTTParty::Response)

    response object from POST request

  • (Nil)

    if any error occurs



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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?Boolean

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

configured

Returns:

  • (Boolean)

    true/false indicating if plugin is correctly



27
28
29
30
31
# 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