Class: Visor::Image::Auth

Inherits:
Object
  • Object
show all
Includes:
Common::Exception
Defined in:
lib/image/auth.rb

Overview

The API for the VISOR Auth System (VAS) server. This class supports all user’s manipulation operations.

After Instantiate a VAS API client object its possible to directly interact with the VAS server and its database backend.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Auth

Returns a new instance of Auth.



19
20
21
22
# File 'lib/image/auth.rb', line 19

def initialize(opts = {})
  @host = opts[:host]
  @port = opts[:port]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



17
18
19
# File 'lib/image/auth.rb', line 17

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



17
18
19
# File 'lib/image/auth.rb', line 17

def port
  @port
end

Instance Method Details

#delete_user(access_key) ⇒ Hash

Delete an user and returns its information.

Parameters:

  • access_key (String)

    The wanted user access_key.

Returns:

  • (Hash)

    The already deleted user detailed information.

Raises:

  • (NotFound)

    If user was not found.



94
95
96
97
# File 'lib/image/auth.rb', line 94

def delete_user(access_key)
  http = request.delete path: "/users/#{access_key}", access_key: delete_headers
  return_response(http)
end

#get_user(access_key) ⇒ Hash

Get information about a specific user.

Parameters:

  • access_key (String)

    The user access key (username).

Returns:

  • (Hash)

    The requested user account information.

Raises:

  • (NotFound)

    If user was not found.



49
50
51
52
# File 'lib/image/auth.rb', line 49

def get_user(access_key)
  http = request.get path: "/users/#{access_key}", head: get_headers
  return_response(http)
end

#get_users(query = {}) ⇒ Array

Get information about all registered users.

Options for filtering the returned results can be passed in.

Parameters:

  • query (Hash) (defaults to: {})

    a customizable set of options

Options Hash (query):

  • : (String)

    The user attribute value to filter returned results.

  • :sort (String) — default: "_id"

    The image attribute to sort returned results.

  • :dir (String) — default: "asc"

    The direction to sort results (“asc”/“desc”).

Returns:

  • (Array)

    All user’s accounts.

Raises:

  • (NotFound)

    If there are no users registered on VAS.



36
37
38
39
# File 'lib/image/auth.rb', line 36

def get_users(query = {})
  http = request.get path: '/users', query: query, head: get_headers
  return_response(http)
end

#post_user(info) ⇒ Hash

Register a new user account on VAS and return its data.

Parameters:

  • info (Hash)

    The user information.

Returns:

  • (Hash)

    The already created user detailed information.

Raises:

  • (Invalid)

    If user data validation fails.

  • (NotFound)

    If user was not found after registered.

  • (ConflictError)

    access_key was already taken.



64
65
66
67
68
# File 'lib/image/auth.rb', line 64

def post_user(info)
  body = prepare_body(info)
  http = request.post path: '/users', body: body, head: post_headers
  return_response(http)
end

#put_user(access_key, info) ⇒ Hash

Update an existing user information and return it.

Parameters:

  • access_key (String)

    The wanted user access_key.

  • info (Hash)

    The user information.

Returns:

  • (Hash)

    The already updated user detailed information.

Raises:

  • (Invalid)

    If user data validation fails.

  • (NotFound)

    If user was not found.



80
81
82
83
84
# File 'lib/image/auth.rb', line 80

def put_user(access_key, info)
  body = prepare_body(info)
  http = request.put path: "/users/#{access_key}", body: body, head: put_headers
  return_response(http)
end