Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceelog committed Aug 19, 2020
1 parent d41d270 commit d7052ae
Show file tree
Hide file tree
Showing 76 changed files with 5,294 additions and 3,223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ See: https://open.feishu.cn/document/ukTMukTMukTM/uITN1EjLyUTNx4iM1UTM
GET https://open.feishu.cn/open-apis/application/v3/is_user_admin
*/
func IsUserAdmin(ctx *feishu.App) (resp []byte, err error) {
func IsUserAdmin(ctx *feishu.App, params url.Values) (resp []byte, err error) {

accessToken, err := ctx.GetTenantAccessTokenHandler()
if err != nil {
return
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiIsUserAdmin, header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiIsUserAdmin+"?"+params.Encode(), header)
}

/*
Expand All @@ -76,9 +76,9 @@ func AdminScopeGet(ctx *feishu.App, params url.Values) (resp []byte, err error)
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiAdminScopeGet+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiAdminScopeGet+"?"+params.Encode(), header)
}

/*
Expand All @@ -100,9 +100,9 @@ func AppVisibility(ctx *feishu.App, params url.Values) (resp []byte, err error)
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiAppVisibility+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiAppVisibility+"?"+params.Encode(), header)
}

/*
Expand All @@ -124,9 +124,9 @@ func VisibleApps(ctx *feishu.App, params url.Values) (resp []byte, err error) {
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiVisibleApps+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiVisibleApps+"?"+params.Encode(), header)
}

/*
Expand All @@ -148,9 +148,9 @@ func AppList(ctx *feishu.App, params url.Values) (resp []byte, err error) {
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiAppList+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiAppList+"?"+params.Encode(), header)
}

/*
Expand All @@ -172,9 +172,9 @@ func UpdateVisibility(ctx *feishu.App, payload []byte) (resp []byte, err error)
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPPost(apiUpdateVisibility, bytes.NewReader(payload), header)
return ctx.Client.HTTPPost(feishu.FeishuServerUrl+apiUpdateVisibility, bytes.NewReader(payload), header)
}

/*
Expand All @@ -200,7 +200,7 @@ func AppAdminUserList(ctx *feishu.App) (resp []byte, err error) {
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiAppAdminUserList, header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiAppAdminUserList, header)
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ func TestIsUserAdmin(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiIsUserAdmin, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiIsUserAdmin, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App

params url.Values
}
tests := []struct {
name string
Expand All @@ -53,7 +55,7 @@ func TestIsUserAdmin(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp = mockResp[tt.name]
gotResp, err := IsUserAdmin(tt.args.ctx)
gotResp, err := IsUserAdmin(tt.args.ctx, tt.args.params)
//fmt.Println(string(gotResp), err)
if (err != nil) != tt.wantErr {
t.Errorf("IsUserAdmin() error = %v, wantErr %v", err, tt.wantErr)
Expand All @@ -70,9 +72,9 @@ func TestAdminScopeGet(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiAdminScopeGet, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiAdminScopeGet, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -107,9 +109,9 @@ func TestAppVisibility(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiAppVisibility, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiAppVisibility, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -144,9 +146,9 @@ func TestVisibleApps(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiVisibleApps, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiVisibleApps, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -181,9 +183,9 @@ func TestAppList(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiAppList, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiAppList, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -218,9 +220,9 @@ func TestUpdateVisibility(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiUpdateVisibility, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiUpdateVisibility, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("POST")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -254,9 +256,9 @@ func TestAppAdminUserList(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiAppAdminUserList, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiAppAdminUserList, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import (
"net/url"

"github.com/fastwego/feishu"
"github.com/fastwego/feishu/apis/appinfo/app_manage"
"github.com/fastwego/feishu/apis/app/app_manage"
)

func ExampleIsUserAdmin() {
var ctx *feishu.App

resp, err := app_manage.IsUserAdmin(ctx)
params := url.Values{}
resp, err := app_manage.IsUserAdmin(ctx, params)

fmt.Println(resp, err)
}
Expand All @@ -34,7 +35,6 @@ func ExampleAdminScopeGet() {
var ctx *feishu.App

params := url.Values{}

resp, err := app_manage.AdminScopeGet(ctx, params)

fmt.Println(resp, err)
Expand All @@ -44,7 +44,6 @@ func ExampleAppVisibility() {
var ctx *feishu.App

params := url.Values{}

resp, err := app_manage.AppVisibility(ctx, params)

fmt.Println(resp, err)
Expand All @@ -54,7 +53,6 @@ func ExampleVisibleApps() {
var ctx *feishu.App

params := url.Values{}

resp, err := app_manage.VisibleApps(ctx, params)

fmt.Println(resp, err)
Expand All @@ -64,7 +62,6 @@ func ExampleAppList() {
var ctx *feishu.App

params := url.Values{}

resp, err := app_manage.AppList(ctx, params)

fmt.Println(resp, err)
Expand All @@ -74,7 +71,6 @@ func ExampleUpdateVisibility() {
var ctx *feishu.App

payload := []byte("{}")

resp, err := app_manage.UpdateVisibility(ctx, payload)

fmt.Println(resp, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package appstore 应用信息/应用商店
package appstore
// Package app_store 应用信息/应用商店
package app_store

import (
"net/http"
Expand All @@ -23,10 +23,33 @@ import (
)

const (
apiCheckUser = "/open-apis/pay/v1/paid_scope/check_user"
apiOrderList = "/open-apis/pay/v1/order/list"
apiOrderGet = "/open-apis/pay/v1/order/get"
)

/*
查询用户是否在应用开通范围
该接口用于查询用户是否在企业管理员设置的使用该应用的范围中。如果设置的付费套餐是按人收费或者限制了最大人数,开放平台会引导企业管理员设置“付费功能开通范围”,本接口用于查询用户是否在企业管理员设置的使用该应用的范围中,可以通过此接口,在付费功能点入口判断是否允许某个用户进入使用。
See: https://open.feishu.cn/document/ukTMukTMukTM/uATNwUjLwUDM14CM1ATN
GET https://open.feishu.cn/open-apis/pay/v1/paid_scope/check_user?open_id=ou_5ad573a6411d72b8305fda3a9c15c70e
*/
func CheckUser(ctx *feishu.App, params url.Values) (resp []byte, err error) {

accessToken, err := ctx.GetTenantAccessTokenHandler()
if err != nil {
return
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiCheckUser+"?"+params.Encode(), header)
}

/*
查询租户购买的付费方案
Expand All @@ -45,9 +68,9 @@ func OrderList(ctx *feishu.App, params url.Values) (resp []byte, err error) {
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiOrderList+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiOrderList+"?"+params.Encode(), header)
}

/*
Expand All @@ -68,7 +91,7 @@ func OrderGet(ctx *feishu.App, params url.Values) (resp []byte, err error) {
}
header := http.Header{}
header.Set("Authorization", "Bearer "+accessToken)
header.Set("Content-appType", "application/json")
header.Set("Content-Type", "application/json")

return ctx.Client.HTTPGet(apiOrderGet+"?"+params.Encode(), header)
return ctx.Client.HTTPGet(feishu.FeishuServerUrl+apiOrderGet+"?"+params.Encode(), header)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package appstore
package app_store

import (
"net/http"
Expand All @@ -30,14 +30,51 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestCheckUser(t *testing.T) {
mockResp := map[string][]byte{
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockRouter.HandleFunc(apiCheckUser, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
}).Methods("GET")

type args struct {
ctx *feishu.App

params url.Values
}
tests := []struct {
name string
args args
wantResp []byte
wantErr bool
}{
{name: "case1", args: args{ctx: test.MockApp}, wantResp: mockResp["case1"], wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp = mockResp[tt.name]
gotResp, err := CheckUser(tt.args.ctx, tt.args.params)
//fmt.Println(string(gotResp), err)
if (err != nil) != tt.wantErr {
t.Errorf("CheckUser() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(gotResp, tt.wantResp) {
t.Errorf("CheckUser() gotResp = %v, want %v", gotResp, tt.wantResp)
}
})
}
}
func TestOrderList(t *testing.T) {
mockResp := map[string][]byte{
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiOrderList, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiOrderList, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down Expand Up @@ -72,9 +109,9 @@ func TestOrderGet(t *testing.T) {
"case1": []byte("{\"errcode\":0,\"errmsg\":\"ok\"}"),
}
var resp []byte
test.MockSvrHandler.HandleFunc(apiOrderGet, func(w http.ResponseWriter, r *http.Request) {
test.MockRouter.HandleFunc(apiOrderGet, func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(resp))
})
}).Methods("GET")

type args struct {
ctx *feishu.App
Expand Down
Loading

0 comments on commit d7052ae

Please sign in to comment.