module Gitlab::Client::Users

Defines methods related to users. @see docs.gitlab.com/ce/api/users.html @see docs.gitlab.com/ce/api/session.html

Public Instance Methods

add_email(email, user_id=nil) click to toggle source

Creates a new email Will create a new email an authorized user if no user ID passed.

@example

Gitlab.add_email('email@example.com')
Gitlab.add_email('email@example.com', 2)

@param [String] email Email address @param [Integer] user_id The ID of a user. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/users.rb, line 215
def add_email(email, user_id=nil)
  url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
  post(url, body: {email: email})
end
block_user(user_id) click to toggle source

Blocks the specified user. Available only for admin.

@example

Gitlab.block_user(15)

@param [Integer] user_id The Id of user @return [Boolean] success or not

# File lib/gitlab/client/users.rb, line 98
def block_user(user_id)
  put("/users/#{user_id}/block")
end
create_ssh_key(title, key) click to toggle source

Creates a new SSH key.

@example

Gitlab.create_ssh_key('key title', 'key body')

@param [String] title The title of an SSH key. @param [String] key The SSH key body. @return [Gitlab::ObjectifiedHash] Information about created SSH key.

# File lib/gitlab/client/users.rb, line 165
def create_ssh_key(title, key)
  post("/user/keys", body: { title: title, key: key })
end
create_user(*args) click to toggle source

Creates a new user. Requires authentication from an admin account.

@example

Gitlab.create_user('joe@foo.org', 'secret', 'joe', { name: 'Joe Smith' })
or
Gitlab.create_user('joe@foo.org', 'secret')

@param [String] email The email of a user. @param [String] password The password of a user. @param [String] username The username of a user. @param [Hash] options A customizable set of options. @option options [String] :name The name of a user. Defaults to email. @option options [String] :skype The skype of a user. @option options [String] :linkedin The linkedin of a user. @option options [String] :twitter The twitter of a user. @option options [Integer] :projects_limit The limit of projects for a user. @return [Gitlab::ObjectifiedHash] Information about created user.

# File lib/gitlab/client/users.rb, line 50
def create_user(*args)
  options = Hash === args.last ? args.pop : {}
  if args[2]
    body = { email: args[0], password: args[1], username: args[2] }
  else
    body = { email: args[0], password: args[1], name: args[0] }
  end
  body.merge!(options)
  post('/users', body: body)
end
delete_email(id, user_id=nil) click to toggle source

Delete email Will delete a email an authorized user if no user ID passed.

@example

Gitlab.delete_email(2)
Gitlab.delete_email(3, 2)

@param [Integer] id Email address ID @param [Integer] user_id The ID of a user. @return [Boolean]

# File lib/gitlab/client/users.rb, line 230
def delete_email(id, user_id=nil)
  url = user_id.to_i.zero? ? "/user/emails/#{id}" : "/users/#{user_id}/emails/#{id}"
  delete(url)
end
delete_ssh_key(id) click to toggle source

Deletes an SSH key.

@example

Gitlab.delete_ssh_key(1)

@param [Integer] id The ID of a user's SSH key. @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.

# File lib/gitlab/client/users.rb, line 176
def delete_ssh_key(id)
  delete("/user/keys/#{id}")
end
delete_user(user_id) click to toggle source

Deletes a user.

@example

Gitlab.delete_user(1)

@param [Integer] id The ID of a user. @return [Gitlab::ObjectifiedHash] Information about deleted user.

# File lib/gitlab/client/users.rb, line 87
def delete_user(user_id)
  delete("/users/#{user_id}")
end
edit_user(user_id, options={}) click to toggle source

Updates a user.

@example

Gitlab.edit_user(15, { email: 'joe.smith@foo.org', projects_limit: 20 })

@param [Integer] id The ID of a user. @param [Hash] options A customizable set of options. @option options [String] :email The email of a user. @option options [String] :password The password of a user. @option options [String] :name The name of a user. Defaults to email. @option options [String] :skype The skype of a user. @option options [String] :linkedin The linkedin of a user. @option options [String] :twitter The twitter of a user. @option options [Integer] :projects_limit The limit of projects for a user. @return [Gitlab::ObjectifiedHash] Information about created user.

# File lib/gitlab/client/users.rb, line 76
def edit_user(user_id, options={})
  put("/users/#{user_id}", body: options)
end
email(id) click to toggle source

Get a single email.

@example

Gitlab.email(3)

@param [Integer] id The ID of a email. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/users.rb, line 201
def email(id)
  get("/user/emails/#{id}")
end
emails(user_id=nil) click to toggle source

Gets user emails. Will return emails an authorized user if no user ID passed.

@example

Gitlab.emails
Gitlab.emails(2)

@param [Integer] user_id The ID of a user. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/users.rb, line 189
def emails(user_id=nil)
  url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
  get(url)
end
session(email, password) click to toggle source

Creates a new user session.

@example

Gitlab.session('jack@example.com', 'secret12345')

@param [String] email The email of a user. @param [String] password The password of a user. @return [Gitlab::ObjectifiedHash] @note This method doesn't require private_token to be set.

# File lib/gitlab/client/users.rb, line 122
def session(email, password)
  post("/session", body: { email: email, password: password })
end
ssh_key(id) click to toggle source

Gets information about SSH key.

@example

Gitlab.ssh_key(1)

@param [Integer] id The ID of a user's SSH key. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/users.rb, line 153
def ssh_key(id)
  get("/user/keys/#{id}")
end
ssh_keys(options={}) click to toggle source

Gets a list of user's SSH keys.

@example

Gitlab.ssh_keys
Gitlab.ssh_keys({ user_id: 2 })

@param [Hash] options A customizable set of options. @option options [Integer] :page The page number. @option options [Integer] :per_page The number of results per page. @option options [Integer] :user_id The ID of the user to retrieve the keys for. @return [Array<Gitlab::ObjectifiedHash>]

# File lib/gitlab/client/users.rb, line 137
def ssh_keys(options={})
  user_id = options.delete :user_id
  if user_id.to_i.zero?
    get("/user/keys", query: options)
  else
    get("/users/#{user_id}/keys", query: options)
  end
end
unblock_user(user_id) click to toggle source

Unblocks the specified user. Available only for admin.

@example

Gitlab.unblock_user(15)

@param [Integer] user_id The Id of user @return [Boolean] success or not

# File lib/gitlab/client/users.rb, line 109
def unblock_user(user_id)
  put("/users/#{user_id}/unblock")
end
user(id=nil) click to toggle source

Gets information about a user. Will return information about an authorized user if no ID passed.

@example

Gitlab.user
Gitlab.user(2)

@param [Integer] id The ID of a user. @return [Gitlab::ObjectifiedHash]

# File lib/gitlab/client/users.rb, line 28
def user(id=nil)
  id.to_i.zero? ? get("/user") : get("/users/#{id}")
end
users(options={}) click to toggle source

Gets a list of users.

@example

Gitlab.users

@param [Hash] options A customizable set of options. @option options [Integer] :page The page number. @option options [Integer] :per_page The number of results per page. @return [Array<Gitlab::ObjectifiedHash>]

# File lib/gitlab/client/users.rb, line 15
def users(options={})
  get("/users", query: options)
end