Sha256: 4abfabf5ee5f0b403a2d2442515dae6cd17a39beb880e0e73dd542207eb7106c

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

module Fastlane
  module Actions
    class TypetalkAction
      def self.run(params)
        options = {
            message: nil,
            success: true,
            topicId: nil,
            typetalk_token: nil,
        }.merge(params.first || {})

        [:message, :topicId, :typetalk_token].each { |key|
          raise "No #{key} given.".red unless options[key]
        }

        emoticon = (options[:success] ? ':smile:' : ':rage:')
        message = "#{emoticon} #{options[:message].to_s}"
        topicId = options[:topicId]
        typetalk_token = options[:typetalk_token]

        self.post_to_typetalk(message, topicId, typetalk_token)

        Helper.log.info 'Successfully sent Typetalk notification'.green
      end

      def self.post_to_typetalk(message, topicId, typetalk_token)
        require 'net/http'
        require 'uri'

        uri = URI.parse("https://typetalk.in/api/v1/topics/#{topicId}")
        response = Net::HTTP.post_form(uri, {'message' => message,
                                             'typetalk_token' => typetalk_token})

        self.check_response(response)
      end

      def self.check_response(response)
        case response.code.to_i
          when 200, 204
            true
          else
            raise "Could not sent Typetalk notification".red
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fastlane-0.1.18 lib/fastlane/actions/typetalk.rb
fastlane-0.1.17 lib/fastlane/actions/typetalk.rb
fastlane-0.1.16 lib/fastlane/actions/typetalk.rb
fastlane-0.1.15 lib/fastlane/actions/typetalk.rb
fastlane-0.1.14 lib/fastlane/actions/typetalk.rb