Class: Visor::Auth::Server
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Visor::Auth::Server
- Includes:
- Common::Config, Common::Exception
- Defined in:
- lib/auth/server.rb
Overview
The VISoR Auth System (VAS) server class. This class supports all users management operations through the REST API implemented along the following routes.
Instance Method Summary collapse
-
#delete('/users/: access_key') ⇒ JSON
Delete an user and returns its information.
-
#get('/users/: access_key') ⇒ JSON
Get information about a specific user.
-
#get('/users') ⇒ JSON
Get information about all registered users.
-
#post('/users') ⇒ JSON
Registers a new user and returns its data.
-
#put('/users/: access_key') ⇒ JSON
Update an existing user information and return it.
Instance Method Details
#delete('/users/: access_key') ⇒ JSON
Delete an user and returns its information.
189 190 191 192 193 194 195 196 |
# File 'lib/auth/server.rb', line 189 delete '/users/:access_key' do |access_key| begin user = DB.delete_user(access_key) {user: user}.to_json rescue NotFound => e json_error 404, e. end end |
#get('/users/: access_key') ⇒ JSON
Get information about a specific user.
{"image": {
"_id":<_id>,
"access_key":<access_key>,
"secret_key":<secret_key>,
"email":<email>,
"created_at":<creation timestamp>,
"updated_at":<update timestamp>
}}
117 118 119 120 121 122 123 124 |
# File 'lib/auth/server.rb', line 117 get '/users/:access_key' do |access_key| begin user = DB.get_user(access_key) {user: user}.to_json rescue NotFound => e json_error 404, e. end end |
#get('/users') ⇒ JSON
Get information about all registered users.
{ "users": [{
"_id":<_id>,
"access_key":<access_key>,
"secret_key":<secret_key>,
"email":<email>,
"created_at":<creation timestamp>,
"updated_at":<update timestamp>,
}, ...]}
The following options can be passed as query parameters.
88 89 90 91 92 93 94 95 |
# File 'lib/auth/server.rb', line 88 get '/users' do begin users = DB.get_users(params) {users: users}.to_json rescue NotFound => e json_error 404, e. end end |
#post('/users') ⇒ JSON
Registers a new user and returns its data.
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/auth/server.rb', line 139 post '/users' do begin info = JSON.parse(request.body.read, @parse_opts) user = DB.post_user(info[:user]) {user: user}.to_json rescue NotFound => e json_error 404, e. rescue ArgumentError => e json_error 400, e. rescue ConflictError => e json_error 409, e. end end |
#put('/users/: access_key') ⇒ JSON
Update an existing user information and return it.
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/auth/server.rb', line 166 put '/users/:access_key' do |access_key| begin info = JSON.parse(request.body.read, @parse_opts) user = DB.put_user(access_key, info[:user]) {user: user}.to_json rescue NotFound => e json_error 404, e. rescue ArgumentError => e json_error 400, e. end end |