Class: Matterhorn::Endpoint::User
- Inherits:
-
Matterhorn::Endpoint
- Object
- Matterhorn::Endpoint
- Matterhorn::Endpoint::User
- Defined in:
- lib/matterhorn/endpoint/user.rb
Overview
Matterhorn::Endpoint::User ===
Instance Attribute Summary
Attributes inherited from Matterhorn::Endpoint
#response_body, #response_code
Instance Method Summary collapse
- #api ⇒ Object
-
#create(username, password, name, email, roles) ⇒ Object
Create a new user with username, password, name, email and a list of roles.
-
#delete(username) ⇒ Object
————————————————————————————- delete —.
-
#get(username) ⇒ Object
Return a given user as a hash { ‘user’ => { ‘username’ => <username>, ‘name’ => <name>, ‘email’ => <email>, ‘roles’ => [ <role>, …] } }.
-
#index(offset = 0, limit = 100) ⇒ Object
Return a list of users as a hash { ‘users’ => { ‘user’ => [ { ‘username’ => <username>, ‘name’ => <name>, ‘email’ => <email>, ‘roles’ => [ <role>, …] }, … ] } }.
- #info_me(username = nil) ⇒ Object
-
#update(username, password, name, email, roles) ⇒ Object
————————————————————————————- update —.
Methods inherited from Matterhorn::Endpoint
#close, create, #error_code, #error_msg, #error_occurred?, #initialize, open
Constructor Details
This class inherits a constructor from Matterhorn::Endpoint
Instance Method Details
#api ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/matterhorn/endpoint/user.rb', line 90 def api info = nil begin split_response http_api_client.get( "api" ) info = JSON.parse(response_body) rescue => ex exception_handler('api', ex, {}) end info end |
#create(username, password, name, email, roles) ⇒ Object
Create a new user with username, password, name, email and a list of roles.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/matterhorn/endpoint/user.rb', line 14 def create(username, password, name, email, roles) done = false begin split_response http_endpoint_client.post( "user-utils", convert_to_form_param(username, password, name, email, roles) ) done = true rescue => ex exception_handler('create', ex, { 409 => "An user with this username: #{username} already exist!" } ) end done end |
#delete(username) ⇒ Object
————————————————————————————- delete —
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/matterhorn/endpoint/user.rb', line 146 def delete(username) done = false begin split_response http_endpoint_client.delete( "user-utils/#{username}.json" ) done = true rescue => ex exception_handler('create', ex, { 404 => "User[#{username}] not found!" } ) end done end |
#get(username) ⇒ Object
Return a given user as a hash {
'user' => {
'username' => <username>,
'name' => <name>,
'email' => <email>,
'roles' => [ <role>, ...]
}
}
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/matterhorn/endpoint/user.rb', line 73 def get(username) user = nil begin split_response http_endpoint_client.get( "user-utils/#{username}.json" ) user = { 'user' => filter_user(JSON.parse(response_body)['user']) } rescue => ex exception_handler('create', ex, { 404 => "User[#{username}] not found!" } ) end user end |
#index(offset = 0, limit = 100) ⇒ Object
Return a list of users as a hash {
'users' => {
'user' => [
{
'username' => <username>,
'name' => <name>,
'email' => <email>,
'roles' => [ <role>, ...]
},
...
]
}
}
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/matterhorn/endpoint/user.rb', line 49 def index(offset = 0, limit = 100) users = {} begin split_response http_endpoint_client.get( "/user-utils/users.json?limit=#{limit}&offset=#{offset}" ) users = filter_users(JSON.parse(response_body)) rescue => ex exception_handler('index', ex, {}) end users end |
#info_me(username = nil) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/matterhorn/endpoint/user.rb', line 104 def info_me(username = nil) me = nil begin headers = {} headers['X-RUN-AS-USER'] = username unless username.nil? split_response http_api_client.get( "api/info/me", headers ) me = JSON.parse(response_body) rescue => ex exception_handler('info_me', ex, { 403 => "User[#{username}] has not access!", 404 => "User[#{username}] not found!" } ) end me end |
#update(username, password, name, email, roles) ⇒ Object
————————————————————————————- update —
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/matterhorn/endpoint/user.rb', line 126 def update(username, password, name, email, roles) done = false begin split_response http_endpoint_client.put( "user-utils/#{username}.json", convert_to_form_param(nil, password, name, email, roles) ) done = true rescue => ex exception_handler('create', ex, { 404 => "User[#{username}] not found!" } ) end done end |