class Capistrano::Dingtalk

Constants

VERSION

Attributes

message[R]

Public Class Methods

new(env) click to toggle source
# File lib/capistrano/dingtalk.rb, line 16
def initialize(env)
  @env = env
  @config = fetch(:dingtalk_info, {})
  # TODO: supports more message categories
  klass = message_klass
  @message = klass.new @config
end

Public Instance Methods

message_klass() click to toggle source
# File lib/capistrano/dingtalk.rb, line 38
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
run(action) click to toggle source
# File lib/capistrano/dingtalk.rb, line 24
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
send_msg_to_ding_talk(json) click to toggle source
# File lib/capistrano/dingtalk.rb, line 33
def send_msg_to_ding_talk(json)
  url = @config[:url]
  RestClient.post(url, json, content_type: :json, accept: :json)
end