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

	userRequest := types.NewUserRequest(u)

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

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

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

	userRequest := types.NewUserRequest(u)

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

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

	return userResponse.User, nil
}
Example #3
0
func (r *User) ChangePassword(id string, password string, originalPassword string) error {
	if r.Session == nil {
		return errors.New("No client.Session to send the request.")
	}

	userRequest := types.NewUserRequest(&types.User{
		Password:         password,
		OriginalPassword: originalPassword,
	})

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

	return nil
}