Sha256: 2fe373a9209a2e003a72a7edf2c1b2815a1ef1238945fabb3a1a3e8e1ba9ad39
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
require 'rest-client' require_relative "dingtalk/version" require_relative "dingtalk/messaging/base" require_relative "dingtalk/messaging/text" require_relative "dingtalk/messaging/markdown" require 'forwardable' load File.expand_path("../tasks/dingtalk.rake", __FILE__) module Capistrano class Dingtalk extend Forwardable def_delegators :env, :fetch, :run_locally attr_reader :message def initialize(env) @env = env @config = fetch(:dingtalk_info, {}) # TODO: supports more message categories klass = message_klass @message = klass.new @config end def run(action) local = self run_locally do info "begin to send action #{action} to Dingtalk" json = local.message.build_msg_json(action) local.send(:send_msg_to_ding_talk, json) end end def send_msg_to_ding_talk(json) url = @config[:url] RestClient.post(url, json, content_type: :json, accept: :json) end def message_klass category = @config[:category] || 'text' klass = Object case category when 'text' klass = ::Capistrano::Dingtalk::Messaging::Text when 'markdown' klass = ::Capistrano::Dingtalk::Messaging::Markdown end klass end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
capistrano-dingtalk-0.1.2 | lib/capistrano/dingtalk.rb |
capistrano-dingtalk-0.1.1 | lib/capistrano/dingtalk.rb |
capistrano-dingtalk-0.1.0 | lib/capistrano/dingtalk.rb |