module StrawberryAPI::Client::Users
Public Instance Methods
Adds a team to a user
@param [Integer] user_id Id of the user the team should be added to @param [Integer] team_id Id of the team to add the user to
@return [Boolean] Success
# File lib/strawberry_api/client/users.rb, line 88 def add_team_to_user(user_id:, team_id:) post("/users/#{user_id}/teams/#{team_id}").success? end
Creates a new user
@param [String] username Username of the user to create @param [String] firstname nil Firstname of the user to create @param [String] lastname nil Lastname of the user to create @param [String] password Password of the user to create @param [Integer] role_id Id of the role to assign the the user to @option [String] user_matrix_attributes Matric attributes to assign to the user to create
@return [StrawberryAPI::User] The created user
# File lib/strawberry_api/client/users.rb, line 37 def create_user(username:, firstname: nil, lastname: nil, password:, role_id:, user_matrix_attributes: nil) body = { username: username, firstname: firstname, lastname: lastname, password: password, password_confirmation: password, role_id: role_id, user_matrix_attributes: user_matrix_attributes }.to_json data = post("/users", body: body).parse['user'] data.nil? ? nil : User.new(data) end
Deletes a user
@param [Integer] id Id of the user to delete
@return [Boolean] Success
# File lib/strawberry_api/client/users.rb, line 77 def delete_user(id:) delete("/users/#{id}").success? end
Removes a team from a user
@param [Integer] user_id Id of the user to remove the team from @param [Integer] team_id Id of the team the user should be removed from
@return [Boolean] Success
# File lib/strawberry_api/client/users.rb, line 99 def remove_team_from_user(user_id:, team_id:) delete("/users/#{user_id}/teams/#{team_id}").success? end
Updates a user
@param [Integer] id Id of the user to update @option options [String] :username @option options [String] :firstname @option options [String] :lastname @option options [String] :password @option options [String] :role_id @option options [String] :user_matrix_attributes
@return [StrawberryAPI::User] The updated user
# File lib/strawberry_api/client/users.rb, line 64 def update_user(id:, **options) body = args.to_json data = put("/users/#{id}", body: body).parse data.nil? ? nil : User.new(data) end
Fetches all users
@return [Array<StrawberryAPI::User>] A list of users
# File lib/strawberry_api/client/users.rb, line 21 def user(id:) data = get("/users/#{id}?with_teams=true").parse['user'] data.nil? ? nil : User.new(data) end
Fetches a user API keys
@param [Integer] id Id of the user to retrieve API keys
@return [StrawberryAPI::ApiKey] The fetched user API key
# File lib/strawberry_api/client/users.rb, line 119 def user_api_keys(id:) ApiKey.find(user_id: id) end
Fetches a user settings
@param [Integer] id Id of the user to retrieve settings
@return [Hash] The fetched user settings
# File lib/strawberry_api/client/users.rb, line 109 def user_settings(id:) get("/users/#{id}/settings").parse['user_settings'] end
Fetches all users
@return [Array<StrawberryAPI::User>] A list of users
# File lib/strawberry_api/client/users.rb, line 10 def users get("/users").parse['users']&.map do |user| User.new(user) end end