Commit 457a1329 by Francis Zhou

增加工作通知消息发送接口

parent 1cb52522
......@@ -4,7 +4,10 @@ require 'openssl'
require "dingtalk/version"
require "dingtalk/auth"
require "dingtalk/user"
require "dingtalk/department"
require "dingtalk/access_token"
require "dingtalk/corp_conversation"
module Dingtalk
class Error < StandardError
......@@ -26,7 +29,10 @@ module Dingtalk
class Request
include Auth
include User
include Department
include AccessToken
include CorpConversation
attr_reader :app_key, :app_secret
......
......@@ -30,7 +30,7 @@ module Dingtalk
# 钉钉内免登录第三方网站 个人信息获取
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/etaarr
add_request :get_3rd_login_free_user_profile, :post, Dingtalk::RequestUrl::GET_USER_INFO_SNS do |request|
request.is_json = true
request.format = :json
request.add_arg :accessKey, required: true, in: :query
request.add_arg :timestamp, required: true, in: :query
......
......@@ -11,7 +11,7 @@ module Dingtalk
attr_reader :query_args, :body_args, :query_const, :body_const, :required_args
def initialize
@is_json = false
@format = nil
@body_args = []
@query_args = []
......@@ -22,7 +22,15 @@ module Dingtalk
end
def is_json?
@is_json
@format == :json
end
def is_x_form?
@format == :x_form
end
def is_form_data?
@format == :form_data
end
def is_arg_required?(arg_name)
......@@ -45,8 +53,8 @@ module Dingtalk
!@query_const.empty?
end
def is_json=(b)
@is_json = b
def format=(format)
@format = format
end
def add_arg(arg_name, option)
......@@ -105,7 +113,9 @@ module Dingtalk
end
end
if builder.is_json?
if builder.is_form_data?
h[:multipart] = true
elsif builder.is_json?
h[:body] = h[:body].to_json if Hash === h[:body]
h[:headers] = {:"Content-Type" => "application/json"}
end
......
require 'dingtalk/core'
require 'dingtalk/request_url'
module Dingtalk
module CorpConversation
extend Dingtalk::Core
# 发送工作通知消息
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy
add_request :send_corp_conversation, :post, SEND_CORP_CONVERSATION do |request|
request.add_arg :agent_id, in: :body, required: true
request.add_arg :userid_list, in: :body
request.add_arg :dept_id_list, in: :body
request.add_arg :to_all_user, in: :body
request.add_arg :msg, in: :body
request.add_arg :access_token, in: :query, required: true
end
# 查询工作通知消息的发送进度
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/e2262dad
add_request :get_corp_conversation_progress, :post, CORP_CONVERSATION_SEND_PROGRESS do |request|
request.add_arg :agent_id, in: :body, required: true
request.add_arg :task_id, in: :body, required: true
request.add_arg :access_token, in: :query, required: true
end
# 查询工作通知消息的发送结果
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/a5920210
add_request :get_corp_conversation_result, :post, CORP_CONVERSATION_SEND_RESULT do |request|
request.add_arg :agent_id, in: :body, required: true
request.add_arg :task_id, in: :body, required: true
request.add_arg :access_token, in: :query, required: true
end
# 工作通知消息撤回
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/hYyV8
add_request :recall_corp_conversation, :post, RECALL_CORP_CONVERSATION do |request|
request.add_arg :agent_id, in: :body, required: true
request.add_arg :msg_task_id, in: :body, required: true
request.add_arg :access_token, in: :query, required: true
end
end
end
\ No newline at end of file
require "dingtalk/core"
require "dingtalk/request_url"
module Dingtalk
module Department
extend Dingtalk::Core
# 获取部门列表
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/dubakq/e6e1604e
add_request :get_department_list, :get, RequestUrl::GET_DEPARTMENT_LIST do |request|
request.add_arg :id, in: :query # 父部门id(如果不传,默认部门为根部门,根部门ID为1)
request.add_arg :fetch_child, in: :query # 是否递归部门的全部子部门
request.add_arg :access_token, required: true, in: :query
end
# 获取部门详情
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/dubakq/5bf960de
add_request :get_department_profile, :get, RequestUrl::GET_DEPARTMENT_PROFILE do |request|
request.add_arg :id, in: :query, required: true
request.add_arg :access_token, in: :query, required: true
end
end
end
\ No newline at end of file
......@@ -28,5 +28,33 @@ module Dingtalk
# 根据手机号获取 userId
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/ege851/soV11
GET_USERID_FROM_MOBILE = "https://oapi.dingtalk.com/user/get_by_mobile"
# 获取部门列表
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/dubakq/e6e1604e
GET_DEPARTMENT_LIST = "https://oapi.dingtalk.com/department/list"
# 获取部门详情
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/dubakq/5bf960de
GET_DEPARTMENT_PROFILE = "https://oapi.dingtalk.com/department/get"
# 发送工作通知消息
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy
SEND_CORP_CONVERSATION = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2"
# 查询工作通知消息的发送进度
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/e2262dad
CORP_CONVERSATION_SEND_PROGRESS = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendprogress"
# 查询工作通知消息的发送结果
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/a5920210
CORP_CONVERSATION_SEND_RESULT = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult"
# 工作通知消息撤回
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/pgoxpy/hYyV8
RECALL_CORP_CONVERSATION = "https://oapi.dingtalk.com/topapi/message/corpconversation/recall"
# 上传媒体文件
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/bcmg0i/08d5a73b
UPLOAD_MEDIA_FILE = "https://oapi.dingtalk.com/media/upload"
end
end
\ No newline at end of file
require 'dingtalk/core'
require 'dingtalk/request_url'
module Dingtalk
module Storage
extend Dingtalk::Core
# 上传媒体文件
# @url https://ding-doc.dingtalk.com/doc#/serverapi2/bcmg0i/08d5a73b
add_request :upload_media, :post, Dingtalk::RequestUrl::UPLOAD_MEDIA_FILE do |request|
request.add_arg :type, in: query, required: true
request.add_arg :access_token, in: :query, required: true
request.add_arg :media, in: :body, required: true
end
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment