Class: Redminerb::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/redminerb/users.rb

Overview

Users resource wrapper

Class Method Summary collapse

Class Method Details

.create(params) ⇒ Object

Creates a brand new user with the given params. In lib/reminerb/cli/user.rb you can see which ones are required (or running ‘redminerb users create’ from the command line).

Example (that will miss required params :_(:

Redminerb.init!
Redminerb::Users.create login: 'wadus'


35
36
37
38
39
40
41
42
43
# File 'lib/redminerb/users.rb', line 35

def create(params)
  response = Redminerb.client.post_json('/users.json', user: params)
  
  if response.success?
    'Created'
  else
    Redminerb::Client.raise_error! response
  end
end

.list(params) ⇒ Object

Get the users of our Redmine as OpenStruct objects.

Example:

Redminerb.init!
Redminerb::Users.list.each do |user|
   puts user.firstname
end

See lib/reminerb/cli/user.rb code to see other example/s.



17
18
19
20
21
22
23
24
25
# File 'lib/redminerb/users.rb', line 17

def list(params)
  if params.delete('all')
    Redminerb.client.get_collection(:users, params)
  else
    Redminerb.client.get_json('/users.json', params)['users']
  end.map do |user|
    OpenStruct.new user
  end
end

.meObject

Returns a hash with the info of the user’s account behind the API key that is used by the script to access the Redmine’s REST API.

Example:

Redminerb.init!
me = Redminerb::Users.me
puts me['login'] + ': ' + me['mail']


53
54
55
# File 'lib/redminerb/users.rb', line 53

def me
  Redminerb.client.get_json('/users/current.json')['user']
end

.read(id) ⇒ Object



57
58
59
# File 'lib/redminerb/users.rb', line 57

def read(id)
  OpenStruct.new Redminerb.client.get_json("/users/#{id}.json")['user']
end