Class: Capistrano::Dingtalk
- Inherits:
-
Object
- Object
- Capistrano::Dingtalk
- 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
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(env) ⇒ Dingtalk
constructor
A new instance of Dingtalk.
- #message_klass ⇒ Object
- #run(action) ⇒ Object
- #send_msg_to_ding_talk(json) ⇒ Object
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.new @config end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/capistrano/dingtalk.rb', line 15 def @message end |
Instance Method Details
#message_klass ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/capistrano/dingtalk.rb', line 38 def 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..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 |