diff --git a/README.md b/README.md index ac474b51..4b51ee10 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ https://godoc.org/github.com/chyroc/lark ## Support APIs -API Count: 1016, Event Count: 148 +API Count: 1017, Event Count: 148
@@ -496,6 +496,7 @@ API Count: 1016, Event Count: 148 - DeleteCoreHRDepartment - UpdateCoreHRDepartment - GetCoreHRDepartment + - BatchGetCoreHRDepartment - GetCoreHRDepartmentList - BatchGetCoreHRLocation - CreateCoreHRLocation diff --git a/README_CN.md b/README_CN.md index 7786d305..1341bccb 100644 --- a/README_CN.md +++ b/README_CN.md @@ -38,7 +38,7 @@ https://godoc.org/github.com/chyroc/lark ## 支持的接口 -API 总数: 1016, 事件总数: 148 +API 总数: 1017, 事件总数: 148
@@ -496,6 +496,7 @@ API 总数: 1016, 事件总数: 148 - DeleteCoreHRDepartment - UpdateCoreHRDepartment - GetCoreHRDepartment + - BatchGetCoreHRDepartment - GetCoreHRDepartmentList - BatchGetCoreHRLocation - CreateCoreHRLocation diff --git a/larkext/docx.go b/larkext/docx.go index 697571f0..05c21f35 100644 --- a/larkext/docx.go +++ b/larkext/docx.go @@ -29,7 +29,7 @@ type Docx struct { typ string } -// NewDoc new Docx client +// NewDocx new Docx client func NewDocx(larkClient *lark.Lark, token string) *Docx { return newDocx(larkClient, token, "") } @@ -54,3 +54,11 @@ func (r *Docx) Move(ctx context.Context, folderToken string) (*Task, error) { func (r *Docx) Delete(ctx context.Context) (*Task, error) { return deleteFile(ctx, r.larkClient, r.token, r.typ) } + +func (r *Docx) RawContent(ctx context.Context) (string, error) { + return r.rawContent(ctx) +} + +func (r *Docx) Blocks(ctx context.Context) ([]*lark.DocxBlock, error) { + return r.blocks(ctx) +} diff --git a/larkext/docx_impl.go b/larkext/docx_impl.go index 8a1cb639..a34b5b3a 100644 --- a/larkext/docx_impl.go +++ b/larkext/docx_impl.go @@ -37,3 +37,38 @@ func (r *Docx) copy(ctx context.Context, folderToken, name string) (*Docx, error } return newDocx(r.larkClient, res.Token, res.URL), nil } + +func (r *Docx) rawContent(ctx context.Context) (string, error) { + resp, _, err := r.larkClient.Drive.GetDocxDocumentRawContent(ctx, &lark.GetDocxDocumentRawContentReq{ + DocumentID: r.token, + Lang: nil, + }) + if err != nil { + return "", err + } + return resp.Content, nil +} + +func (r *Docx) blocks(ctx context.Context) ([]*lark.DocxBlock, error) { + token := "" + size := int64(200) + blocks := []*lark.DocxBlock{} + for { + resp, _, err := r.larkClient.Drive.GetDocxBlockListOfDocument(ctx, &lark.GetDocxBlockListOfDocumentReq{ + DocumentID: r.token, + PageSize: &size, + PageToken: &token, + DocumentRevisionID: nil, + UserIDType: nil, + }) + if err != nil { + return nil, err + } + blocks = append(blocks, resp.Items...) + if !resp.HasMore { + break + } + token = resp.PageToken + } + return blocks, nil +} diff --git a/mock.go b/mock.go index a090f7a7..33a6cd12 100644 --- a/mock.go +++ b/mock.go @@ -443,6 +443,7 @@ type Mock struct { mockCoreHRDeleteCoreHRDepartment func(ctx context.Context, request *DeleteCoreHRDepartmentReq, options ...MethodOptionFunc) (*DeleteCoreHRDepartmentResp, *Response, error) mockCoreHRUpdateCoreHRDepartment func(ctx context.Context, request *UpdateCoreHRDepartmentReq, options ...MethodOptionFunc) (*UpdateCoreHRDepartmentResp, *Response, error) mockCoreHRGetCoreHRDepartment func(ctx context.Context, request *GetCoreHRDepartmentReq, options ...MethodOptionFunc) (*GetCoreHRDepartmentResp, *Response, error) + mockCoreHRBatchGetCoreHRDepartment func(ctx context.Context, request *BatchGetCoreHRDepartmentReq, options ...MethodOptionFunc) (*BatchGetCoreHRDepartmentResp, *Response, error) mockCoreHRGetCoreHRDepartmentList func(ctx context.Context, request *GetCoreHRDepartmentListReq, options ...MethodOptionFunc) (*GetCoreHRDepartmentListResp, *Response, error) mockCoreHRBatchGetCoreHRLocation func(ctx context.Context, request *BatchGetCoreHRLocationReq, options ...MethodOptionFunc) (*BatchGetCoreHRLocationResp, *Response, error) mockCoreHRCreateCoreHRLocation func(ctx context.Context, request *CreateCoreHRLocationReq, options ...MethodOptionFunc) (*CreateCoreHRLocationResp, *Response, error) diff --git a/test/CoreHR_sample_test.go b/test/CoreHR_sample_test.go index 229d3c95..2d3cab22 100644 --- a/test/CoreHR_sample_test.go +++ b/test/CoreHR_sample_test.go @@ -745,6 +745,18 @@ func Test_CoreHR_Sample_Failed(t *testing.T) { as.Equal(err.Error(), "mock-failed") }) + t.Run("", func(t *testing.T) { + + cli.Mock().MockCoreHRBatchGetCoreHRDepartment(func(ctx context.Context, request *lark.BatchGetCoreHRDepartmentReq, options ...lark.MethodOptionFunc) (*lark.BatchGetCoreHRDepartmentResp, *lark.Response, error) { + return nil, nil, fmt.Errorf("mock-failed") + }) + defer cli.Mock().UnMockCoreHRBatchGetCoreHRDepartment() + + _, _, err := moduleCli.BatchGetCoreHRDepartment(ctx, &lark.BatchGetCoreHRDepartmentReq{}) + as.NotNil(err) + as.Equal(err.Error(), "mock-failed") + }) + t.Run("", func(t *testing.T) { cli.Mock().MockCoreHRGetCoreHRDepartmentList(func(ctx context.Context, request *lark.GetCoreHRDepartmentListReq, options ...lark.MethodOptionFunc) (*lark.GetCoreHRDepartmentListResp, *lark.Response, error) { @@ -2143,6 +2155,13 @@ func Test_CoreHR_Sample_Failed(t *testing.T) { as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err)) }) + t.Run("", func(t *testing.T) { + + _, _, err := moduleCli.BatchGetCoreHRDepartment(ctx, &lark.BatchGetCoreHRDepartmentReq{}) + as.NotNil(err) + as.True(lark.GetErrorCode(err) > 0, fmt.Sprintf("need get lark err, but get %s", err)) + }) + t.Run("", func(t *testing.T) { _, _, err := moduleCli.GetCoreHRDepartmentList(ctx, &lark.GetCoreHRDepartmentListReq{}) @@ -3218,6 +3237,13 @@ func Test_CoreHR_Sample_Failed(t *testing.T) { as.Equal("fake raw request", err.Error()) }) + t.Run("", func(t *testing.T) { + + _, _, err := moduleCli.BatchGetCoreHRDepartment(ctx, &lark.BatchGetCoreHRDepartmentReq{}) + as.NotNil(err) + as.Equal("fake raw request", err.Error()) + }) + t.Run("", func(t *testing.T) { _, _, err := moduleCli.GetCoreHRDepartmentList(ctx, &lark.GetCoreHRDepartmentListReq{})