Module: Roust::User
- Included in:
- Roust
- Defined in:
- lib/roust/user.rb
Instance Method Summary collapse
-
#user_create(attrs) ⇒ Object
Requires RT > 3.8.0.
-
#user_show(id) ⇒ Object
(also: #user)
id can be numeric (e.g. 28) or textual (e.g. john).
- #user_update(id, attrs) ⇒ Object
Instance Method Details
#user_create(attrs) ⇒ Object
Requires RT > 3.8.0
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/roust/user.rb', line 44 def user_create(attrs) default_attrs = { 'id' => 'user/new' } attrs = default_attrs.merge(attrs).stringify_keys! content = compose_content('user', attrs['id'], attrs) response = self.class.post( '/user/new', :body => { :content => content } ) body, _ = explode_response(response) case body when /^# User (.+) created/ id = $1 # Return the whole user, not just the id. user_show(id) when /^# Could not create user/ raise BadRequest, body when /^# Syntax error/ raise SyntaxError, body else raise UnhandledResponse, body end end |
#user_show(id) ⇒ Object Also known as: user
id can be numeric (e.g. 28) or textual (e.g. john)
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/roust/user.rb', line 4 def user_show(id) response = self.class.get("/user/#{id}") body, _ = explode_response(response) if body =~ /No user named/ nil else hash = body_to_hash(body) convert_response_boolean_attrs(hash) end end |
#user_update(id, attrs) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/roust/user.rb', line 16 def user_update(id, attrs) convert_request_boolean_attrs(attrs) content = compose_content('user', id, attrs) response = self.class.post( "/user/#{id}/edit", :body => { :content => content } ) body, _ = explode_response(response) case body when /^# User (.+) updated/ id = $1 user_show(id) when /^# You are not allowed to modify user \d+/ raise Unauthorized, body when /^# Syntax error/ raise SyntaxError, body else raise UnhandledResponse end end |