Class: Dingding::Robot
- Inherits:
-
Object
- Object
- Dingding::Robot
- Defined in:
- lib/dingding.rb
Instance Method Summary collapse
-
#initialize(token) ⇒ Robot
constructor
A new instance of Robot.
- #send(json) ⇒ Object
- #send_markdown(title, content) ⇒ Object
- #send_text(content) ⇒ Object
Constructor Details
#initialize(token) ⇒ Robot
Returns a new instance of Robot.
9 10 11 |
# File 'lib/dingding.rb', line 9 def initialize(token) @token = token end |
Instance Method Details
#send(json) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dingding.rb', line 13 def send(json) url = URI("https://oapi.dingtalk.com/robot/send?access_token=#{@token}") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(url) request['content-type'] = 'application/json' request.body = json.to_json response = http.request(request) response.read_body end |
#send_markdown(title, content) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/dingding.rb', line 34 def send_markdown(title, content) send({ msgtype: 'markdown', markdown: { title: title, text: content } }) end |
#send_text(content) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dingding.rb', line 25 def send_text(content) send({ msgtype: 'text', text: { content: content } }) end |