Class: Lolcommits::Plugin::Dotcom
- Inherits:
-
Base
- Object
- Base
- Lolcommits::Plugin::Dotcom
- Defined in:
- lib/lolcommits/plugin/dotcom.rb
Constant Summary collapse
- BASE_URL =
'https://lolcommits.com'.freeze
Instance Method Summary collapse
-
#initialize(runner: nil, name: nil, config: nil) ⇒ Dotcom
constructor
Initialize plugin with runner, config and set all configurable options.
-
#run_capture_ready ⇒ HTTParty::Response, Nil
Post-capture hook, runs after lolcommits captures a snapshot.
-
#valid_configuration? ⇒ Boolean
Returns true/false indicating if the plugin has been correctly configured.
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 .concat() end |
Instance Method Details
#run_capture_ready ⇒ HTTParty::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)
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.}") 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
27 28 29 30 31 |
# File 'lib/lolcommits/plugin/dotcom.rb', line 27 def valid_configuration? .all? do |option| configuration[option] =~ /^([a-z]|[0-9]){32}$/ end end |