Class: Capistrano::Dingtalk

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/capistrano/dingtalk.rb,
lib/capistrano/dingtalk/version.rb

Defined Under Namespace

Modules: Messaging

Constant Summary collapse

VERSION =
"0.1.2".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Dingtalk

Returns a new instance of Dingtalk.



16
17
18
19
20
21
22
# 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

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



15
16
17
# File 'lib/capistrano/dingtalk.rb', line 15

def message
  @message
end

Instance Method Details

#message_klassObject



38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



24
25
26
27
28
29
30
31
# 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) ⇒ Object



33
34
35
36
# 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