Skip to content

Commit

Permalink
add service contact
Browse files Browse the repository at this point in the history
Change-Id: I888ea1515b9767e1beb49512e66c996f3bd2715e
  • Loading branch information
tianfengyuan committed Nov 12, 2020
1 parent fe2ba0b commit f5da8f1
Show file tree
Hide file tree
Showing 7 changed files with 2,097 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go
| Authentication | v1 | [service/authen](service/authen) | [sample/api/authen.go](sample/api/authen.go)|
| Image | v4 | [service/image](service/image)|[sample/api/image.go](sample/api/image.go)|
| Calendar | v4 | [service/calendar](service/calendar)|[sample/api/calendar.go](sample/api/calendar.go)|
| contact | v3 | [service/contact](service/contact) | [sample/api/contact.go](sample/api/contact.go) |


- Instructions for use(For`No business API SDK is generated`the processing method)
Expand Down Expand Up @@ -133,6 +134,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go
| Business service | version | path | sample |
|--------------|--------------|------|------|
| application | v1 | [service/application](service/application) | [sample/event/application.go](sample/event/application.go) |
| contact | v3 | [service/contact](service/contact) | [sample/event/contact.go](sample/event/contact.go) |

- Instructions for use
- Event monitoring service started
Expand Down
2 changes: 2 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go
| 身份验证 | v1 | [service/authen](service/authen) | [sample/api/authen.go](sample/api/authen.go)|
| 图片 | v4 | [service/image](service/image)|[sample/api/image.go](sample/api/image.go)|
| 日历 | v4 | [service/calendar](service/calendar)|[sample/api/calendar.go](sample/api/calendar.go)|
| 通讯录 | v3 | [service/contact](service/contact)|[sample/api/contact.go](sample/api/contact.go)|


- 使用说明(对于`没有生成业务API SDK`的处理方式)
Expand Down Expand Up @@ -139,6 +140,7 @@ $ go get -u github.com/larksuite/oapi-sdk-go
| 业务服务 | 版本 | 路径 | 示例 |
|--------------|--------------|------|------|
| 应用 | v1 | [service/application](service/application) | [sample/event/application.go](sample/event/application.go) |
| 通讯录 | v3 | [service/contact](service/contact) | [sample/event/contact.go](sample/event/contact.go) |

- 使用说明
- 事件监听服务启动
Expand Down
61 changes: 61 additions & 0 deletions sample/api/contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"fmt"

"github.com/larksuite/oapi-sdk-go/api/core/response"
"github.com/larksuite/oapi-sdk-go/core"
"github.com/larksuite/oapi-sdk-go/core/tools"
contact "github.com/larksuite/oapi-sdk-go/service/contact/v3"
)

var contactService = contact.NewService(conf)

func main() {
testUserServiceList()
testDepartmentServiceUpdate()
}
func testUserServiceList() {

coreCtx := core.WarpContext(context.Background())
reqCall := contactService.Users.List(coreCtx)
reqCall.SetDepartmentIdType("open_id")
reqCall.SetPageSize(20)
reqCall.SetDepartmentIdType("open_department_id")
reqCall.SetDepartmentId("od_XXXXXXXXX")
reqCall.SetUserIdType("open_id")
result, err := reqCall.Do()
fmt.Printf("request_id:%s", coreCtx.GetRequestID())
fmt.Printf("http status code:%d", coreCtx.GetHTTPStatusCode())
if err != nil {
e := err.(*response.Error)
fmt.Printf(tools.Prettify(e))
return
}
fmt.Printf("reault:%s", tools.Prettify(result))
}

func testDepartmentServiceUpdate() {
coreCtx := core.WarpContext(context.Background())
updateBody := &contact.Department{
Name: "xxxxx",
ParentDepartmentId: "od_xxxxxx",
LeaderUserId: "ou-xxxxxxx",
Order: 666,
CreateGroupChat: false,
}
reqCall := contactService.Departments.Create(coreCtx, updateBody)
reqCall.SetDepartmentIdType("open_department_id")
reqCall.SetUserIdType("open_id")
reqCall.SetClientToken("xxxxxxx")
result, err := reqCall.Do()
fmt.Printf("request_id:%s", coreCtx.GetRequestID())
fmt.Printf("http status code:%d", coreCtx.GetHTTPStatusCode())
if err != nil {
e := err.(*response.Error)
fmt.Printf(tools.Prettify(e))
return
}
fmt.Printf("reault:%s", tools.Prettify(result))
}
43 changes: 43 additions & 0 deletions sample/event/contact.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"path"

"github.com/gin-gonic/gin"
"github.com/larksuite/oapi-sdk-go/core"
"github.com/larksuite/oapi-sdk-go/core/test"
"github.com/larksuite/oapi-sdk-go/core/tools"
eventginserver "github.com/larksuite/oapi-sdk-go/event/http/gin"
contact "github.com/larksuite/oapi-sdk-go/service/contact/v3"
)

func main() {

conf := test.GetInternalConf("staging")

contact.SetDepartmentCreatedEventHandler(conf, func(ctx *core.Context, event *contact.DepartmentCreatedEvent) error {
fmt.Println(ctx.GetRequestID())
fmt.Println(tools.Prettify(event))
return nil
})

contact.SetUserCreateEventHandler(conf, func(ctx *core.Context, event *contact.UserCreateEvent) error {
fmt.Println(ctx.GetRequestID())
fmt.Println(tools.Prettify(event))
return nil
})
contact.SetDepartmentDeletedEventHandler(conf, func(ctx *core.Context, event *contact.DepartmentDeletedEvent) error {
fmt.Println(ctx.GetRequestID())
fmt.Println(tools.Prettify(event))
return nil
})

g := gin.Default()
eventginserver.Register(path.Join("/", conf.GetAppSettings().AppID, "webhook/event"), conf, g)
err := g.Run(":8089")
if err != nil {
fmt.Println(err)
}

}
Loading

0 comments on commit f5da8f1

Please sign in to comment.