dingbot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 79bede9af793be8857e22e79420cc69554f9a94f
4
+ data.tar.gz: c4ad83216aaea43144d00aa071dd94197a00fe12
5
+ SHA512:
6
+ metadata.gz: 1c139e7e9a8a881a5aa1f1097a6b8fa67db17665b2071104667b1817bc18fbbcc7f3bc4d836a810e5afcd561f541d5bf8b353c56bab136e1e54f67f6570ca5e5
7
+ data.tar.gz: 16d1e94afd493591d7873cd8688acdaf4094277b96b1d905db400df8255c59a6b0e061382894577f4f3c8d8a4a55d444be8c9f849b1fad6e5d32d451dae67961
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.0
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at thierry.xing@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dingbot.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Thierry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # DingTalk Bot
2
+
3
+ DingTalk Bot是阿里钉钉自定义机器人的Ruby库
4
+ 官方文档:[阿里钉钉自定义机器人](https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1).
5
+
6
+
7
+ ## 安装
8
+ 从rubygems中安装:
9
+
10
+ ```sh
11
+ gem install dingbot
12
+ ```
13
+
14
+ 添加到Gemfile中:
15
+
16
+ ```ruby
17
+ gem 'dingbot'
18
+ ```
19
+
20
+ ## 用法
21
+
22
+ 初始化客户端:
23
+
24
+ ```ruby
25
+ access_token = 'xxxxxxxxxxxxxxx'
26
+ client = DingBot.client(access_token)
27
+ ```
28
+
29
+ 发送消息
30
+ ```ruby
31
+ # 发送Text消息
32
+ message = DingBot::Message::Text.new('我就是我, 是不一样的烟火',
33
+ ['156xxxx8827'],
34
+ false)
35
+ client.send_msg(message)
36
+
37
+ # 发送Link消息
38
+ message = DingBot::Message::Link.new('我就是我, 是不一样的烟火',
39
+ '这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。',
40
+ 'https://www.dingtalk.com/',
41
+ 'https://avatars1.githubusercontent.com/u/64818')
42
+ client.send_msg(message)
43
+
44
+ # 发送Markdown消息
45
+ message = DingBot::Message::Markdown.new('我就是我, 是不一样的烟火', '### 我就是我, 是不一样的烟火')
46
+ client.send_msg(message)
47
+
48
+ # 发送整体跳转ActionCard消息
49
+ message = DingBot::Message::WholeActionCard.new('乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身',
50
+ '![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅',
51
+ '0',
52
+ '0',
53
+ '阅读全文',
54
+ 'https://www.dingtalk.com/')
55
+ client.send_msg(message)
56
+
57
+ # 发送独立跳转ActionCard类型消息
58
+ message = DingBot::Message::IndependentActionCard.new('乔布斯 20 年前想打造一间苹果咖啡厅,而它正是 Apple Store 的前身',
59
+ '![screenshot](@lADOpwk3K80C0M0FoA) ### 乔布斯 20 年前想打造的苹果咖啡厅',
60
+ '0',
61
+ '0',
62
+ [
63
+ DingBot::Message::ActionBtn.new('内容不错', 'https://www.dingtalk.com/'),
64
+ DingBot::Message::ActionBtn.new('不感兴趣', 'https://www.dingtalk.com/')
65
+ ])
66
+ client.send_msg(message)
67
+
68
+ # 发送FeedCard类型
69
+ message = DingBot::Message::FeedCard.new([
70
+ DingBot::Message::FeedCardLink.new('时代的火车向前开',
71
+ 'https://avatars1.githubusercontent.com/u/64818',
72
+ 'https://www.dingtalk.com/')
73
+ ])
74
+ client.send_msg(message)
75
+ ```
76
+ 更为详细的用法请见此链接:[https://github.com/thierryxing/dingtalk-bot/blob/master/test/dingbot_test.rb](https://github.com/thierryxing/dingtalk-bot/blob/master/test/dingbot_test.rb)
77
+
78
+ ## License
79
+ Released under the MIT license. See LICENSE.txt for details.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dingbot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dingbot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dingbot"
8
+ spec.version = DingBot::VERSION
9
+ spec.authors = ["Thierry"]
10
+ spec.email = ["thierry.xing@gmail.com"]
11
+
12
+ spec.summary = %q{钉钉自定义机器人Ruby库}
13
+ spec.description = %q{钉钉自定义机器人Ruby库}
14
+ spec.homepage = "https://github.com/thierryxing/dingtalk-bot"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency 'httparty', "~> 0.15.5"
34
+ spec.add_development_dependency "bundler", "~> 1.14"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
37
+ spec.add_development_dependency 'yard', "~> 0.9.5"
38
+ end
@@ -0,0 +1,45 @@
1
+ require "dingbot/version"
2
+ require 'dingbot/error'
3
+ require 'dingbot/client'
4
+ require 'dingbot/message/text'
5
+ require 'dingbot/message/link'
6
+ require 'dingbot/message/markdown'
7
+ require 'dingbot/message/action_card'
8
+ require 'dingbot/message/feed_card'
9
+
10
+ module DingBot
11
+
12
+ ENDPOINT = "https://oapi.dingtalk.com/robot/send"
13
+
14
+ # Alias for DingBot::Client.new
15
+ #
16
+ # @return [DingBot::Client]
17
+ def self.client(access_token='')
18
+ DingBot::Client.new(access_token)
19
+ end
20
+
21
+ # Delegate to DingBot::Client
22
+ def self.method_missing(method, *args, &block)
23
+ return super unless client.respond_to?(method)
24
+ client.send(method, *args, &block)
25
+ end
26
+
27
+ # Delegate to DingBot::Client
28
+ def respond_to_missing?(method_name, include_private = false)
29
+ client.respond_to?(method_name) || super
30
+ end
31
+
32
+ # Delegate to HTTParty.http_proxy
33
+ def self.http_proxy(address=nil, port=nil, username=nil, password=nil)
34
+ DingBot::Client.http_proxy(address, port, username, password)
35
+ end
36
+
37
+ # Returns an unsorted array of available client methods.
38
+ #
39
+ # @return [Array<Symbol>]
40
+ def self.actions
41
+ hidden = /access_token|post|validate|set_request_defaults|httparty/
42
+ (DingBot::Client.instance_methods - Object.methods).reject {|e| e[hidden]}
43
+ end
44
+
45
+ end
@@ -0,0 +1,73 @@
1
+ require 'httparty'
2
+ require 'dingbot/message/base'
3
+
4
+ module DingBot
5
+ # @private
6
+ class Client
7
+ include HTTParty
8
+
9
+ format :json
10
+ headers "Content-Type" => "application/json"
11
+
12
+ attr_accessor :access_token
13
+
14
+ def initialize(access_token='')
15
+ @access_token = access_token
16
+ end
17
+
18
+ # Parse response body.
19
+ def self.parse(body)
20
+ begin
21
+ decode(body)
22
+ rescue => e
23
+ raise Error::Parsing.new "Couldn't parse a response body"
24
+ end
25
+ end
26
+
27
+ # Decodes a JSON response into Ruby object.
28
+ def self.decode(response)
29
+ JSON.load response
30
+ rescue JSON::ParserError
31
+ raise Error::Parsing.new "The response is not a valid JSON"
32
+ end
33
+
34
+ def send_msg(message)
35
+ validate self.class.post(DingBot::ENDPOINT, {query: {access_token: @access_token}, body: message.to_json})
36
+ end
37
+
38
+ # Checks the response code for common errors.
39
+ # Returns parsed response for successful requests.
40
+ def validate(response)
41
+ error_klass = case response.code
42
+ when 400 then
43
+ Error::BadRequest
44
+ when 401 then
45
+ Error::Unauthorized
46
+ when 403 then
47
+ Error::Forbidden
48
+ when 404 then
49
+ Error::NotFound
50
+ when 405 then
51
+ Error::MethodNotAllowed
52
+ when 409 then
53
+ Error::Conflict
54
+ when 422 then
55
+ Error::Unprocessable
56
+ when 500 then
57
+ Error::InternalServerError
58
+ when 502 then
59
+ Error::BadGateway
60
+ when 503 then
61
+ Error::ServiceUnavailable
62
+ end
63
+
64
+ fail error_klass.new(response) if error_klass
65
+
66
+ parsed = response.parsed_response
67
+ parsed.client = self if parsed.respond_to?(:client=)
68
+ parsed.parse_headers!(response.headers) if parsed.respond_to?(:parse_headers!)
69
+ parsed
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,98 @@
1
+ module DingBot
2
+ module Error
3
+ # Custom error class for rescuing from all Sentry errors.
4
+ class Error < StandardError;
5
+ end
6
+
7
+ # Raised when API endpoint credentials not configured.
8
+ class MissingCredentials < Error;
9
+ end
10
+
11
+ # Raised when impossible to parse response body.
12
+ class Parsing < Error;
13
+ end
14
+
15
+ # Custom error class for rescuing from HTTP response errors.
16
+ class ResponseError < Error
17
+ def initialize(response)
18
+ @response = response
19
+ super(build_error_message)
20
+ end
21
+
22
+ # Status code returned in the http response.
23
+ #
24
+ # @return [Integer]
25
+ def response_status
26
+ @response.code
27
+ end
28
+
29
+ private
30
+
31
+ # Human friendly message.
32
+ #
33
+ # @return [String]
34
+ def build_error_message
35
+ parsed_response = @response.parsed_response
36
+ message = parsed_response.message || parsed_response.error
37
+
38
+ "Server responded with code #{@response.code}, message: " \
39
+ "#{handle_message(message)}. " \
40
+ "Request URI: #{@response.request.base_uri}#{@response.request.path}"
41
+ end
42
+
43
+ # Handle error response message in case of nested hashes
44
+ def handle_message(message)
45
+ case message
46
+ when SentryApi::ObjectifiedHash
47
+ message.to_h.sort.map do |key, val|
48
+ "'#{key}' #{(val.is_a?(Hash) ? val.sort.map {|k, v| "(#{k}: #{v.join(' ')})"} : val).join(' ')}"
49
+ end.join(', ')
50
+ when Array
51
+ message.join(' ')
52
+ else
53
+ message
54
+ end
55
+ end
56
+ end
57
+
58
+ # Raised when API endpoint returns the HTTP status code 400.
59
+ class BadRequest < ResponseError;
60
+ end
61
+
62
+ # Raised when API endpoint returns the HTTP status code 401.
63
+ class Unauthorized < ResponseError;
64
+ end
65
+
66
+ # Raised when API endpoint returns the HTTP status code 403.
67
+ class Forbidden < ResponseError;
68
+ end
69
+
70
+ # Raised when API endpoint returns the HTTP status code 404.
71
+ class NotFound < ResponseError;
72
+ end
73
+
74
+ # Raised when API endpoint returns the HTTP status code 405.
75
+ class MethodNotAllowed < ResponseError;
76
+ end
77
+
78
+ # Raised when API endpoint returns the HTTP status code 409.
79
+ class Conflict < ResponseError;
80
+ end
81
+
82
+ # Raised when API endpoint returns the HTTP status code 422.
83
+ class Unprocessable < ResponseError;
84
+ end
85
+
86
+ # Raised when API endpoint returns the HTTP status code 500.
87
+ class InternalServerError < ResponseError;
88
+ end
89
+
90
+ # Raised when API endpoint returns the HTTP status code 502.
91
+ class BadGateway < ResponseError;
92
+ end
93
+
94
+ # Raised when API endpoint returns the HTTP status code 503.
95
+ class ServiceUnavailable < ResponseError;
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,81 @@
1
+ module DingBot
2
+ module Message
3
+
4
+ # ActionCard基类
5
+ class ActionCard < Base
6
+ attr_accessor :title, :text, :btn_orientation, :hide_avatar
7
+
8
+ def initialize(title='', text='', btn_orientation='0', hide_avatar='0')
9
+ @title = title
10
+ @text = text
11
+ @btn_orientation = btn_orientation
12
+ @hide_avatar = hide_avatar
13
+ end
14
+
15
+ def msg_type
16
+ TYPE::ACTION_CARD
17
+ end
18
+
19
+ def body_params
20
+ super.merge(actionCard: {
21
+ title: @title,
22
+ text: @text,
23
+ "hideAvatar": @hide_avatar,
24
+ "btnOrientation": @btn_orientation,
25
+ })
26
+ end
27
+ end
28
+
29
+ # 整体跳转ActionCard类型
30
+ class WholeActionCard < ActionCard
31
+ attr_accessor :single_title, :single_url
32
+
33
+ def initialize(title='', text='', btn_orientation='0', hide_avatar='0', single_title='', single_url='')
34
+ super(title, text, btn_orientation, hide_avatar)
35
+ @single_title = single_title
36
+ @single_url = single_url
37
+ end
38
+
39
+ def body_params
40
+ action_card = super[:actionCard].merge({
41
+ singleTitle: @single_title,
42
+ singleURL: @single_url
43
+ })
44
+ super.merge(actionCard: action_card)
45
+ end
46
+ end
47
+
48
+ # 独立跳转ActionCard类型
49
+ class IndependentActionCard < ActionCard
50
+ attr_accessor :buttons
51
+
52
+ def initialize(title='', text='', btn_orientation='0', hide_avatar='0', buttons=[])
53
+ super(title, text, btn_orientation, hide_avatar)
54
+ @buttons = buttons
55
+ end
56
+
57
+ def body_params
58
+ action_card = super[:actionCard].merge(btns: @buttons.map {|btn| btn.format})
59
+ super.merge(actionCard: action_card)
60
+ end
61
+ end
62
+
63
+ # 跳转按钮
64
+ class ActionBtn
65
+ attr_accessor :title, :action_url
66
+
67
+ def initialize(title='', action_url='')
68
+ @title = title
69
+ @action_url = action_url
70
+ end
71
+
72
+ def format
73
+ {
74
+ title: @title,
75
+ actionURL: @action_url
76
+ }
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,33 @@
1
+ require 'json'
2
+ module DingBot
3
+ module Message
4
+
5
+ module TYPE
6
+ TEXT = 'text'
7
+ LINK = 'link'
8
+ MARKDOWN = 'markdown'
9
+ ACTION_CARD = 'actionCard'
10
+ FEED_CARD = 'feedCard'
11
+ end
12
+
13
+ # Base Message
14
+ class Base
15
+
16
+ def msg_type
17
+ # implement inside child
18
+ end
19
+
20
+ def body_params
21
+ {
22
+ msgtype: msg_type
23
+ }
24
+ end
25
+
26
+ # Set http post body as json string
27
+ def to_json
28
+ body_params.to_json
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module DingBot
2
+ module Message
3
+
4
+ # FeedCard类型
5
+ class FeedCard < Base
6
+ attr_accessor :links
7
+
8
+ def initialize(links=[])
9
+ @links = links
10
+ end
11
+
12
+ def msg_type
13
+ TYPE::FEED_CARD
14
+ end
15
+
16
+ def body_params
17
+ super.merge(feedCard: {
18
+ links: @links.map {|link| link.format}
19
+ })
20
+ end
21
+ end
22
+
23
+ # FeedCard跳转链接
24
+ class FeedCardLink
25
+ attr_accessor :title, :pic_url, :message_url
26
+
27
+ def initialize(title='', pic_url='', message_url='')
28
+ @title = title
29
+ @pic_url = pic_url
30
+ @message_url = message_url
31
+ end
32
+
33
+ def format
34
+ {
35
+ title: @title,
36
+ messageURL: @message_url,
37
+ picURL: @pic_url
38
+ }
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ module DingBot
2
+ module Message
3
+ # link类型
4
+ # {
5
+ # "msgtype": "link",
6
+ # "link": {
7
+ # "text": "这个即将发布的新版本,创始人陈航(花名“无招”)称它为“红树林”。
8
+ # 而在此之前,每当面临重大升级,产品经理们都会取一个应景的代号,这一次,为什么是“红树林”?",
9
+ # "title": "时代的火车向前开",
10
+ # "picUrl": "",
11
+ # "messageUrl": "https://mp.weixin.qq.com/s?__biz=MzA4NjMwMTA2Ng==&mid=2650316842&idx=1&sn=60da3ea2b29f1dcc43a7c8e4a7c97a16&scene=2&srcid=09189AnRJEdIiWVaKltFzNTw&from=timeline&isappinstalled=0&key=&ascene=2&uin=&devicetype=android-23&version=26031933&nettype=WIFI"
12
+ # }
13
+ # }
14
+ class Link < Base
15
+ attr_accessor :title, :text, :pic_url, :message_url
16
+
17
+ def initialize(title='', text='', message_url='', pic_url='')
18
+ @title = title
19
+ @text = text
20
+ @message_url = message_url
21
+ @pic_url = pic_url
22
+ end
23
+
24
+ def msg_type
25
+ TYPE::LINK
26
+ end
27
+
28
+ def body_params
29
+ super.merge(link: {
30
+ text: @text,
31
+ title: @title,
32
+ picUrl: @pic_url,
33
+ messageUrl: @message_url
34
+ })
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module DingBot
2
+ module Message
3
+
4
+ # markdown类型
5
+ # {
6
+ # "msgtype": "markdown",
7
+ # "markdown": {
8
+ # "title":"杭州天气",
9
+ # "text": "#### 杭州天气\n" +
10
+ # "> 9度,西北风1级,空气良89,相对温度73%\n\n" +
11
+ # "> ![screenshot](http://image.jpg)\n" +
12
+ # "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n"
13
+ # }
14
+ # }
15
+ class Markdown < Base
16
+ attr_accessor :title, :text
17
+
18
+ def initialize(title='', text='')
19
+ @title = title
20
+ @text = text
21
+ end
22
+
23
+ def msg_type
24
+ TYPE::MARKDOWN
25
+ end
26
+
27
+ def body_params
28
+ super.merge(markdown: {
29
+ text: @text,
30
+ title: @title,
31
+ })
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,45 @@
1
+ module DingBot
2
+ module Message
3
+
4
+ # text类型
5
+ # {
6
+ # "msgtype": "text",
7
+ # "text": {
8
+ # "content": "我就是我, 是不一样的烟火"
9
+ # },
10
+ # "at": {
11
+ # "atMobiles": [
12
+ # "156xxxx8827",
13
+ # "189xxxx8325"
14
+ # ],
15
+ # "isAtAll": false
16
+ # }
17
+ # }
18
+ class Text < Base
19
+ attr_accessor :content, :at_mobiles, :is_at_all
20
+
21
+ def initialize(content='', at_mobiles=[], is_at_all=false)
22
+ @content = content
23
+ @at_mobiles = at_mobiles
24
+ @is_at_all = is_at_all
25
+ end
26
+
27
+ def msg_type
28
+ TYPE::TEXT
29
+ end
30
+
31
+ def body_params
32
+ super.merge({
33
+ text: {
34
+ "content": @content
35
+ },
36
+ at: {
37
+ atMobiles: @at_mobiles,
38
+ isAtAll: @is_at_all
39
+ }
40
+ })
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module DingBot
2
+
3
+ VERSION = "0.1.0"
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dingbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thierry
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.5
83
+ description: 钉钉自定义机器人Ruby库
84
+ email:
85
+ - thierry.xing@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".idea/dingbot.iml"
92
+ - ".idea/encodings.xml"
93
+ - ".idea/misc.xml"
94
+ - ".idea/modules.xml"
95
+ - ".idea/workspace.xml"
96
+ - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - dingbot.gemspec
105
+ - lib/dingbot.rb
106
+ - lib/dingbot/client.rb
107
+ - lib/dingbot/error.rb
108
+ - lib/dingbot/message/action_card.rb
109
+ - lib/dingbot/message/base.rb
110
+ - lib/dingbot/message/feed_card.rb
111
+ - lib/dingbot/message/link.rb
112
+ - lib/dingbot/message/markdown.rb
113
+ - lib/dingbot/message/text.rb
114
+ - lib/dingbot/version.rb
115
+ homepage: https://github.com/thierryxing/dingtalk-bot
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ allowed_push_host: https://rubygems.org
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: 钉钉自定义机器人Ruby库
140
+ test_files: []