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

     1  // Package tenant 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 larktenant
    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) *TenantService {
    24  	t := &TenantService{config: config}
    25  	t.Tenant = &tenant{service: t}
    26  	return t
    27  }
    28  
    29  type TenantService struct {
    30  	config *larkcore.Config
    31  	Tenant *tenant // 企业
    32  }
    33  
    34  type tenant struct {
    35  	service *TenantService
    36  }
    37  
    38  // 获取企业信息
    39  //
    40  // - 获取企业名称、企业编号等企业信息
    41  //
    42  // - 如果ISV应用是企业创建时默认安装,并且180天内企业未打开或使用过此应用,则无法通过此接口获取到企业信息。
    43  //
    44  // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/tenant-v2/tenant/query
    45  //
    46  // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/tenantv2/query_tenant.go
    47  func (t *tenant) Query(ctx context.Context, options ...larkcore.RequestOptionFunc) (*QueryTenantResp, error) {
    48  	// 发起请求
    49  	apiReq := &larkcore.ApiReq{
    50  		PathParams:  larkcore.PathParams{},
    51  		QueryParams: larkcore.QueryParams{},
    52  	}
    53  	apiReq.ApiPath = "/open-apis/tenant/v2/tenant/query"
    54  	apiReq.HttpMethod = http.MethodGet
    55  	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
    56  	apiResp, err := larkcore.Request(ctx, apiReq, t.service.config, options...)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  	// 反序列响应结果
    61  	resp := &QueryTenantResp{ApiResp: apiResp}
    62  	err = apiResp.JSONUnmarshalBody(resp)
    63  	if err != nil {
    64  		return nil, err
    65  	}
    66  	return resp, err
    67  }