Example #1
0
func (r *Role) Create(d *types.Role) (*types.Role, error) {
	if r.Session == nil {
		return nil, errors.New("No client.Session to send the request.")
	}

	roleRequest := types.NewRoleRequest(d)

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

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

	return roleResponse.Role, nil
}
Example #2
0
func (r *Role) Update(id string, d *types.Role) (*types.Role, error) {
	if r.Session == nil {
		return nil, errors.New("No client.Session to send the request.")
	}

	roleRequest := types.NewRoleRequest(d)

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

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

	return roleResponse.Role, nil
}