Sha256: fd455e51a2960b6c6bd65c3b8b2cde2f7826c5db6d718d841451816b5d7ff5ab

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require 'rest_client'

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

      def self.name
        'flowdock'
      end

      def self.runner_order
        :capture_ready
      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 = 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 = gets.to_s.strip.downcase
        print "Enter the name of the organization for this Flowdock account.\n"
        organization = 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_capture_ready
        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 StandardError => 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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lolcommits-0.9.7 lib/lolcommits/plugin/lol_flowdock.rb
lolcommits-0.9.7.pre1 lib/lolcommits/plugin/lol_flowdock.rb