Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lib/gitlab/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,16 @@ def ssh_key(id)
#
# @param [String] title The title of an SSH key.
# @param [String] key The SSH key body.
# @param [Hash] options A customizable set of options.
# @option options [Integer] :user_id id of the user to associate the key with
# @return [Gitlab::ObjectifiedHash] Information about created SSH key.
def create_ssh_key(title, key)
post("/user/keys", body: { title: title, key: key })
def create_ssh_key(title, key, options={})
user_id = options.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

# Deletes an SSH key.
Expand All @@ -173,8 +180,13 @@ def create_ssh_key(title, key)
#
# @param [Integer] id The ID of a user's SSH key.
# @return [Gitlab::ObjectifiedHash] Information about deleted SSH key.
def delete_ssh_key(id)
delete("/user/keys/#{id}")
def delete_ssh_key(id, options={})
user_id = options.delete :user_id
if user_id.to_i.zero?
delete("/user/keys/#{id}")
else
delete("/users/#{user_id}/keys/#{id}")
end
end

# Gets user emails.
Expand Down Expand Up @@ -246,5 +258,21 @@ def user_search(search, options={})
options[:search] = search
get("/users", query: options)
end


# Search for user by username
#
# @example
# Gitlab.user_search_username('gitlab')
#
# @param [String] search A username to search
# @param [Hash] options A customizable set of options.
# @option options [String] :per_page Number of user to return per page
# @option options [String] :page The page to retrieve
# @return [Array<Gitlab::ObjectifiedHash>]
def user_search_username(username, options={})
options[:username] = username
get("/users", query: options)
end
end
end