using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
namespace SKIT.FlurlHttpClient.Wechat.Work
{
public static class WechatWorkClientExecuteCgibinDepartmentExtensions
{
///
/// 异步调用 [POST] /cgi-bin/department/create 接口。
/// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/90205
/// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/90341
/// REF: https://open.work.weixin.qq.com/api/doc/90002/90151/90824
///
///
///
///
///
public static async Task ExecuteCgibinDepartmentCreateAsync(this WechatWorkClient client, Models.CgibinDepartmentCreateRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "department", "create")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken);
}
///
/// 异步调用 [POST] /cgi-bin/department/update 接口。
/// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/90206
/// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/90342
/// REF: https://open.work.weixin.qq.com/api/doc/90002/90151/90825
///
///
///
///
///
public static async Task ExecuteCgibinDepartmentUpdateAsync(this WechatWorkClient client, Models.CgibinDepartmentUpdateRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "department", "update")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken);
}
///
/// 异步调用 [GET] /cgi-bin/department/delete 接口。
/// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/90206
/// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/90343
/// REF: https://open.work.weixin.qq.com/api/doc/90002/90151/90826
///
///
///
///
///
public static async Task ExecuteCgibinDepartmentDeleteAsync(this WechatWorkClient client, Models.CgibinDepartmentDeleteRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Get, "cgi-bin", "department", "delete")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("id", request.DepartmentId);
return await client.SendRequestWithJsonAsync(flurlReq, cancellationToken: cancellationToken);
}
///
/// 异步调用 [GET] /cgi-bin/department/list 接口。
/// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/90208
/// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/90344
/// REF: https://open.work.weixin.qq.com/api/doc/90002/90151/90827
///
///
///
///
///
public static async Task ExecuteCgibinDepartmentListAsync(this WechatWorkClient client, Models.CgibinDepartmentListRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Get, "cgi-bin", "department", "list")
.SetQueryParam("access_token", request.AccessToken);
if (request.ParentDepartmentId.HasValue)
flurlReq.SetQueryParam("id", request.ParentDepartmentId.Value);
return await client.SendRequestWithJsonAsync(flurlReq, cancellationToken: cancellationToken);
}
}
}