• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang rbxweb.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Client类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: UploadModel

// UploadModel uploads data from `reader` to Roblox as a Model asset. If
// updating an existing model, `modelId` should be the id of the model. If
// `modelId` is 0, then a new model will be uploaded. If uploading a new
// model, `info` can be used to specify information about the model.
//
// This function requires the client to be logged in.
func UploadModel(client *rbxweb.Client, reader io.Reader, modelId int64, info url.Values) (assetVersionId int64, err error) {
	query := url.Values{
		"assetid": {client.I64toa(modelId)},
		"type":    {"Model"},
		//	"name":          {"Unnamed Model"},
		//	"description":   {""},
		//	"genreTypeId":   {"1"},
		//	"isPublic":      {"False"},
		//	"allowComments": {"False"},
	}
	if info != nil {
		for key, value := range info {
			query[key] = value
		}
	}

	return assetVersionId, err
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:24,代码来源:asset.go


示例3: GetIdFromName

// GetIdFromName returns a user id from a user name.
func GetIdFromName(client *rbxweb.Client, name string) (id int32, err error) {
	if name == "" {
		return 0, errors.New("name not specified")
	}
	query := url.Values{
		"UserName": {name},
	}
	req, _ := http.NewRequest("HEAD", client.GetURL(`www`, `/User.aspx`, query), nil)
	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	resp.Body.Close()
	values, err := url.ParseQuery(resp.Header.Get("Location"))
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	return client.Atoi32(values.Get("ID"))
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:20,代码来源:user.go


示例4: 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


示例5: 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


示例6: UpdatePlace

// UpdatePlace uploads data from `reader` to Roblox as a Place asset.
// `placeId` must be the id of an existing place. This function cannot create
// a new place.
//
// This function requires the client to be logged in.
func UpdatePlace(client *rbxweb.Client, reader io.Reader, placeId int64) (err error) {
	query := url.Values{
		"assetid": {client.I64toa(placeId)},
		"type":    {"Place"},
	}
	buf := new(bytes.Buffer)
	buf.ReadFrom(reader)
	req, _ := http.NewRequest("POST", client.GetURL(`www`, `/Data/Upload.ashx`, query), buf)
	req.Header.Set("User-Agent", "Roblox")

	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return err
	}
	defer resp.Body.Close()
	return nil
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:22,代码来源:asset.go


示例7: Upload

// Upload generically uploads data from `reader` as an asset to the ROBLOX
// website. `info` can be used to specify information about the model. The
// following parameters are known:
//
//     type           - The type of asset.
//     assetid        - The id of the asset to update. 0 uploads a new asset.
//     name           - The name of the asset.
//     description    - The asset's description.
//     genreTypeId    - The asset's genre.
//     isPublic       - Whether the asset can be taken by other users.
//     allowComments  - Whether users can comment on the asset.
//
// The success of this function is highly dependent on these parameters. For
// example, most asset types may only be uploaded by authorized users.
// Parameters that specify information about the asset only apply for new
// assets. That is, updating an asset will only update the contents, but not
// the information about it.
//
// `assetVersionId` is the version id of the uploaded asset. This is unique
// for each upload. This can be used with GetIdFromVersion to get the asset
// id.
//
// This function requires the client to be logged in.
func Upload(client *rbxweb.Client, reader io.Reader, info url.Values) (assetVersionId int64, err error) {
	buf := new(bytes.Buffer)
	buf.ReadFrom(reader)
	req, _ := http.NewRequest("POST", client.GetURL(`www`, `/Data/Upload.ashx`, info), buf)
	req.Header.Set("User-Agent", "roblox/rbxweb")

	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	defer resp.Body.Close()

	r := new(bytes.Buffer)
	r.ReadFrom(resp.Body)
	assetVersionId, _ = client.Atoi64(r.String())

	return assetVersionId, err
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:41,代码来源:asset.go


示例8: 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


示例9: 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


示例10: GetIdFromVersion

// GetIdFromVersion returns an asset id from an asset version id.
func GetIdFromVersion(client *rbxweb.Client, assetVersionId int64) (assetId int64, err error) {
	query := url.Values{
		"avid": {client.I64toa(assetVersionId)},
	}

	// This relies on how asset names are converted to url names. Currently,
	// if an asset name is "_", its url becomes "unnamed".
	req, _ := http.NewRequest("HEAD", client.GetURL(`www`, `/_-item`, query), nil)
	resp, err := client.Do(req)
	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}
	resp.Body.Close()

	if err = client.AssertResp(resp, err); err != nil {
		return 0, err
	}

	return client.Atoi64(resp.Request.URL.Query().Get("id"))
}
开发者ID:JanBerktold,项目名称:rbxweb,代码行数:21,代码来源:asset.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang datastore.CloseTest函数代码示例发布时间:2022-05-23
下一篇:
Golang log.Log类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap