Module: StrawberryAPI::Client::Users

Included in:
StrawberryAPI::Client
Defined in:
lib/strawberry_api/client/users.rb

Instance Method Summary collapse

Instance Method Details

#add_team_to_user(user_id:, team_id:) ⇒ Boolean

Adds a team to a user

Parameters:

  • user_id (Integer)

    Id of the user the team should be added to

  • team_id (Integer)

    Id of the team to add the user to

Returns:

  • (Boolean)

    Success



88
89
90
# 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) ⇒ StrawberryAPI::User

Creates a new user

Parameters:

  • username (String)

    Username of the user to create

  • firstname (String)

    nil Firstname of the user to create

  • lastname (String)

    nil Lastname of the user to create

  • password (String)

    Password of the user to create

  • role_id (Integer)

    Id of the role to assign the the user to

  • [String] (Hash)

    a customizable set of options

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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:) ⇒ Boolean

Deletes a user

Parameters:

  • id (Integer)

    Id of the user to delete

Returns:

  • (Boolean)

    Success



77
78
79
# 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:) ⇒ Boolean

Removes a team from a user

Parameters:

  • user_id (Integer)

    Id of the user to remove the team from

  • team_id (Integer)

    Id of the team the user should be removed from

Returns:

  • (Boolean)

    Success



99
100
101
# 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) ⇒ StrawberryAPI::User

Updates a user

Parameters:

  • id (Integer)

    Id of the user to update

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :username (String)
  • :firstname (String)
  • :lastname (String)
  • :password (String)
  • :role_id (String)
  • :user_matrix_attributes (String)

Returns:



64
65
66
67
68
69
# 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:) ⇒ Array<StrawberryAPI::User>

Fetches all users

Returns:



21
22
23
24
# 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:) ⇒ StrawberryAPI::ApiKey

Fetches a user API keys

Parameters:

  • id (Integer)

    Id of the user to retrieve API keys

Returns:



119
120
121
# File 'lib/strawberry_api/client/users.rb', line 119

def user_api_keys(id:)
  ApiKey.find(user_id: id)
end

#user_settings(id:) ⇒ Hash

Fetches a user settings

Parameters:

  • id (Integer)

    Id of the user to retrieve settings

Returns:

  • (Hash)

    The fetched user settings



109
110
111
# File 'lib/strawberry_api/client/users.rb', line 109

def (id:)
  get("/users/#{id}/settings").parse['user_settings']
end

#usersArray<StrawberryAPI::User>

Fetches all users

Returns:



10
11
12
13
14
# File 'lib/strawberry_api/client/users.rb', line 10

def users
  get("/users").parse['users']&.map do |user|
    User.new(user)
  end
end