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
-
#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.
-
#block_user(user_id) ⇒ Boolean
Blocks the specified user.
-
#create_ssh_key(title, key, options = {}) ⇒ Gitlab::ObjectifiedHash
Creates a new SSH key.
-
#create_user(*args) ⇒ Gitlab::ObjectifiedHash
Creates a new user.
-
#delete_email(id, user_id = nil) ⇒ Boolean
Delete email Will delete a email an authorized user if no user ID passed.
-
#delete_ssh_key(id, options = {}) ⇒ Gitlab::ObjectifiedHash
Deletes an SSH key.
-
#delete_user(user_id) ⇒ Gitlab::ObjectifiedHash
Deletes a user.
-
#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash
Updates a user.
-
#email(id) ⇒ Gitlab::ObjectifiedHash
Get a single email.
-
#emails(user_id = nil) ⇒ Gitlab::ObjectifiedHash
Gets user emails.
-
#session(email, password) ⇒ Gitlab::ObjectifiedHash
Creates a new user session.
-
#ssh_key(id) ⇒ Gitlab::ObjectifiedHash
Gets information about SSH key.
-
#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user’s SSH keys.
-
#unblock_user(user_id) ⇒ Boolean
Unblocks the specified user.
-
#user(id = nil) ⇒ Gitlab::ObjectifiedHash
Gets information about a user.
-
#user_search(search, options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Search for groups by name.
-
#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of users.
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.
231 232 233 234 |
# File 'lib/gitlab/client/users.rb', line 231 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.
100 101 102 |
# File 'lib/gitlab/client/users.rb', line 100 def block_user(user_id) post("/users/#{user_id}/block") end |
#create_ssh_key(title, key, options = {}) ⇒ Gitlab::ObjectifiedHash
Creates a new SSH key.
169 170 171 172 173 174 175 176 |
# File 'lib/gitlab/client/users.rb', line 169 def create_ssh_key(title, key, = {}) user_id = .delete :user_id if user_id.to_i.zero? post('/user/keys', body: { title: title, key: key }) else post("/users/#{user_id}/keys", body: { title: title, key: key }) end end |
#create_user(*args) ⇒ Gitlab::ObjectifiedHash
Creates a new user. Requires authentication from an admin account.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gitlab/client/users.rb', line 52 def create_user(*args) = args.last.is_a?(Hash) ? args.pop : {} body = if args[2] { email: args[0], password: args[1], username: args[2] } else { email: args[0], password: args[1], name: args[0] } end body.merge!() 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.
246 247 248 249 |
# File 'lib/gitlab/client/users.rb', line 246 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, options = {}) ⇒ Gitlab::ObjectifiedHash
Deletes an SSH key.
187 188 189 190 191 192 193 194 |
# File 'lib/gitlab/client/users.rb', line 187 def delete_ssh_key(id, = {}) user_id = .delete :user_id if user_id.to_i.zero? delete("/user/keys/#{id}") else delete("/users/#{user_id}/keys/#{id}") end end |
#delete_user(user_id) ⇒ Gitlab::ObjectifiedHash
Deletes a user.
89 90 91 |
# File 'lib/gitlab/client/users.rb', line 89 def delete_user(user_id) delete("/users/#{user_id}") end |
#edit_user(user_id, options = {}) ⇒ Gitlab::ObjectifiedHash
Updates a user.
78 79 80 |
# File 'lib/gitlab/client/users.rb', line 78 def edit_user(user_id, = {}) put("/users/#{user_id}", body: ) end |
#email(id) ⇒ Gitlab::ObjectifiedHash
Get a single email.
217 218 219 |
# File 'lib/gitlab/client/users.rb', line 217 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.
205 206 207 208 |
# File 'lib/gitlab/client/users.rb', line 205 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
This method doesn’t require private_token to be set.
Creates a new user session.
124 125 126 |
# File 'lib/gitlab/client/users.rb', line 124 def session(email, password) post('/session', body: { email: email, password: password }, unauthenticated: true) end |
#ssh_key(id) ⇒ Gitlab::ObjectifiedHash
Gets information about SSH key.
155 156 157 |
# File 'lib/gitlab/client/users.rb', line 155 def ssh_key(id) get("/user/keys/#{id}") end |
#ssh_keys(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of user’s SSH keys.
139 140 141 142 143 144 145 146 |
# File 'lib/gitlab/client/users.rb', line 139 def ssh_keys( = {}) user_id = .delete :user_id if user_id.to_i.zero? get('/user/keys', query: ) else get("/users/#{user_id}/keys", query: ) end end |
#unblock_user(user_id) ⇒ Boolean
Unblocks the specified user. Available only for admin.
111 112 113 |
# File 'lib/gitlab/client/users.rb', line 111 def unblock_user(user_id) post("/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.
30 31 32 |
# File 'lib/gitlab/client/users.rb', line 30 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
261 262 263 264 |
# File 'lib/gitlab/client/users.rb', line 261 def user_search(search, = {}) [:search] = search get('/users', query: ) end |
#users(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of users.
17 18 19 |
# File 'lib/gitlab/client/users.rb', line 17 def users( = {}) get('/users', query: ) end |