示例#1
0
文件: regions.go 项目: heartsg/dasea
func (r *Region) Create(d *types.Region) (*types.Region, error) {
	if r.Session == nil {
		return nil, errors.New("No client.Session to send the request.")
	}

	regionRequest := types.NewRegionRequest(d)

	_, body, err := r.Session.Request("/regions",
		requests.POST,
		nil,           //header
		nil,           // query params
		regionRequest, // body data
		true)
	if err != nil {
		return nil, err
	}

	regionResponse := &types.RegionResponse{}
	err = json.Unmarshal(body, regionResponse)
	if err != nil {
		return nil, err
	}

	return regionResponse.Region, nil
}
示例#2
0
文件: regions.go 项目: heartsg/dasea
func (r *Region) Update(id string, d *types.Region) (*types.Region, error) {
	if r.Session == nil {
		return nil, errors.New("No client.Session to send the request.")
	}

	regionRequest := types.NewRegionRequest(d)

	_, body, err := r.Session.Request(fmt.Sprintf("/regions/%s", id),
		requests.PATCH,
		nil,           //header
		nil,           // query params
		regionRequest, // body data
		true)
	if err != nil {
		return nil, err
	}

	regionResponse := &types.RegionResponse{}
	err = json.Unmarshal(body, regionResponse)
	if err != nil {
		return nil, err
	}

	return regionResponse.Region, nil
}