Module: Gitlab::Client::Users

Included in:
Gitlab::Client
Defined in:
lib/gitlab/client/users.rb

Overview

Defines methods related to users.

Instance Method Summary collapse

Instance Method Details

#add_email(email, user_id = nil) ⇒ Gitlab::ObjectifiedHash

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

Examples:

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


208
209
210
211
# File 'lib/gitlab/client/users.rb', line 208

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) ⇒ Boolean

Blocks the specified user. Available only for admin.

Examples:

Gitlab.block_user(15)


98
99
100
# File 'lib/gitlab/client/users.rb', line 98

def block_user(user_id)
  put("/users/#{user_id}/block")
end

#create_ssh_key(title, key) ⇒ Gitlab::ObjectifiedHash

Creates a new SSH key.

Examples:

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


158
159
160
# File 'lib/gitlab/client/users.rb', line 158

def create_ssh_key(title, key)
  post("/user/keys", body: { title: title, key: key })
end

#create_user(*args) ⇒ Gitlab::ObjectifiedHash

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

Examples:

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


50
51
52
53
54
55
56
57
58
59
# 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) ⇒ Boolean

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

Examples:

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


223
224
225
226
# File 'lib/gitlab/client/users.rb', line 223

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) ⇒ Gitlab::ObjectifiedHash

Deletes an SSH key.

Examples:

Gitlab.delete_ssh_key(1)


169
170
171
# File 'lib/gitlab/client/users.rb', line 169

def delete_ssh_key(id)
  delete("/user/keys/#{id}")
end

#delete_user(user_id) ⇒ Gitlab::ObjectifiedHash

Deletes a user.

Examples:

Gitlab.delete_user(1)


87
88
89
# File 'lib/gitlab/client/users.rb', line 87

def delete_user(user_id)
  delete("/users/#{user_id}")
end

#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash

Updates a user.

Examples:

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

Options Hash (options):

  • :email (String)

    The email of a user.

  • :password (String)

    The password of a user.

  • :name (String)

    The name of a user. Defaults to email.

  • :skype (String)

    The skype of a user.

  • :linkedin (String)

    The linkedin of a user.

  • :twitter (String)

    The twitter of a user.

  • :projects_limit (Integer)

    The limit of projects for a user.



76
77
78
# File 'lib/gitlab/client/users.rb', line 76

def edit_user(user_id, options={})
  put("/users/#{user_id}", body: options)
end

#email(id) ⇒ Gitlab::ObjectifiedHash

Get a single email.

Examples:

Gitlab.email(3)


194
195
196
# File 'lib/gitlab/client/users.rb', line 194

def email(id)
  get("/user/emails/#{id}")
end

#emails(user_id = nil) ⇒ Gitlab::ObjectifiedHash

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

Examples:

Gitlab.emails
Gitlab.emails(2)


182
183
184
185
# File 'lib/gitlab/client/users.rb', line 182

def emails(user_id=nil)
  url = user_id.to_i.zero? ? "/user/emails" : "/users/#{user_id}/emails"
  get(url)
end

#session(email, password) ⇒ Gitlab::ObjectifiedHash

Note:

This method doesn't require private_token to be set.

Creates a new user session.

Examples:

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


122
123
124
# File 'lib/gitlab/client/users.rb', line 122

def session(email, password)
  post("/session", body: { email: email, password: password })
end

#ssh_key(id) ⇒ Gitlab::ObjectifiedHash

Gets information about SSH key.

Examples:

Gitlab.ssh_key(1)


146
147
148
# File 'lib/gitlab/client/users.rb', line 146

def ssh_key(id)
  get("/user/keys/#{id}")
end

#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of user's SSH keys.

Examples:

Gitlab.ssh_keys

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



135
136
137
# File 'lib/gitlab/client/users.rb', line 135

def ssh_keys(options={})
  get("/user/keys", query: options)
end

#unblock_user(user_id) ⇒ Boolean

Unblocks the specified user. Available only for admin.

Examples:

Gitlab.unblock_user(15)


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

def unblock_user(user_id)
  put("/users/#{user_id}/unblock")
end

#user(id = nil) ⇒ Gitlab::ObjectifiedHash

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

Examples:

Gitlab.user
Gitlab.user(2)


28
29
30
# File 'lib/gitlab/client/users.rb', line 28

def user(id=nil)
  id.to_i.zero? ? get("/user") : get("/users/#{id}")
end

#user_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Search for groups by name

Examples:

Gitlab.user_search('gitlab')

Options Hash (options):

  • :per_page (String)

    Number of user to return per page

  • :page (String)

    The page to retrieve



238
239
240
241
# File 'lib/gitlab/client/users.rb', line 238

def user_search(search, options={})
  options[:search] = search
  get("/users", query: options)
end

#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>

Gets a list of users.

Examples:

Gitlab.users

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.



15
16
17
# File 'lib/gitlab/client/users.rb', line 15

def users(options={})
  get("/users", query: options)
end