Class: Lolcommits::Uploldz

Inherits:
Plugin
  • Object
show all
Defined in:
lib/lolcommits/plugins/uploldz.rb

Instance Attribute Summary collapse

Attributes inherited from Plugin

#options, #runner

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plugin

#configuration, #configure_options!, #debug, #enabled?, #execute_postcapture, #execute_precapture, #log_error, #parse_user_input, #puts, #run_precapture, #valid_configuration?

Constructor Details

#initialize(runner) ⇒ Uploldz

Returns a new instance of Uploldz.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lolcommits/plugins/uploldz.rb', line 9

def initialize(runner)
  super
  options.concat(
    %w(
      endpoint
      optional_key
      optional_http_auth_username
      optional_http_auth_password
    )
  )
end

Instance Attribute Details

#endpointObject

Returns the value of attribute endpoint.



7
8
9
# File 'lib/lolcommits/plugins/uploldz.rb', line 7

def endpoint
  @endpoint
end

Class Method Details

.nameObject



57
58
59
# File 'lib/lolcommits/plugins/uploldz.rb', line 57

def self.name
  'uploldz'
end

.runner_orderObject



61
62
63
# File 'lib/lolcommits/plugins/uploldz.rb', line 61

def self.runner_order
  :postcapture
end

Instance Method Details

#authorization_headerObject



49
50
51
52
53
54
55
# File 'lib/lolcommits/plugins/uploldz.rb', line 49

def authorization_header
  user     = configuration['optional_http_auth_username']
  password = configuration['optional_http_auth_password']
  return unless user || password

  'Basic ' + Base64.encode64("#{user}:#{password}").chomp
end

#configured?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lolcommits/plugins/uploldz.rb', line 45

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

#run_postcaptureObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lolcommits/plugins/uploldz.rb', line 21

def run_postcapture
  return unless valid_configuration?

  if runner.git_info.repo.empty?
    puts 'Repo is empty, skipping upload'
  else
    debug "Posting capture to #{configuration['endpoint']}"
    RestClient.post(configuration['endpoint'],
                    {
                      :file         => File.new(runner.main_image),
                      :message      => runner.message,
                      :repo         => runner.git_info.repo,
                      :author_name  => runner.git_info.author_name,
                      :author_email => runner.git_info.author_email,
                      :sha          => runner.sha,
                      :key          => configuration['optional_key']
                    },
                    :Authorization => authorization_header
                   )
  end
rescue => e
  log_error(e, "ERROR: RestClient POST FAILED #{e.class} - #{e.message}")
end