Sha256: 827e68b19a3d477c90942aaf1dd51aeb3b04319a78f7470facff97e28152c29f

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

# -*- encoding : utf-8 -*-
require 'rest_client'

module Lolcommits
  class LolFlowdock < Plugin
    ENDPOINT_URL = 'api.flowdock.com/flows/'.freeze
    RETRY_COUNT  = 2

    def self.name
      'flowdock'
    end

    def self.runner_order
      :postcapture
    end

    def configured?
      !configuration['access_token'].nil?
    end

    def configure
      print "Open the URL below and issue a token for your user (Personal API token):\n"
      print "https://flowdock.com/account/tokens\n"
      print "Enter the generated token below, then press enter: \n"
      code = STDIN.gets.to_s.strip
      print "Enter the machine name of the flow you want to post to from this repo.\n"
      print "Go to https://www.flowdock.com/account and click Flows, then click the flow, then get the machine name from the URL:\n"
      flow = STDIN.gets.to_s.strip.downcase
      print "Enter the name of the organization for this Flowdock account.\n"
      organization = STDIN.gets.to_s.strip.downcase

      {
        'access_token' => code,
        'flow' => flow,
        'organization' => organization
      }
    end

    def configure_options!
      options = super
      if options['enabled']
        config = configure
        options.merge!(config)
      end
      options
    end

    def run_postcapture
      return unless valid_configuration?

      retries = RETRY_COUNT
      begin

        endpoint = 'https://' + configuration['access_token'] + '@' + ENDPOINT_URL + configuration['organization'] + '/' + configuration['flow'] + '/messages'
        response = RestClient.post(
          endpoint,
          event: 'file',
          content: File.new(runner.main_image)
        )
        debug response
      rescue => e
        retries -= 1
        retry if retries > 0
        puts "Posting to flowdock failed - #{e.message}"
        puts 'Try running config again:'
        puts "\tlolcommits --config --plugin flowdock"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lolcommits-0.9.2 lib/lolcommits/plugins/lol_flowdock.rb
lolcommits-0.9.2.pre1 lib/lolcommits/plugins/lol_flowdock.rb
lolcommits-0.9.1 lib/lolcommits/plugins/lol_flowdock.rb
lolcommits-0.9.1.pre1 lib/lolcommits/plugins/lol_flowdock.rb
lolcommits-0.9.0 lib/lolcommits/plugins/lol_flowdock.rb