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

     1  // Package block 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 larkblock
    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) *BlockService {
    24  	b := &BlockService{config: config}
    25  	b.Entity = &entity{service: b}
    26  	b.Message = &message{service: b}
    27  	return b
    28  }
    29  
    30  type BlockService struct {
    31  	config  *larkcore.Config
    32  	Entity  *entity  // 服务端 API
    33  	Message *message // 服务端 API
    34  }
    35  
    36  type entity struct {
    37  	service *BlockService
    38  }
    39  type message struct {
    40  	service *BlockService
    41  }
    42  
    43  // 创建 BlockEntity
    44  //
    45  // - 开发者可以通过该接口将部分或全部数据存放于 BlockEntity。
    46  //
    47  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/block-v2/entity/create
    48  //
    49  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/blockv2/create_entity.go
    50  func (e *entity) Create(ctx context.Context, req *CreateEntityReq, options ...larkcore.RequestOptionFunc) (*CreateEntityResp, error) {
    51  	// 发起请求
    52  	apiReq := req.apiReq
    53  	apiReq.ApiPath = "/open-apis/block/v2/entities"
    54  	apiReq.HttpMethod = http.MethodPost
    55  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    56  	apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	// 反序列响应结果
    61  	resp := &CreateEntityResp{ApiResp: apiResp}
    62  	err = apiResp.JSONUnmarshalBody(resp)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	return resp, err
    67  }
    68  
    69  // 更新BlockEntity
    70  //
    71  // - 开发者通过该接口可以更新存储在BlockEntity中的数据,并实时推送到端侧。
    72  //
    73  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/block-v2/entity/update
    74  //
    75  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/blockv2/update_entity.go
    76  func (e *entity) Update(ctx context.Context, req *UpdateEntityReq, options ...larkcore.RequestOptionFunc) (*UpdateEntityResp, error) {
    77  	// 发起请求
    78  	apiReq := req.apiReq
    79  	apiReq.ApiPath = "/open-apis/block/v2/entities/:block_id"
    80  	apiReq.HttpMethod = http.MethodPut
    81  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    82  	apiResp, err := larkcore.Request(ctx, apiReq, e.service.config, options...)
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  	// 反序列响应结果
    87  	resp := &UpdateEntityResp{ApiResp: apiResp}
    88  	err = apiResp.JSONUnmarshalBody(resp)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	return resp, err
    93  }
    94  
    95  // Block协同数据推送
    96  //
    97  // - 根据BlockID向指定用户列表推送协同数据。
    98  //
    99  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/block-v2/message/create
   100  //
   101  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/blockv2/create_message.go
   102  func (m *message) Create(ctx context.Context, req *CreateMessageReq, options ...larkcore.RequestOptionFunc) (*CreateMessageResp, error) {
   103  	// 发起请求
   104  	apiReq := req.apiReq
   105  	apiReq.ApiPath = "/open-apis/block/v2/message"
   106  	apiReq.HttpMethod = http.MethodPost
   107  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
   108  	apiResp, err := larkcore.Request(ctx, apiReq, m.service.config, options...)
   109  	if err != nil {
   110  		return nil, err
   111  	}
   112  	// 反序列响应结果
   113  	resp := &CreateMessageResp{ApiResp: apiResp}
   114  	err = apiResp.JSONUnmarshalBody(resp)
   115  	if err != nil {
   116  		return nil, err
   117  	}
   118  	return resp, err
   119  }