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

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

Creates a new SSH key.

Examples:

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

Parameters:

  • title (String)

    The title of an SSH key.

  • key (String)

    The SSH key body.

Returns:



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

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

#create_user(email, password, options = {}) ⇒ Gitlab::ObjectifiedHash

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

Parameters:

  • email (String)

    The email of a user.

  • password (String)

    The password of a user.

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :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.

Returns:



44
45
46
47
# File 'lib/gitlab/client/users.rb', line 44

def create_user(email, password, options={})
  body = {:email => email, :password => password, :name => email}.merge(options)
  post("/users", :body => body)
end

#delete_ssh_key(id) ⇒ Gitlab::ObjectifiedHash

Deletes an SSH key.

Examples:

Gitlab.delete_ssh_key(1)

Parameters:

  • id (Integer)

    The ID of a user’s SSH key.

Returns:



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

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

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

Updates a user.

Parameters:

  • id (Integer)

    The ID of a user.

  • options (Hash) (defaults to: {})

    A customizable set of options.

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.

Returns:



61
62
63
# File 'lib/gitlab/client/users.rb', line 61

def edit_user(user_id, options={})
  put("/users/#{user_id}", :body => options)
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('[email protected]', 'secret12345')

Parameters:

  • email (String)

    The email of a user.

  • password (String)

    The password of a user.

Returns:



74
75
76
# File 'lib/gitlab/client/users.rb', line 74

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)

Parameters:

  • id (Integer)

    The ID of a user’s SSH key.

Returns:



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

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

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



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

def ssh_keys(options={})
  get("/user/keys", :query => options)
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)

Parameters:

  • id (Integer) (defaults to: nil)

    The ID of a user.

Returns:



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

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

Gets a list of users.

Examples:

Gitlab.users

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :page (Integer)

    The page number.

  • :per_page (Integer)

    The number of results per page.

Returns:



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

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