Class: Lolcommits::Plugin::Uploldz

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



14
15
16
17
# File 'lib/lolcommits/plugin/uploldz.rb', line 14

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

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint



9
10
11
# File 'lib/lolcommits/plugin/uploldz.rb', line 9

def endpoint
  @endpoint
end

Class Method Details

.nameString

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

Returns:

  • (String)

    the plugin name



24
25
26
# File 'lib/lolcommits/plugin/uploldz.rb', line 24

def self.name
  'uploldz'
end

.runner_orderArray

Returns position(s) of when this plugin should run during the capture process. Uploading happens when a new capture is ready.

Returns:

  • (Array)

    the position(s) (:capture_ready)



34
35
36
# File 'lib/lolcommits/plugin/uploldz.rb', line 34

def self.runner_order
  [:capture_ready]
end

Instance Method Details

#configured?Boolean

Returns true if the plugin has been configured.

Returns:

  • (Boolean)

    true/false indicating if plugin is configured



43
44
45
# File 'lib/lolcommits/plugin/uploldz.rb', line 43

def configured?
  !!(!configuration['enabled'].nil? && configuration['endpoint'])
end

#run_capture_readyRestClient::Response, Nil

Post-capture hook, runs after lolcommits captures a snapshot. Uploads the lolcommit image to the remote server with an optional Authorization header and the following request params.

`file` - captured lolcommit image file `message` - the commit message `repo` - repository name e.g. mroth/lolcommits `sha` - commit SHA `key` - key (string) from plugin configuration (optional) `author_name` - the commit author name `author_email` - the commit author email address

Returns:

  • (RestClient::Response)

    response object frm POST request

  • (Nil)

    if any error occurs



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/lolcommits/plugin/uploldz.rb', line 75

def run_capture_ready
  debug "Posting capture to #{configuration['endpoint']}"
  RestClient.post(
    configuration['endpoint'],
    {
      file: File.new(runner.main_image),
      message: runner.message,
      repo: runner.vcs_info.repo,
      author_name: runner.vcs_info.author_name,
      author_email: runner.vcs_info.author_email,
      sha: runner.sha,
      key: configuration['optional_key']
    },
    Authorization: authorization_header
  )
rescue => e
  log_error(e, "ERROR: RestClient POST FAILED #{e.class} - #{e.message}")
end

#valid_configuration?Boolean

Returns true/false indicating if the plugin has been correctly configured. The `endpoint` option must be set with a URL beginning with http(s)://

configured

Returns:

  • (Boolean)

    true/false indicating if plugin is correctly



55
56
57
# File 'lib/lolcommits/plugin/uploldz.rb', line 55

def valid_configuration?
  !!(configuration['endpoint'] =~ /^http(s)?:\/\//)
end