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'


32
33
34
35
36
37
38
39
40
# File 'lib/redminerb/users.rb', line 32

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.



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

def list(params)
  Redminerb.client.get_json('/users.json', params)['users'].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']


50
51
52
# File 'lib/redminerb/users.rb', line 50

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

.read(id) ⇒ Object



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

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