当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Get方法代码示例

本文整理汇总了Golang中github.com/JanBerktold/rbxweb.Client.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Get方法的具体用法?Golang Client.Get怎么用?Golang Client.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/JanBerktold/rbxweb.Client的用法示例。


在下文中一共展示了Client.Get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GetLatestModel

// GetLatestModel returns the asset id of the latest model for a given user.
// While this is useful for retrieving the asset id of a newly created model
// that was just uploaded, it is not necessarily reliable for this purpose.
func GetLatestModel(client *rbxweb.Client, userId int32) (assetId int64, err error) {
	if userId == 0 {
		return 0, errors.New("invalid user id")
	}

	query := url.Values{
		"Category":          {"Models"},
		"SortType":          {"RecentlyUpdated"},
		"IncludeNotForSale": {"true"},
		"ResultsPerPage":    {"1"},
		"CreatorID":         {client.I32toa(userId)},
	}
	resp, err := client.Get(client.GetURL(`api`, `/catalog/json`, query))
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	defer resp.Body.Close()

	dec := json.NewDecoder(resp.Body)
	var asset []struct {
		AssetId int64
	}
	if err = dec.Decode(&asset); err != nil {
		return 0, errors.New("JSON decode failed: " + err.Error())
	}
	return asset[0].AssetId, nil
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:30,代码来源:asset.go

示例2: GetInfo

// GetInfo returns information about the current user.
//
// This function requires the client to be logged in.
func GetInfo(client *rbxweb.Client) (info Info, err error) {
	resp, err := client.Get(client.GetURL(`www`, `/MobileAPI/UserInfo`, nil))
	if err = client.AssertResp(resp, err); err != nil {
		return info, err
	}
	defer resp.Body.Close()
	dec := json.NewDecoder(resp.Body)
	if err = dec.Decode(&info); err != nil {
		return info, errors.New("JSON decode failed: " + err.Error())
	}
	return info, nil
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:15,代码来源:user.go

示例3: GetInfo

// GetInfo returns information about an asset, given an asset id.
func GetInfo(client *rbxweb.Client, id int64) (info Info, err error) {
	query := url.Values{
		"assetId": {client.I64toa(id)},
	}
	resp, err := client.Get(client.GetURL(`api`, `/marketplace/productinfo`, query))
	if err = client.AssertResp(resp, err); err != nil {
		return Info{}, err
	}
	defer resp.Body.Close()

	dec := json.NewDecoder(resp.Body)
	dec.Decode(&info)
	return
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:15,代码来源:asset.go

示例4: GetCurrentId

// GetCurrentId returns the id of the user currently logged in.
//
// This function requires the client to be logged in.
func GetCurrentId(client *rbxweb.Client) (id int32, err error) {
	resp, err := client.Get(client.GetURL(`www`, `/Game/GetCurrentUser.ashx`, nil))
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	defer resp.Body.Close()

	var r bytes.Buffer
	r.ReadFrom(resp.Body)
	id, err = client.Atoi32(r.String())
	if err != nil {
		return 0, errors.New("user is not authorized")
	}
	return id, nil
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:18,代码来源:user.go

示例5: GetNameFromId

// GetNameFromId returns a user name from a user id.
func GetNameFromId(client *rbxweb.Client, id int32) (name string, err error) {
	if id == 0 {
		return "", errors.New("id not specified")
	}
	resp, err := client.Get(client.GetURL(`api`, `/users/`+client.I32toa(id), nil))
	if err = client.AssertResp(resp, err); err != nil {
		return "", err
	}
	defer resp.Body.Close()
	dec := json.NewDecoder(resp.Body)
	var user struct {
		Username string
	}
	if err = dec.Decode(&user); err != nil {
		return "", errors.New("JSON decode failed: " + err.Error())
	}
	return user.Username, nil
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:19,代码来源:user.go


注:本文中的github.com/JanBerktold/rbxweb.Client.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。