class Lolcommits::Plugin::Flowdock

Public Instance Methods

configure_options!() click to toggle source

Prompts the user to configure plugin options. Options are enabled (true/false), a Flowdock Personal API token, and the Flowdock organization and flow names.

@return [Hash] a hash of configured plugin options

Calls superclass method
# File lib/lolcommits/plugin/flowdock.rb, line 19
def configure_options!
  options = super
  if options[:enabled]
    puts "\nCopy (or create) your Flowdock personal API token (paste it below)"
    open_url("https://flowdock.com/account/tokens")
    print "API token: "
    access_token = gets.strip
    flowdock.access_token = access_token

    organization = configure_organization
    flow         = configure_flow
    raise Interrupt unless flow && organization

    options.merge!(
      access_token: access_token,
      flow: flow,
      organization: organization
    )
  end

  options
end
run_capture_ready() click to toggle source

Post-capture hook, runs after lolcommits captures a snapshot. Posts the lolcommit image (as a file message) to the configured Flowdock flow.

@return [Hash] JSON response object (newly created message hash) @return [Nil] if an error occurs

# File lib/lolcommits/plugin/flowdock.rb, line 49
def run_capture_ready
  print "Posting to Flowdock ... "
  message = flowdock.create_message(
    organization: configuration[:organization],
    flow: configuration[:flow],
    params: {
      event: 'file',
      content: File.new(runner.lolcommit_path),
      tags: %w(lolcommits)
    }
  )
  print "done!\n"
  message
rescue Lolcommits::Flowdock::RequestFailed => e
  print "failed :( (try again with --debug)\n"
  log_error(e, "ERROR: POST to Flowdock FAILED - #{e.message}")
  nil
end

Private Instance Methods

configure_flow() click to toggle source
# File lib/lolcommits/plugin/flowdock.rb, line 82
def configure_flow
  flows = flowdock.flows
  if flows.empty?
    puts "\nNo Flowdock flows found, please check your account at flowdock.com"
    nil
  else
    puts "\nEnter your Flowdock flow name (tab to autocomplete, Ctrl+c cancels)"
    prompt_autocomplete_hash("Flow: ", flows, value: "parameterized_name")
  end
end
configure_organization() click to toggle source
# File lib/lolcommits/plugin/flowdock.rb, line 71
def configure_organization
  orgs = flowdock.organizations
  if orgs.empty?
    puts "\nNo Flowdock organizations found, please check your account at flowdock.com"
    nil
  else
    puts "\nEnter your Flowdock organization name (tab to autocomplete, Ctrl+c cancels)"
    prompt_autocomplete_hash("Organization: ", orgs, value: "parameterized_name")
  end
end
flowdock() click to toggle source
# File lib/lolcommits/plugin/flowdock.rb, line 97
def flowdock
  @flowdock ||= Lolcommits::Flowdock::Client.new(
    configuration[:access_token]
  )
end
open_url(url) click to toggle source
# File lib/lolcommits/plugin/flowdock.rb, line 93
def open_url(url)
  Lolcommits::CLI::Launcher.open_url(url)
end