module StrawberryAPI::Client::Users

Public Instance Methods

add_team_to_user(user_id:, team_id:) click to toggle source

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
create_user(username:, firstname: nil, lastname: nil, password:, role_id:, user_matrix_attributes: nil) click to toggle source

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
delete_user(id:) click to toggle source

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
remove_team_from_user(user_id:, team_id:) click to toggle source

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
update_user(id:, **options) click to toggle source

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
user(id:) click to toggle source

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
user_api_keys(id:) click to toggle source

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
user_settings(id:) click to toggle source

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
users() click to toggle source

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