gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/docx/v1/api.go (about)

     1  // Package docx code generated by oapi sdk gen
     2  /*
     3   * MIT License
     4   *
     5   * Copyright (c) 2022 Lark Technologies Pte. Ltd.
     6   *
     7   * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
     8   *
     9   * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
    10   *
    11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    12   */
    13  
    14  package larkdocx
    15  
    16  import (
    17  	"context"
    18  	"net/http"
    19  
    20  	"gitee.com/larksuite/oapi-sdk-go/v3/core"
    21  )
    22  
    23  func NewService(config *larkcore.Config) *DocxService {
    24  	d := &DocxService{config: config}
    25  	d.Document = &document{service: d}
    26  	d.DocumentBlock = &documentBlock{service: d}
    27  	d.DocumentBlockChildren = &documentBlockChildren{service: d}
    28  	return d
    29  }
    30  
    31  type DocxService struct {
    32  	config                *larkcore.Config
    33  	Document              *document              // 文档
    34  	DocumentBlock         *documentBlock         // 块
    35  	DocumentBlockChildren *documentBlockChildren // document.block.children
    36  }
    37  
    38  type document struct {
    39  	service *DocxService
    40  }
    41  type documentBlock struct {
    42  	service *DocxService
    43  }
    44  type documentBlockChildren struct {
    45  	service *DocxService
    46  }
    47  
    48  // 创建文档
    49  //
    50  // - 创建新版文档,文档标题和目录可选。
    51  //
    52  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnyoyCgwS8ywWwMtQr9yjZ2f),了解相关规则及约束。
    53  //
    54  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document/create
    55  //
    56  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/create_document.go
    57  func (d *document) Create(ctx context.Context, req *CreateDocumentReq, options ...larkcore.RequestOptionFunc) (*CreateDocumentResp, error) {
    58  	// 发起请求
    59  	apiReq := req.apiReq
    60  	apiReq.ApiPath = "/open-apis/docx/v1/documents"
    61  	apiReq.HttpMethod = http.MethodPost
    62  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
    63  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
    64  	if err != nil {
    65  		return nil, err
    66  	}
    67  	// 反序列响应结果
    68  	resp := &CreateDocumentResp{ApiResp: apiResp}
    69  	err = apiResp.JSONUnmarshalBody(resp)
    70  	if err != nil {
    71  		return nil, err
    72  	}
    73  	return resp, err
    74  }
    75  
    76  // 获取文档基本信息
    77  //
    78  // - 获取文档最新版本号、标题等
    79  //
    80  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnWKAE4aSaIU4GcdLInSaVde),了解相关规则及约束。
    81  //
    82  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document/get
    83  //
    84  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/get_document.go
    85  func (d *document) Get(ctx context.Context, req *GetDocumentReq, options ...larkcore.RequestOptionFunc) (*GetDocumentResp, error) {
    86  	// 发起请求
    87  	apiReq := req.apiReq
    88  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id"
    89  	apiReq.HttpMethod = http.MethodGet
    90  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
    91  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
    92  	if err != nil {
    93  		return nil, err
    94  	}
    95  	// 反序列响应结果
    96  	resp := &GetDocumentResp{ApiResp: apiResp}
    97  	err = apiResp.JSONUnmarshalBody(resp)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  	return resp, err
   102  }
   103  
   104  // 获取文档纯文本内容
   105  //
   106  // - 获取文档的纯文本内容。
   107  //
   108  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnQeqI4wiKIMis6GNvCOBuqg),了解相关规则及约束。
   109  //
   110  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document/raw_content
   111  //
   112  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/rawContent_document.go
   113  func (d *document) RawContent(ctx context.Context, req *RawContentDocumentReq, options ...larkcore.RequestOptionFunc) (*RawContentDocumentResp, error) {
   114  	// 发起请求
   115  	apiReq := req.apiReq
   116  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/raw_content"
   117  	apiReq.HttpMethod = http.MethodGet
   118  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   119  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   120  	if err != nil {
   121  		return nil, err
   122  	}
   123  	// 反序列响应结果
   124  	resp := &RawContentDocumentResp{ApiResp: apiResp}
   125  	err = apiResp.JSONUnmarshalBody(resp)
   126  	if err != nil {
   127  		return nil, err
   128  	}
   129  	return resp, err
   130  }
   131  
   132  // 批量更新块
   133  //
   134  // - 批量更新块的富文本内容。
   135  //
   136  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnMiwAKCiE6oQEkPyhvmmQEe),了解相关规则及约束。
   137  //
   138  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block/batch_update
   139  //
   140  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/batchUpdate_documentBlock.go
   141  func (d *documentBlock) BatchUpdate(ctx context.Context, req *BatchUpdateDocumentBlockReq, options ...larkcore.RequestOptionFunc) (*BatchUpdateDocumentBlockResp, error) {
   142  	// 发起请求
   143  	apiReq := req.apiReq
   144  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/batch_update"
   145  	apiReq.HttpMethod = http.MethodPatch
   146  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   147  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   148  	if err != nil {
   149  		return nil, err
   150  	}
   151  	// 反序列响应结果
   152  	resp := &BatchUpdateDocumentBlockResp{ApiResp: apiResp}
   153  	err = apiResp.JSONUnmarshalBody(resp)
   154  	if err != nil {
   155  		return nil, err
   156  	}
   157  	return resp, err
   158  }
   159  
   160  // 获取块
   161  //
   162  // - 获取指定块的富文本内容。
   163  //
   164  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnamKaccZKqIMopnREJCZUMe#doxcnWEMWYAg2YMkEq0SZXHzaih),了解相关规则及约束。
   165  //
   166  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block/get
   167  //
   168  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/get_documentBlock.go
   169  func (d *documentBlock) Get(ctx context.Context, req *GetDocumentBlockReq, options ...larkcore.RequestOptionFunc) (*GetDocumentBlockResp, error) {
   170  	// 发起请求
   171  	apiReq := req.apiReq
   172  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/:block_id"
   173  	apiReq.HttpMethod = http.MethodGet
   174  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   175  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   176  	if err != nil {
   177  		return nil, err
   178  	}
   179  	// 反序列响应结果
   180  	resp := &GetDocumentBlockResp{ApiResp: apiResp}
   181  	err = apiResp.JSONUnmarshalBody(resp)
   182  	if err != nil {
   183  		return nil, err
   184  	}
   185  	return resp, err
   186  }
   187  
   188  // 获取文档所有块
   189  //
   190  // - 获取文档所有块的富文本内容并分页返回。
   191  //
   192  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnamKaccZKqIMopnREJCZUMe#doxcn6AkCE2AUUm2WwxID7lS7Xc),了解相关规则及约束。
   193  //
   194  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block/list
   195  //
   196  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/list_documentBlock.go
   197  func (d *documentBlock) List(ctx context.Context, req *ListDocumentBlockReq, options ...larkcore.RequestOptionFunc) (*ListDocumentBlockResp, error) {
   198  	// 发起请求
   199  	apiReq := req.apiReq
   200  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks"
   201  	apiReq.HttpMethod = http.MethodGet
   202  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   203  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   204  	if err != nil {
   205  		return nil, err
   206  	}
   207  	// 反序列响应结果
   208  	resp := &ListDocumentBlockResp{ApiResp: apiResp}
   209  	err = apiResp.JSONUnmarshalBody(resp)
   210  	if err != nil {
   211  		return nil, err
   212  	}
   213  	return resp, err
   214  }
   215  func (d *documentBlock) ListByIterator(ctx context.Context, req *ListDocumentBlockReq, options ...larkcore.RequestOptionFunc) (*ListDocumentBlockIterator, error) {
   216  	return &ListDocumentBlockIterator{
   217  		ctx:      ctx,
   218  		req:      req,
   219  		listFunc: d.List,
   220  		options:  options,
   221  		limit:    req.Limit}, nil
   222  }
   223  
   224  // 更新块
   225  //
   226  // - 更新指定的块。
   227  //
   228  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnEeyS0I8MMqoieIMpK7jm8g),了解相关规则及约束。
   229  //
   230  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block/patch
   231  //
   232  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/patch_documentBlock.go
   233  func (d *documentBlock) Patch(ctx context.Context, req *PatchDocumentBlockReq, options ...larkcore.RequestOptionFunc) (*PatchDocumentBlockResp, error) {
   234  	// 发起请求
   235  	apiReq := req.apiReq
   236  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/:block_id"
   237  	apiReq.HttpMethod = http.MethodPatch
   238  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   239  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   240  	if err != nil {
   241  		return nil, err
   242  	}
   243  	// 反序列响应结果
   244  	resp := &PatchDocumentBlockResp{ApiResp: apiResp}
   245  	err = apiResp.JSONUnmarshalBody(resp)
   246  	if err != nil {
   247  		return nil, err
   248  	}
   249  	return resp, err
   250  }
   251  
   252  // 删除块
   253  //
   254  // - 指定需要操作的块,删除其指定范围的子块。如果操作成功,接口将返回应用删除操作后的文档版本号。
   255  //
   256  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcngCsscGk0WacO258mYDgM6b),了解相关规则及约束。
   257  //
   258  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block-children/batch_delete
   259  //
   260  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/batchDelete_documentBlockChildren.go
   261  func (d *documentBlockChildren) BatchDelete(ctx context.Context, req *BatchDeleteDocumentBlockChildrenReq, options ...larkcore.RequestOptionFunc) (*BatchDeleteDocumentBlockChildrenResp, error) {
   262  	// 发起请求
   263  	apiReq := req.apiReq
   264  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/:block_id/children/batch_delete"
   265  	apiReq.HttpMethod = http.MethodDelete
   266  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   267  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   268  	if err != nil {
   269  		return nil, err
   270  	}
   271  	// 反序列响应结果
   272  	resp := &BatchDeleteDocumentBlockChildrenResp{ApiResp: apiResp}
   273  	err = apiResp.JSONUnmarshalBody(resp)
   274  	if err != nil {
   275  		return nil, err
   276  	}
   277  	return resp, err
   278  }
   279  
   280  // 创建块
   281  //
   282  // - 指定需要操作的块,为其创建一批子块,并插入到指定位置。如果操作成功,接口将返回新创建子块的富文本内容。
   283  //
   284  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnm0ooUe0s20GwwVB3a05rtb),了解相关规则及约束。
   285  //
   286  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block-children/create
   287  //
   288  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/create_documentBlockChildren.go
   289  func (d *documentBlockChildren) Create(ctx context.Context, req *CreateDocumentBlockChildrenReq, options ...larkcore.RequestOptionFunc) (*CreateDocumentBlockChildrenResp, error) {
   290  	// 发起请求
   291  	apiReq := req.apiReq
   292  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/:block_id/children"
   293  	apiReq.HttpMethod = http.MethodPost
   294  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   295  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   296  	if err != nil {
   297  		return nil, err
   298  	}
   299  	// 反序列响应结果
   300  	resp := &CreateDocumentBlockChildrenResp{ApiResp: apiResp}
   301  	err = apiResp.JSONUnmarshalBody(resp)
   302  	if err != nil {
   303  		return nil, err
   304  	}
   305  	return resp, err
   306  }
   307  
   308  // 获取所有子块
   309  //
   310  // - 给定一个指定版本的文档,并指定需要操作的块,分页遍历其所有子块富文本内容 。如果不指定版本,则会默认查询最新版本。
   311  //
   312  // - 在调用此接口前,请仔细阅读[新版文档 OpenAPI 接口校验规则](https://bytedance.feishu.cn/docx/doxcnby5Y0yoACL3PdfZqrJEm6f#doxcnE2UK2yY0gEGK8nBMPtB0vd),了解相关规则及约束。
   313  //
   314  // - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/document-docx/docx-v1/document-block-children/get
   315  //
   316  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/docxv1/get_documentBlockChildren.go
   317  func (d *documentBlockChildren) Get(ctx context.Context, req *GetDocumentBlockChildrenReq, options ...larkcore.RequestOptionFunc) (*GetDocumentBlockChildrenResp, error) {
   318  	// 发起请求
   319  	apiReq := req.apiReq
   320  	apiReq.ApiPath = "/open-apis/docx/v1/documents/:document_id/blocks/:block_id/children"
   321  	apiReq.HttpMethod = http.MethodGet
   322  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
   323  	apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...)
   324  	if err != nil {
   325  		return nil, err
   326  	}
   327  	// 反序列响应结果
   328  	resp := &GetDocumentBlockChildrenResp{ApiResp: apiResp}
   329  	err = apiResp.JSONUnmarshalBody(resp)
   330  	if err != nil {
   331  		return nil, err
   332  	}
   333  	return resp, err
   334  }
   335  func (d *documentBlockChildren) GetByIterator(ctx context.Context, req *GetDocumentBlockChildrenReq, options ...larkcore.RequestOptionFunc) (*GetDocumentBlockChildrenIterator, error) {
   336  	return &GetDocumentBlockChildrenIterator{
   337  		ctx:      ctx,
   338  		req:      req,
   339  		listFunc: d.Get,
   340  		options:  options,
   341  		limit:    req.Limit}, nil
   342  }