Exemple #1
0
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
}
Exemple #2
0
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
}